Skip to content

Commit

Permalink
Diff: Add nest token
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxsan committed Apr 3, 2020
1 parent 947a55b commit e9da444
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
23 changes: 18 additions & 5 deletions components/prism-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,24 @@
alias.push("bold");
}

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

if (['-', '<', '+', '>'].indexOf(prefix) !== -1) {
var inside = {
prefix: RegExp('^[' + prefix + ']', 'm')
};
Prism.languages.diff[name] = {
pattern: pattern,
alias: alias,
inside: inside
};
} else {
Prism.languages.diff[name] = {
pattern: pattern,
alias: alias
};
}

});

// make prefixes available to Diff plugin
Expand Down
8 changes: 4 additions & 4 deletions tests/languages/diff/diff_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
[
["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"]
["deleted-sign", [["prefix", "-"], " qt: core\r\n"]],
["inserted-sign", [["prefix", "+"], " qt: core gui\r\n"]],
["deleted-arrow", [["prefix", "<"], " qt: core\r\n"]],
["inserted-arrow", [["prefix", ">"], " qt: core quick"]]
]

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

0 comments on commit e9da444

Please sign in to comment.