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

Fix custom components markdown parsing #1548

Merged

Conversation

wxwxwxwx9
Copy link
Contributor

@wxwxwxwx9 wxwxwxwx9 commented Apr 17, 2021

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • Others, please explain:

Resolves #958.

This issue is also related to #1534. We were prompted to re-visit #958 as it needs to be fixed before we can proceed to implement #1534.

As @ang-zeyu mentioned, we have never defined how our components should behave as html tags (block / inline (default)) regarding markdown.

Thus, we decided to adapt VuePress implementation to fit our own needs. VuePress treats every custom component (or unknown tags) as block-level element. This applies mostly in our use-case as well, except for <panel minimized> component (panels which are minimized), which is treated as inline element.

Overview of changes:
Adapted VuePress markdown-it patch for custom components.

Anything you'd like to highlight / discuss:
The patch used by VuePress replaces the html_block rule in markdown-it. However, on our side, we are also replacing html_block rule with special-escape-tags already.

Thus, instead of modifying / merging special-escape-tags rule and VuePress's custom-component rule, I decided to just add VuePress's custom component patch rule under special-escape-tags rule.

Should I look into combining the rules together somehow? Seeing that there is a bit of code duplication here and time-wise it is a little more expensive as markdown-it has to run through an additional rule (which can be combined into one).

But I think I am more comfortable with not combining them for separation of concern reasons. It would be easier to read the code with them being separate in my opinion.

Testing instructions:
npm run test

Try out the examples as raised by @ang-zeyu in #958. The bugs should be fixed.

However, when you use the minimized option for panel, then the "bug" (not actually a bug since it is expected behaviour) should still be present, as minimized panel is treated as an inline element instead of block-level element.

Proposed commit message: (wrap lines at 72 characters)
Fix custom components markdown parsing.

We have never defined the behavior of our custom components as html tags
(whether block-level or inline) in markdown parsing. This causes some
undesirable edge cases during markdown parsing, as raised up in #958.

Let's adopt the way VuePress define the behaviour for custom components
and adapt it to fit our needs.


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No blatantly unrelated changes
  • Pinged someone for a review!

@wxwxwxwx9 wxwxwxwx9 requested a review from ang-zeyu April 17, 2021 04:05
Copy link
Contributor

@ang-zeyu ang-zeyu left a comment

Choose a reason for hiding this comment

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

Brief look:

Copy link
Contributor

@ang-zeyu ang-zeyu left a comment

Choose a reason for hiding this comment

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

couple more:

requirements capture are some of the terms commonly <strong>and</strong> interchangeably used to represent the activity
of understanding what a software product should do.</seg>
</p>
<seg id="preview">Requirements gathering, requirements elicitation, requirements analysis,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yep, that would be good. On another note, should we update to something else in the SSR PR since we don't "allow" unknown components?

sounds good, over here might be better in fact since you've changed the behaviour of unknown tags

Copy link
Contributor

@ang-zeyu ang-zeyu left a comment

Choose a reason for hiding this comment

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

Lgtm! 👍

@ang-zeyu ang-zeyu added this to the v3.0 milestone Apr 21, 2021
@ang-zeyu ang-zeyu merged commit d6cff30 into MarkBind:master Apr 21, 2021
@wxwxwxwx9 wxwxwxwx9 mentioned this pull request Apr 21, 2021
10 tasks
wxwxwxwx9 added a commit to wxwxwxwx9/markbind that referenced this pull request Apr 22, 2021
wxwxwxwx9 added a commit to wxwxwxwx9/markbind that referenced this pull request Apr 22, 2021
wxwxwxwx9 added a commit to wxwxwxwx9/markbind that referenced this pull request Apr 22, 2021
wxwxwxwx9 added a commit to wxwxwxwx9/markbind that referenced this pull request Apr 22, 2021
wxwxwxwx9 added a commit to wxwxwxwx9/markbind that referenced this pull request Apr 22, 2021
wxwxwxwx9 added a commit to wxwxwxwx9/markbind that referenced this pull request Apr 22, 2021
@ang-zeyu
Copy link
Contributor

Remark: this PR introduces a lot of breaking changes in the form of properly defined block/inline behaviour. (should be a step in the right direction irregardless of SSR or not)

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.

Unexpected behaviour of components when immediately prepended by GFMD
2 participants