From 3b513370feb72726072d8e28d947715df257b50e Mon Sep 17 00:00:00 2001 From: Mukund-Tandon Date: Wed, 26 Jul 2023 16:24:02 +0530 Subject: [PATCH] fix: fixed the issue of code block not being exported in markdown --- .../markdown/encoder/parser/code_block_node_parser.dart | 7 ++++--- .../markdown/encoder/parser/text_node_parser_test.dart | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/plugins/markdown/encoder/parser/code_block_node_parser.dart b/lib/src/plugins/markdown/encoder/parser/code_block_node_parser.dart index dd10ef32f..b32b8c11d 100644 --- a/lib/src/plugins/markdown/encoder/parser/code_block_node_parser.dart +++ b/lib/src/plugins/markdown/encoder/parser/code_block_node_parser.dart @@ -4,18 +4,19 @@ class CodeBlockNodeParser extends NodeParser { const CodeBlockNodeParser(); @override - String get id => 'code_block'; + String get id => 'code'; @override String transform(Node node) { - assert(node.type == 'code_block'); + assert(node.type == 'code'); final delta = node.delta; + final language = node.attributes['language'] ?? ''; if (delta == null) { throw Exception('Delta is null'); } final markdown = DeltaMarkdownEncoder().convert(delta); - final result = '```\n$markdown\n```'; + final result = '```$language\n$markdown\n```'; final suffix = node.next == null ? '' : '\n'; return '$result$suffix'; diff --git a/test/plugins/markdown/encoder/parser/text_node_parser_test.dart b/test/plugins/markdown/encoder/parser/text_node_parser_test.dart index 9e0b475ad..704162c48 100644 --- a/test/plugins/markdown/encoder/parser/text_node_parser_test.dart +++ b/test/plugins/markdown/encoder/parser/text_node_parser_test.dart @@ -70,7 +70,7 @@ void main() async { test('code block style', () { final node = Node( - type: 'code_block', + type: 'code', attributes: { 'delta': (Delta()..insert(text)).toJson(), },