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

[SuperEditorMarkdown] Add header alignments #1350

Merged
merged 10 commits into from
Sep 29, 2023

Conversation

lamnhan066
Copy link
Contributor

@matthew-carroll Here are my implementations for the header alignments.

Fixes #865

@matthew-carroll
Copy link
Contributor

@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.

Copy link
Collaborator

@angelosilvestre angelosilvestre left a 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.

@lamnhan066
Copy link
Contributor Author

@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?

@lamnhan066 lamnhan066 changed the title [super_editor_markdown] Add header alignments [SuperEditorMarkdown] Add header alignments Sep 11, 2023
Copy link
Collaborator

@angelosilvestre angelosilvestre left a 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.

@lamnhan066
Copy link
Contributor Author

@matthew-carroll I have formatted the code and improved the comments. Please give it a look.

@matthew-carroll
Copy link
Contributor

@vnniz there seems to be a number of merge conflicts with your PR. Please rebase against main and resolve those.

@lamnhan066
Copy link
Contributor Author

@matthew-carroll done.

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.".

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@lamnhan066 lamnhan066 left a 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.
Copy link
Contributor Author

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?

Copy link
Contributor

@matthew-carroll matthew-carroll left a 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.

@matthew-carroll matthew-carroll merged commit cc4a07e into superlistapp:main Sep 29, 2023
10 of 11 checks passed
@matthew-carroll
Copy link
Contributor

@angelosilvestre can you please cherry pick this to stable?

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.

[SuperEditorMarkdown] Alignment for the header text
3 participants