@@ -31,75 +31,6 @@ MutableDocument deserializeMarkdownToDocument(String markdown) {
31
31
return MutableDocument (nodes: nodeVisitor.content);
32
32
}
33
33
34
- String serializeDocumentToMarkdown (Document doc) {
35
- final StringBuffer buffer = StringBuffer ();
36
-
37
- bool isFirstLine = true ;
38
- for (int i = 0 ; i < doc.nodes.length; ++ i) {
39
- final node = doc.nodes[i];
40
-
41
- if (! isFirstLine) {
42
- // Create a new line to encode the given node.
43
- buffer.writeln ('' );
44
- } else {
45
- isFirstLine = false ;
46
- }
47
-
48
- if (node is ImageNode ) {
49
- buffer.write ('' );
50
- } else if (node is HorizontalRuleNode ) {
51
- buffer.write ('---' );
52
- } else if (node is ListItemNode ) {
53
- final indent = List .generate (node.indent + 1 , (index) => ' ' ).join ('' );
54
- final symbol = node.type == ListItemType .unordered ? '*' : '1.' ;
55
-
56
- buffer.write ('$indent $symbol ${node .text .toMarkdown ()}' );
57
-
58
- final nodeBelow = i < doc.nodes.length - 1 ? doc.nodes[i + 1 ] : null ;
59
- if (nodeBelow != null && (nodeBelow is ! ListItemNode )) {
60
- // This list item is the last item in the list. Add an extra
61
- // blank line after it.
62
- buffer.writeln ('' );
63
- }
64
- } else if (node is ParagraphNode ) {
65
- final Attribution ? blockType = node.getMetadataValue ('blockType' );
66
-
67
- if (blockType == header1Attribution) {
68
- buffer.write ('# ${node .text .toMarkdown ()}' );
69
- } else if (blockType == header2Attribution) {
70
- buffer.write ('## ${node .text .toMarkdown ()}' );
71
- } else if (blockType == header3Attribution) {
72
- buffer.write ('### ${node .text .toMarkdown ()}' );
73
- } else if (blockType == header4Attribution) {
74
- buffer.write ('#### ${node .text .toMarkdown ()}' );
75
- } else if (blockType == header5Attribution) {
76
- buffer.write ('##### ${node .text .toMarkdown ()}' );
77
- } else if (blockType == header6Attribution) {
78
- buffer.write ('###### ${node .text .toMarkdown ()}' );
79
- } else if (blockType == blockquoteAttribution) {
80
- // TODO: handle multiline
81
- buffer.write ('> ${node .text .toMarkdown ()}' );
82
- } else if (blockType == codeAttribution) {
83
- buffer //
84
- ..writeln ('```' ) //
85
- ..writeln (node.text.toMarkdown ()) //
86
- ..write ('```' );
87
- } else {
88
- buffer.write (node.text.toMarkdown ());
89
- }
90
-
91
- // Separates paragraphs with blank lines.
92
- // If we are at the last node we don't add a trailing
93
- // blank line.
94
- if (i != doc.nodes.length - 1 ) {
95
- buffer.writeln ();
96
- }
97
- }
98
- }
99
-
100
- return buffer.toString ();
101
- }
102
-
103
34
/// Converts structured markdown to a list of [DocumentNode] s.
104
35
///
105
36
/// To use [_MarkdownToDocument] , obtain a series of markdown
0 commit comments