From 3f9ab69104f22f9926be185c35619effde21ca96 Mon Sep 17 00:00:00 2001 From: Alan Mantoux Date: Thu, 23 Nov 2023 15:16:57 +0100 Subject: [PATCH] Support strike through in markdown codec --- packages/parchment/lib/src/codecs/markdown.dart | 6 +++++- packages/parchment/test/codecs/markdown_test.dart | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/parchment/lib/src/codecs/markdown.dart b/packages/parchment/lib/src/codecs/markdown.dart index 20f6e484..e651295e 100644 --- a/packages/parchment/lib/src/codecs/markdown.dart +++ b/packages/parchment/lib/src/codecs/markdown.dart @@ -449,7 +449,7 @@ class _ParchmentMarkdownEncoder extends Converter { } else if (attribute == ParchmentAttribute.inlineCode) { _writeInlineCodeTag(buffer); } else if (attribute == ParchmentAttribute.strikethrough) { - _writeInlineCodeTag(buffer); + _writeStrikeThoughTag(buffer); } else if (attribute?.key == ParchmentAttribute.link.key) { _writeLinkTag(buffer, attribute as ParchmentAttribute, close: close); @@ -475,6 +475,10 @@ class _ParchmentMarkdownEncoder extends Converter { buffer.write('`'); } + void _writeStrikeThoughTag(StringBuffer buffer) { + buffer.write('~~'); + } + void _writeLinkTag(StringBuffer buffer, ParchmentAttribute link, {bool close = false}) { if (close) { diff --git a/packages/parchment/test/codecs/markdown_test.dart b/packages/parchment/test/codecs/markdown_test.dart index dd56b751..60a23555 100644 --- a/packages/parchment/test/codecs/markdown_test.dart +++ b/packages/parchment/test/codecs/markdown_test.dart @@ -9,7 +9,7 @@ import 'package:quill_delta/quill_delta.dart'; import 'package:test/test.dart'; void main() { - group('$ParchmentMarkdownCodec.decode', () { + group('ParchmentMarkdownCodec.decode', () { test('should convert empty markdown to valid empty document', () { final markdown = ''; final newParchment = ParchmentDocument(); @@ -405,7 +405,7 @@ void main() { }); }); - group('$ParchmentMarkdownCodec.encode', () { + group('ParchmentMarkdownCodec.encode', () { test('split adjacent paragraphs', () { final delta = Delta()..insert('First line\nSecond line\n'); final result = @@ -429,7 +429,8 @@ void main() { runFor(ParchmentAttribute.bold, 'This **house** is a **circus**\n\n'); runFor(ParchmentAttribute.italic, 'This _house_ is a _circus_\n\n'); - runFor(ParchmentAttribute.strikethrough, 'This ~~house~~ is a ~~circus~~\n\n'); + runFor(ParchmentAttribute.strikethrough, + 'This ~~house~~ is a ~~circus~~\n\n'); }); test('intersecting inline styles', () {