Skip to content

Commit

Permalink
fix: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
maelchiotti committed Oct 13, 2024
1 parent 5fb9f5a commit 4806549
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
31 changes: 14 additions & 17 deletions packages/parchment/lib/src/codecs/markdown.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import 'package:parchment/parchment.dart';
import '../../parchment.dart';

class ParchmentMarkdownCodec extends Codec<ParchmentDocument, String> {
const ParchmentMarkdownCodec({this.strictEncoding = true});
Expand All @@ -11,6 +11,9 @@ class ParchmentMarkdownCodec extends Codec<ParchmentDocument, String> {
/// 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 `<u>...</u>`
final bool strictEncoding;

@override
Expand Down Expand Up @@ -410,8 +413,11 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {

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;
Expand Down Expand Up @@ -498,11 +504,8 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {
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) {
Expand All @@ -512,19 +515,13 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {
} else if (attribute == ParchmentAttribute.strikethrough) {
_writeStrikeThoughTag(buffer);
} else if (attribute?.key == ParchmentAttribute.link.key) {
_writeLinkTag(
buffer,
attribute as ParchmentAttribute<String>,
close: close,
);
_writeLinkTag(buffer, attribute as ParchmentAttribute<String>,
close: close);
} else if (attribute?.key == ParchmentAttribute.heading.key) {
_writeHeadingTag(buffer, attribute as ParchmentAttribute<int>);
} else if (attribute?.key == ParchmentAttribute.block.key) {
_writeBlockTag(
buffer,
attribute as ParchmentAttribute<String>,
close: close,
);
_writeBlockTag(buffer, attribute as ParchmentAttribute<String>,
close: close);
} else if (attribute?.key == ParchmentAttribute.checked.key) {
// no-op already handled in handleBlock
} else if (attribute?.key == ParchmentAttribute.indent.key) {
Expand Down
6 changes: 0 additions & 6 deletions packages/parchment/lib/src/document/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ final class LineNode extends ContainerNode<LeafNode> 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) {
Expand Down

0 comments on commit 4806549

Please sign in to comment.