diff options
Diffstat (limited to 'packages/dev-tools-pages/ts/highlight.tsx')
-rw-r--r-- | packages/dev-tools-pages/ts/highlight.tsx | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/packages/dev-tools-pages/ts/highlight.tsx b/packages/dev-tools-pages/ts/highlight.tsx index cef03904a..02f4a753e 100644 --- a/packages/dev-tools-pages/ts/highlight.tsx +++ b/packages/dev-tools-pages/ts/highlight.tsx @@ -1,6 +1,7 @@ import * as hljs from 'highlight.js/lib/highlight'; import * as javascript from 'highlight.js/lib/languages/javascript'; import * as json from 'highlight.js/lib/languages/json'; +import * as _ from 'lodash'; hljs.registerLanguage('javascript', javascript); hljs.registerLanguage('json', json); @@ -16,28 +17,25 @@ const PATCH_TYPES: PatchInterface = { }; function diffHighlight(language: string, code: any, gutter: any): string { - return code - .split(/\r?\n/g) - .map((line: string, index: number) => { - let type; - let currentLine = line; + return _.map(code.split(/\r?\n/g), (line: string, index: number) => { + let type; + let currentLine = line; - if (/^-{3} [^-]+ -{4}$|^\*{3} [^*]+ \*{4}$|^@@ [^@]+ @@$/.test(currentLine)) { - type = 'chunk'; - } else if (/^Index: |^[+\-*]{3}|^[*=]{5,}$/.test(currentLine)) { - type = 'header'; - } else { - type = PATCH_TYPES[currentLine[0]] || 'null'; - currentLine = currentLine.replace(/^[+\-! ]/, ''); - } + if (/^-{3} [^-]+ -{4}$|^\*{3} [^*]+ \*{4}$|^@@ [^@]+ @@$/.test(currentLine)) { + type = 'chunk'; + } else if (/^Index: |^[+\-*]{3}|^[*=]{5,}$/.test(currentLine)) { + type = 'header'; + } else { + type = PATCH_TYPES[currentLine[0]] || 'null'; + currentLine = currentLine.replace(/^[+\-! ]/, ''); + } - const g = gutter[index]; + const g = gutter[index]; - return `<span data-gutter="${g !== undefined ? `${g}x` : ''}" class="line-${type}">${ - hljs.highlight(language, currentLine).value - }</span>`; - }) - .join('\n'); + return `<span data-gutter="${g !== undefined ? `${g}x` : ''}" class="line-${type}">${ + hljs.highlight(language, currentLine).value + }</span>`; + }).join('\n'); } interface HighlightProps { |