mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix : Code block parser implementation (#2046)
* fix: Code block implementation * fix: Added test to cover CodeBlock * fix: typos * fix: Code block implementation * fix: typos
This commit is contained in:
@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
import 'package:appflowy/plugins/document/application/share_service.dart';
|
import 'package:appflowy/plugins/document/application/share_service.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/plugins/parsers/divider_node_parser.dart';
|
import 'package:appflowy/plugins/document/presentation/plugins/parsers/divider_node_parser.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/plugins/parsers/math_equation_node_parser.dart';
|
import 'package:appflowy/plugins/document/presentation/plugins/parsers/math_equation_node_parser.dart';
|
||||||
|
import 'package:appflowy/plugins/document/presentation/plugins/parsers/code_block_node_parser.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
@ -53,6 +54,7 @@ class DocShareBloc extends Bloc<DocShareEvent, DocShareState> {
|
|||||||
return documentToMarkdown(document, customParsers: [
|
return documentToMarkdown(document, customParsers: [
|
||||||
const DividerNodeParser(),
|
const DividerNodeParser(),
|
||||||
const MathEquationNodeParser(),
|
const MathEquationNodeParser(),
|
||||||
|
const CodeBlockNodeParser(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
|
|
||||||
|
class CodeBlockNodeParser extends NodeParser {
|
||||||
|
const CodeBlockNodeParser();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get id => 'code_block';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String transform(Node node) {
|
||||||
|
return '```\n${node.attributes['code_block']}\n```';
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:appflowy/plugins/document/presentation/plugins/parsers/code_block_node_parser.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/plugins/parsers/divider_node_parser.dart';
|
import 'package:appflowy/plugins/document/presentation/plugins/parsers/divider_node_parser.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/plugins/parsers/math_equation_node_parser.dart';
|
import 'package:appflowy/plugins/document/presentation/plugins/parsers/math_equation_node_parser.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
@ -31,7 +32,31 @@ void main() {
|
|||||||
]);
|
]);
|
||||||
expect(result, r'$$E = MC^2$$');
|
expect(result, r'$$E = MC^2$$');
|
||||||
});
|
});
|
||||||
|
// Changes
|
||||||
|
test('code block', () {
|
||||||
|
const text = '''
|
||||||
|
{
|
||||||
|
"document":{
|
||||||
|
"type":"editor",
|
||||||
|
"children":[
|
||||||
|
{
|
||||||
|
"type":"code_block",
|
||||||
|
"attributes":{
|
||||||
|
"code_block":"Some Code"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
final document = Document.fromJson(
|
||||||
|
Map<String, Object>.from(json.decode(text)),
|
||||||
|
);
|
||||||
|
final result = documentToMarkdown(document, customParsers: [
|
||||||
|
const CodeBlockNodeParser(),
|
||||||
|
]);
|
||||||
|
expect(result, '```\nSome Code\n```');
|
||||||
|
});
|
||||||
test('divider', () {
|
test('divider', () {
|
||||||
const text = '''
|
const text = '''
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user