fix: document from markdown contains html escaped text (#841)
This commit is contained in:
parent
d2d987312d
commit
e0d673afbb
3 changed files with 49 additions and 3 deletions
|
|
@ -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()),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
47
example/test/markdown_code_block_parser_test.dart
Normal file
47
example/test/markdown_code_block_parser_test.dart
Normal file
|
|
@ -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()''',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {
|
|||
...inlineSyntaxes,
|
||||
UnderlineInlineSyntax(),
|
||||
],
|
||||
encodeHtml: false,
|
||||
).parse(input);
|
||||
final document = Document.blank();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue