Skip to content

Commit

Permalink
Support strike through in markdown codec
Browse files Browse the repository at this point in the history
  • Loading branch information
amantoux committed Nov 23, 2023
1 parent 7ddce8e commit 3f9ab69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/parchment/lib/src/codecs/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {
} 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<String>,
close: close);
Expand All @@ -475,6 +475,10 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {
buffer.write('`');
}

void _writeStrikeThoughTag(StringBuffer buffer) {
buffer.write('~~');
}

void _writeLinkTag(StringBuffer buffer, ParchmentAttribute<String> link,
{bool close = false}) {
if (close) {
Expand Down
7 changes: 4 additions & 3 deletions packages/parchment/test/codecs/markdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 =
Expand All @@ -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', () {
Expand Down

0 comments on commit 3f9ab69

Please sign in to comment.