From ab214d4a74e877103990a50b598b4be0ba4bd218 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 12 Dec 2021 23:37:34 -0500 Subject: [PATCH] Added missing attributes to markdown renderer --- .../markdown/src/delta_markdown_encoder.dart | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_encoder.dart b/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_encoder.dart index 12f57e6e8e..bd2aa4c281 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_encoder.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/markdown/src/delta_markdown_encoder.dart @@ -65,8 +65,7 @@ class DeltaMarkdownEncoder extends Converter { // First close any current styles if needed final markedForRemoval = []; // Close the styles in reverse order, e.g. **_ for _**Test**_. - for (final value - in currentInlineStyle.attributes.values.toList().reversed) { + for (final value in currentInlineStyle.attributes.values.toList().reversed) { // TODO(tillf): Is block correct? if (value.scope == AttributeScope.BLOCK) { continue; @@ -123,10 +122,8 @@ class DeltaMarkdownEncoder extends Converter { // Close any open inline styles. _handleInline(lineBuffer, '', null); - final lineBlock = Style.fromJson(attributes) - .attributes - .values - .singleWhereOrNull((a) => a.scope == AttributeScope.BLOCK); + final lineBlock = + Style.fromJson(attributes).attributes.values.singleWhereOrNull((a) => a.scope == AttributeScope.BLOCK); if (lineBlock == currentBlockStyle) { currentBlockLines.add(lineBuffer.toString()); @@ -220,6 +217,16 @@ class DeltaMarkdownEncoder extends Converter { buffer.write(!close ? '[' : '](${attribute.value})'); } else if (attribute == Attribute.codeBlock) { buffer.write(!close ? '```\n' : '\n```'); + } else if (attribute.key == Attribute.background.key) { + buffer.write(!close ? '' : ''); + } else if (attribute.key == Attribute.underline.key) { + buffer.write(!close ? '' : ''); + } else if (attribute.key == Attribute.codeBlock.key) { + buffer.write(!close ? '```\n' : '\n```'); + } else if (attribute.key == Attribute.inlineCode.key) { + buffer.write(!close ? '`' : '`'); + } else if (attribute.key == Attribute.strikeThrough.key) { + buffer.write(!close ? '~~' : '~~'); } else { throw ArgumentError('Cannot handle $attribute'); } @@ -246,6 +253,8 @@ class DeltaMarkdownEncoder extends Converter { buffer.write('## '); } else if (block.key == Attribute.h3.key && block.value == 3) { buffer.write('### '); + } else if (block.key == Attribute.list.key) { + buffer.write('* '); } else { throw ArgumentError('Cannot handle block $block'); }