source: node_modules/refractor/lang/diff.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[d24f17c]1'use strict'
2
3module.exports = diff
4diff.displayName = 'diff'
5diff.aliases = []
6function diff(Prism) {
7 ;(function (Prism) {
8 Prism.languages.diff = {
9 coord: [
10 // Match all kinds of coord lines (prefixed by "+++", "---" or "***").
11 /^(?:\*{3}|-{3}|\+{3}).*$/m, // Match "@@ ... @@" coord lines in unified diff.
12 /^@@.*@@$/m, // Match coord lines in normal diff (starts with a number).
13 /^\d.*$/m
14 ] // deleted, inserted, unchanged, diff
15 }
16 /**
17 * A map from the name of a block to its line prefix.
18 *
19 * @type {Object<string, string>}
20 */
21 var PREFIXES = {
22 'deleted-sign': '-',
23 'deleted-arrow': '<',
24 'inserted-sign': '+',
25 'inserted-arrow': '>',
26 unchanged: ' ',
27 diff: '!'
28 } // add a token for each prefix
29 Object.keys(PREFIXES).forEach(function (name) {
30 var prefix = PREFIXES[name]
31 var alias = []
32 if (!/^\w+$/.test(name)) {
33 // "deleted-sign" -> "deleted"
34 alias.push(/\w+/.exec(name)[0])
35 }
36 if (name === 'diff') {
37 alias.push('bold')
38 }
39 Prism.languages.diff[name] = {
40 pattern: RegExp(
41 '^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+',
42 'm'
43 ),
44 alias: alias,
45 inside: {
46 line: {
47 pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
48 lookbehind: true
49 },
50 prefix: {
51 pattern: /[\s\S]/,
52 alias: /\w+/.exec(name)[0]
53 }
54 }
55 }
56 }) // make prefixes available to Diff plugin
57 Object.defineProperty(Prism.languages.diff, 'PREFIXES', {
58 value: PREFIXES
59 })
60 })(Prism)
61}
Note: See TracBrowser for help on using the repository browser.