Skip to content

Commit

Permalink
Diff: Added prefix token (#2281)
Browse files Browse the repository at this point in the history
This adds a token to match line prefixes.
  • Loading branch information
chenxsan committed Apr 4, 2020
1 parent 8167005 commit fd432a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
14 changes: 12 additions & 2 deletions components/prism-diff.js
Expand Up @@ -40,10 +40,20 @@
}

Prism.languages.diff[name] = {
// pattern: /^(?:[_].*(?:\r\n?|\n|(?![\s\S])))+/m
pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'),
alias: alias
alias: alias,
inside: {
'line': {
pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
lookbehind: true
},
'prefix': {
pattern: /[\s\S]/,
alias: /\w+/.exec(name)[0]
}
}
};

});

// make prefixes available to Diff plugin
Expand Down
2 changes: 1 addition & 1 deletion components/prism-diff.min.js

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

12 changes: 6 additions & 6 deletions tests/languages/diff/diff_feature.test
Expand Up @@ -11,12 +11,12 @@
----------------------------------------------------

[
["diff", "! qt: core\r\n"],
["unchanged", " unchanged\r\n"],
["deleted-sign", "- qt: core\r\n"],
["inserted-sign", "+ qt: core gui\r\n"],
["deleted-arrow", "< qt: core\r\n"],
["inserted-arrow", "> qt: core quick"]
["diff", [["prefix", "!"], ["line", " qt: core\r\n"]]],
["unchanged", [["prefix", " "], ["line", " unchanged\r\n"]]],
["deleted-sign", [["prefix", "-"], ["line", " qt: core\r\n"]]],
["inserted-sign", [["prefix", "+"], ["line", " qt: core gui\r\n"]]],
["deleted-arrow", [["prefix", "<"], ["line", " qt: core\r\n"]]],
["inserted-arrow", [["prefix", ">"], ["line", " qt: core quick"]]]
]

----------------------------------------------------
Expand Down

0 comments on commit fd432a5

Please sign in to comment.