Skip to content

Commit

Permalink
Markdown: Added support for nested lists (#2228)
Browse files Browse the repository at this point in the history
This improves the support for nested lists by making the `code` pattern stricter.
  • Loading branch information
RunDevelopment authored Feb 24, 2020
1 parent 7d8ff7e commit 73c8a37
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
12 changes: 6 additions & 6 deletions components/prism-markdown.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function (Prism) {

// Allow only one line break
var inner = /(?:\\.|[^\\\n\r]|(?:\r?\n|\r)(?!\r?\n|\r))/.source;
var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?!\n|\r\n?))/.source;

/**
* This function is intended for the creation of the bold or italic pattern.
Expand All @@ -24,8 +24,8 @@


var tableCell = /(?:\\.|``.+?``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
var tableRow = /\|?__(?:\|__)+\|?(?:(?:\r?\n|\r)|$)/.source.replace(/__/g, tableCell);
var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\r?\n|\r)/.source;
var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|$)/.source.replace(/__/g, tableCell);
var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;


Prism.languages.markdown = Prism.languages.extend('markup', {});
Expand Down Expand Up @@ -72,7 +72,7 @@
'code': [
{
// Prefixed by 4 spaces or 1 tab and preceded by an empty line
pattern: /(^[ \t]*(?:\r?\n|\r))(?: {4}|\t).+(?:(?:\r?\n|\r)(?: {4}|\t).+)*/m,
pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
lookbehind: true,
alias: 'keyword'
},
Expand All @@ -90,7 +90,7 @@
greedy: true,
inside: {
'code-block': {
pattern: /^(```.*(?:\r?\n|\r))[\s\S]+?(?=(?:\r?\n|\r)^```$)/m,
pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
lookbehind: true
},
'code-language': {
Expand All @@ -108,7 +108,7 @@

// title 2
// -------
pattern: /\S.*(?:\r?\n|\r)(?:==+|--+)(?=[ \t]*$)/m,
pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
alias: 'important',
inside: {
punctuation: /==+$|--+$/
Expand Down
2 changes: 1 addition & 1 deletion components/prism-markdown.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions tests/languages/markdown/list_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,41 @@
2. bar
42. baz

1. list
1. nested list
- a
- b
2. foo

----------------------------------------------------

[
["list", "*"], " foo\r\n",
["list", "+"], " bar\r\n",
["list", "-"], " baz\r\n\r\n",
["list", "1."], " foo\r\n ",
["list", "2."], " bar\r\n",
["list", "42."], " baz"
["list", "*"],
" foo\r\n",
["list", "+"],
" bar\r\n",
["list", "-"],
" baz\r\n\r\n",

["list", "1."],
" foo\r\n ",
["list", "2."],
" bar\r\n",
["list", "42."],
" baz\r\n\r\n",

["list", "1."],
" list\r\n\t",
["list", "1."],
" nested list\r\n\t\t",
["list", "-"],
" a\r\n\t\t",
["list", "-"],
" b\r\n\t",
["list", "2."],
" foo"
]

----------------------------------------------------

Checks for list symbols.
Checks for list symbols.

0 comments on commit 73c8a37

Please sign in to comment.