Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unsupported attributes in Markdown conversion + horizontal lines #418

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

maelchiotti
Copy link
Contributor

@maelchiotti maelchiotti commented Sep 2, 2024

fixes #405

@amantoux
Copy link
Member

amantoux commented Sep 4, 2024

Thank you @maelchiotti, will take a look as soon as I find some time
In the meanwhile, can you ensure the CI is green? You seem to have some issues with the linter

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 39.13043% with 14 lines in your changes missing coverage. Please review.

Project coverage is 87.93%. Comparing base (b98743a) to head (2ed078e).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
packages/parchment/lib/src/codecs/markdown.dart 44.44% 10 Missing ⚠️
packages/parchment/lib/src/document/line.dart 0.00% 3 Missing ⚠️
packages/fleather/lib/src/widgets/theme.dart 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #418      +/-   ##
==========================================
- Coverage   87.94%   87.93%   -0.02%     
==========================================
  Files          62       62              
  Lines       10364    10433      +69     
==========================================
+ Hits         9115     9174      +59     
- Misses       1249     1259      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

import '../document/block.dart';
import '../document/leaf.dart';
import '../document/line.dart';
import 'package:parchment/parchment.dart';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When refering to files within the package, we'd rather use relative file imports as per
https://dart.dev/effective-dart/usage#prefer-relative-import-paths

@@ -486,8 +498,11 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {
return buffer.toString();
}

void _writeAttribute(StringBuffer buffer, ParchmentAttribute? attribute,
{bool close = false}) {
void _writeAttribute(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd rather avoid trailing commas in function declarations when not a Flutter widget

@@ -497,18 +512,26 @@ 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

} 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


class ParchmentMarkdownCodec extends Codec<ParchmentDocument, String> {
const ParchmentMarkdownCodec();
const ParchmentMarkdownCodec({this.strictEncoding = true});

Copy link
Member

@amantoux amantoux Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth mentioning we only support <u> at the moment

@@ -529,8 +560,11 @@ class _ParchmentMarkdownEncoder extends Converter<ParchmentDocument, String> {
buffer.write('~~');
}

void _writeLinkTag(StringBuffer buffer, ParchmentAttribute<String> link,
{bool close = false}) {
void _writeLinkTag(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@@ -26,6 +26,12 @@ final class LineNode extends ContainerNode<LeafNode> with StyledNode {
return false;
}

EmbedNode get embedNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a getter that may throw an assertion error seems dangerous here

Copy link
Member

@amantoux amantoux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @maelchiotti for this PR and very sorry for the late review
See my comments inline
More generally, you seem to tackle only the decoding part, did you intentionally ignore the encoding?
Also, we had mentioned the replacement of unsupported embeds with [object]
Lastly, can you prove this works with some tests please and remove the localization file from the PR?
Thanks!

Copy link
Member

@amantoux amantoux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maelchiotti let me know if you want me to contribute to your PR

@maelchiotti
Copy link
Contributor Author

Thanks, I'll take a look at your review in a week or two, work on the encoding part that is missing, and I'll let you know where I could use some help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could the markdown conversion convert unsupported attributes to plain text insead of throwing an error?
2 participants