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

Reorganize grammars #1407

Closed

Conversation

Feder1co5oave
Copy link
Contributor

Description

I noticed commonmark tests were being run in gfm mode. So I disabled it and moved block rules around to better represent the difference between the two grammar flavors:

  • code fences are now parsed with gfm: false too (they're a part of commonmark)

  • ATX headings require a space after the #s in gfm: false mode, too. They're still not required in pedantic mode.

  • tables are supported whenever gfm: true (they're a part of gfm), so the old tables mode (described as "github flavored markdown + tables") is now practically the same as gfm mode.

  • re-write the paragraph rule to make it more clear and efficient.

    • setext headings can no longer interrupt paragraphs. This means that the following markdown

      Paragraph?
      Heading?
      =======

      was previously parsed (and still is, but only in pedantic mode) as

      <p>Paragraph?</p>
      <h1 id="heading">Heading?</h1>

      whereas now it is

      <p>Paragraph?
      Heading?
      =======</p>

      Neither of these complies with commonmark, which introduced multi-line setext headings and whould parse it like

      <h1>Paragraph?
      Heading?</h1>

      This involves parsing a paragraph-like block, followed by a line made of = or -. Now that I think of it, I'm not sure it's worth introducing this breaking change, and then another. Or we could merge this and wait until we get setext heading parsing 100% compliant before releasing. Let's hear opinions on this.

    • lists can now interrupt paragraphs, but only if unordered, or starting from 1. (as per example 268)

Fixes

I don't know at this time of any filed issues solved by this PR.

Expectation

marked should parse commonmark in normal mode (gfm: false, tables: false), and github flavored markdown in gfm mode, according to spec.
We should consider deprecating the tables option.

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,

Committer

In most cases, this should be a different person than the contributor.

  • Draft GitHub release notes have been updated.
  • CI is green (no forced merge required).
  • Merge PR

lib/marked.js Outdated Show resolved Hide resolved
@styfle
Copy link
Member

styfle commented Jan 7, 2019

@davisjam Can you review for redos vulnerabilities?

@@ -14,9 +14,9 @@
var block = {
newline: /^\n+/,
code: /^( {4}[^\n]+\n*)+/,
fences: noop,
fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
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 rule was copied from block.gfm as-is.

hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davisjam I think this is "better" than before?

fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
paragraph: /^/,
heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these were copied as-is from block.tables

@UziTech
Copy link
Member

UziTech commented May 21, 2019

@Feder1co5oave could you fix the merge conflicts so we can get this merged?

@UziTech UziTech mentioned this pull request Jul 1, 2019
4 tasks
@UziTech UziTech closed this in #1511 Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants