File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * This will convert every lines that is not
3
+ * starts with - or + (diff-support) to be encase
4
+ * inside a div with the class of hljs-line
5
+ *
6
+ * @param {* } hljs
7
+ * @returns
8
+ */
9
+
10
+ export default function ( hljs ) {
11
+ function highlight ( code , options ) {
12
+ const result = hljs . highlight ( code , { ...options , language : options . language } )
13
+ const lines = result . value . split ( '\n' )
14
+
15
+ const processedLines = lines . map ( line => {
16
+ const hasAddition = line . startsWith ( `<span class="hljs-addition">+` )
17
+ const hasDeletion = line . startsWith ( `<span class="hljs-deletion">-` )
18
+ const isEmpty = line === ""
19
+ let outputLine = line . replace ( "+ " , "<span class='hljs-indicator'>+</span>" ) . replace ( "- " , "<span class='hljs-indicator'>-</span>" ) ;
20
+ if ( ! isEmpty && ! hasAddition && ! hasDeletion ) {
21
+ outputLine = `<span class="hljs-line">${ line } </span>`
22
+ }
23
+
24
+ return outputLine
25
+ } ) . join ( '\n' )
26
+
27
+ return {
28
+ ...result ,
29
+ code,
30
+ value : processedLines ,
31
+ language : options . language
32
+ }
33
+ }
34
+
35
+ return {
36
+ ...hljs ,
37
+ highlight ( codeOrLanguageName , optionsOrCode , ignoreIllegals = false ) {
38
+ return typeof optionsOrCode === 'string'
39
+ ? highlight ( optionsOrCode , { language : codeOrLanguageName , ignoreIllegals } )
40
+ : highlight ( codeOrLanguageName , optionsOrCode )
41
+ }
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments