From 7997fdadcd43c979d747140e64a7f2e72b9c4abe Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 5 Jul 2019 17:11:17 +0300 Subject: [PATCH] Apply special rules for collapsing whitespace inside code blocks Change as per commonmark 0.29 spec See also: https://github.com/commonmark/commonmark-spec/commit/e121b4e30185ca0513052cc4d08470ee75f9646b --- lib/rules_inline/backticks.js | 4 +- test/fixtures/commonmark/bad.txt | 140 ------------------ test/fixtures/commonmark/good.txt | 93 ++++++++++++ .../markdown-it/commonmark_extras.txt | 9 -- 4 files changed, 95 insertions(+), 151 deletions(-) diff --git a/lib/rules_inline/backticks.js b/lib/rules_inline/backticks.js index 0cd1a99..b585c6f 100644 --- a/lib/rules_inline/backticks.js +++ b/lib/rules_inline/backticks.js @@ -29,8 +29,8 @@ module.exports = function backtick(state, silent) { token = state.push('code_inline', 'code', 0); token.markup = marker; token.content = state.src.slice(pos, matchStart) - .replace(/[ \n]+/g, ' ') - .trim(); + .replace(/\n/g, ' ') + .replace(/^ (.+) $/, '$1'); } state.pos = matchEnd; return true; diff --git a/test/fixtures/commonmark/bad.txt b/test/fixtures/commonmark/bad.txt index 493870c..5d22760 100644 --- a/test/fixtures/commonmark/bad.txt +++ b/test/fixtures/commonmark/bad.txt @@ -1,20 +1,3 @@ -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 1884 - -. -``` ``` -aaa -. -

-aaa

-. - -error: - -

-aaa

- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 5176 @@ -82,114 +65,6 @@ error: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5898 - -. -` `` ` -. -

``

-. - -error: - -

``

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5907 - -. -` a` -. -

a

-. - -error: - -

a

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5916 - -. -` b ` -. -

 b 

-. - -error: - -

b

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5924 - -. -` ` -` ` -. -

  -

-. - -error: - -

-

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5935 - -. -`` -foo -bar -baz -`` -. -

foo bar baz

-. - -error: - -

foo bar baz

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5945 - -. -`` -foo -`` -. -

foo

-. - -error: - -

foo

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5956 - -. -`foo bar -baz` -. -

foo bar baz

-. - -error: - -

foo bar baz

- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 6912 @@ -218,18 +93,3 @@ error:

foo******bar*********baz

-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 9240 - -. -`code -span` -. -

code span

-. - -error: - -

code span

- - diff --git a/test/fixtures/commonmark/good.txt b/test/fixtures/commonmark/good.txt index bc990c9..6e945a7 100644 --- a/test/fixtures/commonmark/good.txt +++ b/test/fixtures/commonmark/good.txt @@ -1374,6 +1374,17 @@ aaa . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 1884 + +. +``` ``` +aaa +. +

+aaa

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 1893 @@ -4648,6 +4659,78 @@ src line: 5890

``

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5898 + +. +` `` ` +. +

``

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5907 + +. +` a` +. +

a

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5916 + +. +` b ` +. +

 b 

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5924 + +. +` ` +` ` +. +

  +

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5935 + +. +`` +foo +bar +baz +`` +. +

foo bar baz

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5945 + +. +`` +foo +`` +. +

foo

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5956 + +. +`foo bar +baz` +. +

foo bar baz

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 5973 @@ -7523,6 +7606,16 @@ bar* bar

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 9240 + +. +`code +span` +. +

code span

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 9248 diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index bbaa488..0be81b0 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -475,11 +475,6 @@ Coverage. Various tags not interrupting blockquotes because of indentation: > foo # not a heading - -> foo - ``` - not a fence - ``` .

foo @@ -489,8 +484,4 @@ Coverage. Various tags not interrupting blockquotes because of indentation:

foo # not a heading

-
-

foo -not a fence

-
.