Skip to content

Commit

Permalink
fix: document from markdown contains html escaped text (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jul 11, 2024
1 parent d2d9873 commit e0d673a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 1 addition & 3 deletions example/lib/pages/markdown/markdown_code_block_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ class MarkdownCodeBlockParserV2 extends CustomMarkdownParser {
language = languageClass.substring('language-'.length);
}

final deltaDecoder = DeltaMarkdownDecoder();

return [
codeBlockNode(
language: language,
delta: deltaDecoder.convertNodes(code.children),
delta: Delta()..insert(code.textContent.trimRight()),
),
];
}
Expand Down
47 changes: 47 additions & 0 deletions example/test/markdown_code_block_parser_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:appflowy_editor/src/plugins/markdown/decoder/document_markdown_decoder.dart';
import 'package:example/pages/markdown/markdown_code_block_parser.dart';
import 'package:flutter_test/flutter_test.dart';

void main() async {
group('markdown_heading_parser.dart', () {
final parser = DocumentMarkdownDecoder(
markdownElementParsers: [
const MarkdownCodeBlockParserV2(),
],
);

test('contains quote syntax', () {
const codeBlockMarkdown = '''```python
# Example of using the GTD class
gtd_system = GTD()
gtd_system.capture("Write a blog post")
gtd_system.capture("Prepare presentation for Monday")
gtd_system.capture("Plan vacation")
gtd_system.clarify()
gtd_system.review()
gtd_system.engage()
```''';

final result = parser.convert(codeBlockMarkdown);
final codeBlock = result.root.children.first;
expect(codeBlock.toJson(), {
'type': 'code',
'data': {
'language': 'python',
'delta': [
{
'insert': '''# Example of using the GTD class
gtd_system = GTD()
gtd_system.capture("Write a blog post")
gtd_system.capture("Prepare presentation for Monday")
gtd_system.capture("Plan vacation")
gtd_system.clarify()
gtd_system.review()
gtd_system.engage()''',
},
],
},
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {
...inlineSyntaxes,
UnderlineInlineSyntax(),
],
encodeHtml: false,
).parse(input);
final document = Document.blank();

Expand Down

0 comments on commit e0d673a

Please sign in to comment.