-
Notifications
You must be signed in to change notification settings - Fork 250
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
[SuperEditorMarkdown] Add header alignments #1350
[SuperEditorMarkdown] Add header alignments #1350
Conversation
@vnniz as I mentioned in the ticket, I'm still trying to determine what syntax you're proposing. Can you please return to the ticket and explain the Markdown syntax? We need to decide that this is something we want before taking time to review an implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discussed with Matt about the syntax and we agreed we should add the alignment notation in the same line of the header, after the #
.
If you want to proceed with this PR, please update it to the following syntax:
#:--- Header
or # Header
=> Left Alignment
#:---: Header
=> Center Alignment
#---: Header
=> Right Alignment
#-::- Header
=> Justify Alignment
Also, please add tests for parsing a header with alignment, also updating the 'example doc'
and 'example doc 1'
tests to include headers with all alignments.
If you are not willing to make those changes, please let me know and I will create a new PR based on this one.
super_editor_markdown/lib/src/document_to_markdown_serializer.dart
Outdated
Show resolved
Hide resolved
super_editor_markdown/lib/src/document_to_markdown_serializer.dart
Outdated
Show resolved
Hide resolved
@angelosilvestre As we discussed at #865, I'll keep the current format of the header alignment syntax. I have resolved some issues that you mentioned and added some tests. Can you give it a look and do you think the added tests are enough? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. After addressing them you can tag @matthew-carroll for his review.
super_editor_markdown/lib/src/document_to_markdown_serializer.dart
Outdated
Show resolved
Hide resolved
super_editor_markdown/lib/src/markdown_to_document_parsing.dart
Outdated
Show resolved
Hide resolved
super_editor_markdown/lib/src/markdown_to_document_parsing.dart
Outdated
Show resolved
Hide resolved
super_editor_markdown/lib/src/markdown_to_document_parsing.dart
Outdated
Show resolved
Hide resolved
@matthew-carroll I have formatted the code and improved the comments. Please give it a look. |
@vnniz there seems to be a number of merge conflicts with your PR. Please rebase against main and resolve those. |
917177b
to
4fed0ae
Compare
@matthew-carroll done. |
super_editor_markdown/lib/src/document_to_markdown_serializer.dart
Outdated
Show resolved
Hide resolved
super_editor_markdown/lib/src/document_to_markdown_serializer.dart
Outdated
Show resolved
Hide resolved
final Attribution? blockType = node.getMetadataValue('blockType'); | ||
final String? textAlign = node.getMetadataValue('textAlign'); | ||
|
||
// Left alignment is the default, so there is no need to add the alignment token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is in a strange location. It's unclear how it relates to the code. After reading this comment, I go down a few lines, and we're adding the alignment token, so it's confusing to see a comment that says "there is no need to add the alignment token". Please ensure that comments appear in places that clarify code behavior, rather than confuse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next line, we have textAlign != 'left'
condition, which means we don't need to add the left alignment token to the markdown when we serialize a header node (the same as ParagraphNodeSerializer). Do you have any better comment for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary issue is the location of the comment. The code directly below that comment doesn't implement "no need to add the alignment token". This comment actually refers to a non-existent else
statement.
The code that actually exists is code that adds an alignment token. Not code that avoids adding an alignment token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Left alignment is the default, so there is no need to add the alignment token.
if (markdownSyntax == MarkdownSyntax.superEditor && textAlign != null && textAlign != 'left') {
final alignmentToken = _convertAlignmentToMarkdown(textAlign);
if (alignmentToken != null) {
buffer.writeln(alignmentToken);
}
}
I think it would be clear if the comment is "Left alignment is the default, so there is no need to add the left alignment token.".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're still phrasing the comment in terms of what the code ISN'T doing, instead of what the code IS doing. Please write code comments in terms of what the code IS doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment has been updated as you requested.
super_editor_markdown/lib/src/markdown_to_document_parsing.dart
Outdated
Show resolved
Hide resolved
…mple doc' and 'example doc 1'
170259c
to
0bb0998
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthew-carroll I have updated some comments and reviews.
final Attribution? blockType = node.getMetadataValue('blockType'); | ||
final String? textAlign = node.getMetadataValue('textAlign'); | ||
|
||
// Left alignment is the default, so there is no need to add the alignment token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next line, we have textAlign != 'left'
condition, which means we don't need to add the left alignment token to the markdown when we serialize a header node (the same as ParagraphNodeSerializer). Do you have any better comment for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks for the contribution.
@angelosilvestre can you please cherry pick this to stable? |
@matthew-carroll Here are my implementations for the header alignments.
Fixes #865