diff --git a/packages/parchment/lib/src/codecs/markdown.dart b/packages/parchment/lib/src/codecs/markdown.dart index ed621765..9645a436 100644 --- a/packages/parchment/lib/src/codecs/markdown.dart +++ b/packages/parchment/lib/src/codecs/markdown.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:parchment/parchment.dart'; +import '../../parchment.dart'; class ParchmentMarkdownCodec extends Codec { const ParchmentMarkdownCodec({this.strictEncoding = true}); @@ -11,6 +11,9 @@ class ParchmentMarkdownCodec extends Codec { /// not natively supported by the Markdown syntax exist, an exception will be /// thrown. Otherwise, they will be converted in the best way possible /// (for example with HTML tags, plain text or placeholders). + /// + /// Currently supported attributes: + /// - Underline with `...` final bool strictEncoding; @override @@ -410,8 +413,11 @@ class _ParchmentMarkdownEncoder extends Converter { void handleLine(LineNode node) { if (node.hasBlockEmbed) { - if (node.embedNode.value == BlockEmbed.horizontalRule) { + if ((node.children.single as EmbedNode).value == + BlockEmbed.horizontalRule) { _writeHorizontalLineTag(buffer); + } else { + buffer.write('[object]'); } return; @@ -498,11 +504,8 @@ class _ParchmentMarkdownEncoder extends Converter { return buffer.toString(); } - void _writeAttribute( - StringBuffer buffer, - ParchmentAttribute? attribute, { - bool close = false, - }) { + void _writeAttribute(StringBuffer buffer, ParchmentAttribute? attribute, + {bool close = false}) { if (attribute == ParchmentAttribute.bold) { _writeBoldTag(buffer); } else if (attribute == ParchmentAttribute.italic) { @@ -512,19 +515,13 @@ class _ParchmentMarkdownEncoder extends Converter { } else if (attribute == ParchmentAttribute.strikethrough) { _writeStrikeThoughTag(buffer); } else if (attribute?.key == ParchmentAttribute.link.key) { - _writeLinkTag( - buffer, - attribute as ParchmentAttribute, - close: close, - ); + _writeLinkTag(buffer, attribute as ParchmentAttribute, + close: close); } else if (attribute?.key == ParchmentAttribute.heading.key) { _writeHeadingTag(buffer, attribute as ParchmentAttribute); } else if (attribute?.key == ParchmentAttribute.block.key) { - _writeBlockTag( - buffer, - attribute as ParchmentAttribute, - close: close, - ); + _writeBlockTag(buffer, attribute as ParchmentAttribute, + close: close); } else if (attribute?.key == ParchmentAttribute.checked.key) { // no-op already handled in handleBlock } else if (attribute?.key == ParchmentAttribute.indent.key) { diff --git a/packages/parchment/lib/src/document/line.dart b/packages/parchment/lib/src/document/line.dart index f174a0fc..3d330a5c 100644 --- a/packages/parchment/lib/src/document/line.dart +++ b/packages/parchment/lib/src/document/line.dart @@ -26,12 +26,6 @@ final class LineNode extends ContainerNode with StyledNode { return false; } - EmbedNode get embedNode { - assert(hasBlockEmbed); - - return children.single as EmbedNode; - } - /// Returns next [LineNode] or `null` if this is the last line in the document. LineNode? get nextLine { if (isLast) {