@peaceroad/markdown-it-renderer-fence 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -4
- package/index.js +125 -67
- package/package.json +4 -4
- package/test/example-lines-emphasis.txt +98 -0
- package/test/examples-highlightjs.txt +68 -0
- package/test/examples.txt +87 -0
- package/test/test.js +8 -6
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ const md = mdit({
|
|
|
22
22
|
return highlightjs.highlight(str, { language: lang }).value
|
|
23
23
|
} catch (__) {}
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return str
|
|
26
26
|
}).use(mditAttrs).use(mditRendererFence)
|
|
27
27
|
|
|
28
28
|
|
|
@@ -68,12 +68,12 @@ $ pwd
|
|
|
68
68
|
~~~
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
## Add span elements to display line number
|
|
71
|
+
## Add span elements to display line number.
|
|
72
72
|
|
|
73
73
|
Add `start` or `data-pre-start` attribute by adding attributes used markdown-it-attrs.
|
|
74
74
|
|
|
75
75
|
~~~md
|
|
76
|
-
```js {
|
|
76
|
+
```js {start="1"}
|
|
77
77
|
import mdit from 'markdonw-it'
|
|
78
78
|
const md = mdit()
|
|
79
79
|
md.render('Nyaan')
|
|
@@ -81,10 +81,36 @@ md.render('Nyaan')
|
|
|
81
81
|
~~~
|
|
82
82
|
|
|
83
83
|
~~~html
|
|
84
|
-
<pre><code class="language-js
|
|
84
|
+
<pre><code class="language-js" data-pre-start="1" style="counter-set:pre-line-number 1;"><span class="pre-line"><span class="hljs-keyword">import</span> mdit <span class="hljs-keyword">from</span> <span class="hljs-string">'markdonw-it'</span></span>
|
|
85
85
|
<span class="pre-line"><span class="hljs-keyword">const</span> md = <span class="hljs-title function_">mdit</span>()</span>
|
|
86
86
|
<span class="pre-line">md.<span class="hljs-title function_">render</span>(<span class="hljs-string">'Nyaan'</span>)</span>
|
|
87
87
|
</code></pre>
|
|
88
88
|
~~~
|
|
89
89
|
|
|
90
90
|
CSS example: <https://codepen.io/peaceroad/pen/qBGpYGK>
|
|
91
|
+
|
|
92
|
+
## Add span elements to add background color to the row ranges.
|
|
93
|
+
|
|
94
|
+
Add `em-lines` or `emphasize-lines` attribute by by adding attributes used markdown-it-attrs.
|
|
95
|
+
|
|
96
|
+
~~~md
|
|
97
|
+
``` {em-lines="2,4-5"}
|
|
98
|
+
1
|
|
99
|
+
2
|
|
100
|
+
3
|
|
101
|
+
4
|
|
102
|
+
5
|
|
103
|
+
6
|
|
104
|
+
```
|
|
105
|
+
~~~
|
|
106
|
+
|
|
107
|
+
~~~html
|
|
108
|
+
[HTML]
|
|
109
|
+
<pre><code>1
|
|
110
|
+
<span class="pre-lines-emphasis">2
|
|
111
|
+
</span>3
|
|
112
|
+
<span class="pre-lines-emphasis">4
|
|
113
|
+
5
|
|
114
|
+
</span>6
|
|
115
|
+
</code></pre>
|
|
116
|
+
~~~
|
package/index.js
CHANGED
|
@@ -1,108 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//console.log('start: ' +token.attrs)
|
|
6
|
-
for (let attr of token.attrs) {
|
|
7
|
-
if (attr[0] === 'id') {
|
|
8
|
-
idAttr.push(attr)
|
|
9
|
-
} else if (attr[0] === 'class') {
|
|
10
|
-
hasClass = true
|
|
11
|
-
classAttr.push([attr[0], opt.langPrefix + token.info + ' ' + attr[1]])
|
|
12
|
-
} else if (attr[0].startsWith('data-')) {
|
|
13
|
-
dataAttrs.push(attr)
|
|
14
|
-
} else if (attr[0] === 'style') {
|
|
15
|
-
styleAttr.push(attr)
|
|
16
|
-
} else {
|
|
17
|
-
otherAttrs.push(attr)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (!hasClass) classAttr.push(['class', opt.langPrefix + token.info])
|
|
22
|
-
let orderedAttrs = [...idAttr, ...classAttr, ...dataAttrs, ...styleAttr, ...otherAttrs]
|
|
1
|
+
//import highlightjs from 'highlight.js'
|
|
2
|
+
|
|
3
|
+
const fenceStartTag = (tagName, sAttr) => {
|
|
4
|
+
let orderedAttrs = [...sAttr.id, ...sAttr.clas, ...sAttr.data, ...sAttr.style, ...sAttr.other]
|
|
23
5
|
//console.log(orderedAttrs)
|
|
24
6
|
let tag = '<' + tagName
|
|
25
7
|
for (let attr of orderedAttrs) {
|
|
26
|
-
tag += ' ' + attr[0] + '="' + attr[1] + '"'
|
|
8
|
+
if (attr[0]) tag += ' ' + attr[0] + '="' + attr[1] + '"'
|
|
27
9
|
}
|
|
28
10
|
return tag + '>'
|
|
29
|
-
}
|
|
11
|
+
}
|
|
30
12
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!hasCodeLineStart && setNumber === -1) return content
|
|
46
|
-
token.attrs[dataIndex][0] = 'data-pre-start'
|
|
47
|
-
setNumber = token.attrs[dataIndex][1]
|
|
13
|
+
const parseEmphasizeLines = (attrValue) => {
|
|
14
|
+
const lines = []
|
|
15
|
+
let s, e
|
|
16
|
+
attrValue.split(',').forEach(range => {
|
|
17
|
+
if (range.includes('-')) {
|
|
18
|
+
[s, e] = range.split('-').map(n => parseInt(n.trim(), 10));
|
|
19
|
+
lines.push([s, e]);
|
|
20
|
+
} else {
|
|
21
|
+
s = parseInt(range.trim(), 10)
|
|
22
|
+
lines.push([s, s])
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return lines;
|
|
26
|
+
}
|
|
48
27
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
token.attrs[styleIndex][1] = token.attrs[styleIndex][1].replace(/;?$/, '; counter-set:pre-line-number ' + setNumber + ';')
|
|
53
|
-
}
|
|
28
|
+
const splitFenceBlockToLines = (content, emphasizeLines, opt, hasPreLineStart) => {
|
|
29
|
+
const br = content.match(/\r?\n/)
|
|
30
|
+
const lines = content.split(/\r?\n/)
|
|
54
31
|
lines.map((line, n) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
if (opt.setLineNumber && hasPreLineStart) {
|
|
33
|
+
const lastElementTag = line.match(/<(\w+)( +[^>]*?)>[^>]*?(<\/\1>)?[^>]*?$/)
|
|
34
|
+
if (lastElementTag && !lastElementTag[3]) {
|
|
35
|
+
line += '</span>'
|
|
36
|
+
if (n < lines.length - 2) {
|
|
37
|
+
lines[n + 1] = `<${lastElementTag[1]}${lastElementTag[2]}>` + lines[n + 1]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (n < lines.length - 1) {
|
|
41
|
+
lines[n] = '<span class="pre-line">' + line + '</span>'
|
|
60
42
|
}
|
|
61
43
|
}
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
|
|
45
|
+
if (opt.setEmphasizeLines && emphasizeLines.length > 0) {
|
|
46
|
+
if (emphasizeLines[0][0] === n + 1) {
|
|
47
|
+
lines[n] = `<span class="pre-lines-emphasis">${lines[n]}`
|
|
48
|
+
}
|
|
49
|
+
if (emphasizeLines[0][1] === n) {
|
|
50
|
+
lines[n] = '</span>' + lines[n]
|
|
51
|
+
emphasizeLines.shift()
|
|
52
|
+
}
|
|
64
53
|
}
|
|
54
|
+
|
|
65
55
|
})
|
|
66
56
|
return lines.join(br)
|
|
67
57
|
}
|
|
68
58
|
|
|
59
|
+
const setInfoAttr = (infoAttr) => {
|
|
60
|
+
let arr = []
|
|
61
|
+
let attrSets = infoAttr.trim().split(/ +/)
|
|
62
|
+
for (let attrSet of attrSets) {
|
|
63
|
+
const str = attrSet.match(/^(?:([.#])(.+)|(.+?)(?:=("')?(.*?)\1?)?)$/)
|
|
64
|
+
if (str) {
|
|
65
|
+
//console.log(str)
|
|
66
|
+
if (str[1] === '.') str[1] = 'class'
|
|
67
|
+
if (str[1] === '#') str[1] = 'id'
|
|
68
|
+
if (str[3]) {
|
|
69
|
+
str[1] = str[3]
|
|
70
|
+
str[2] = str[5] ? str[5].replace(/^['"]/, '').replace(/['"]$/, '') : ''
|
|
71
|
+
}
|
|
72
|
+
arr.push([str[1], str[2]])
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return arr
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
const getFenceHtml = (tokens, idx, env, slf, md, options) => {
|
|
70
79
|
const opt = {
|
|
71
80
|
setHighlight: true,
|
|
72
81
|
setLineNumber: true,
|
|
82
|
+
setEmphasizeLines: true,
|
|
73
83
|
langPrefix: 'language-',
|
|
74
84
|
highlight: null,
|
|
75
85
|
}
|
|
76
86
|
if (options) Object.assign(opt, options)
|
|
77
87
|
|
|
78
88
|
const token = tokens[idx]
|
|
79
|
-
//console.log(token)
|
|
80
89
|
let content = token.content
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
const infoAttr = token.info.trim().match(/{(.*)}$/)
|
|
91
|
+
if(infoAttr) {
|
|
92
|
+
token.attrs = token.attrs ? [...token.attrs, ...setInfoAttr(infoAttr[1])] : setInfoAttr(infoAttr[1])
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let lang = token.info.trim().replace(/ *({.*)?$/, '')
|
|
96
|
+
const langClass = lang && token.info !== 'samp' ? opt.langPrefix + lang : ''
|
|
97
|
+
let sAttr = {id: [], clas: [], data: [], style: [], other: []}
|
|
98
|
+
let hasPreLineStart = false
|
|
99
|
+
let preLineStart = -1
|
|
100
|
+
let emphasizeLines = []
|
|
101
|
+
if (token.attrs) {
|
|
102
|
+
//console.log('start: ' +token.attrs)
|
|
103
|
+
for (let attr of token.attrs) {
|
|
104
|
+
if (attr[0] === 'id') {
|
|
105
|
+
sAttr.id.push(attr)
|
|
106
|
+
} else if (attr[0] === 'class') {
|
|
107
|
+
const sAttrClass = langClass ? langClass + ' ' + attr[1] : attr[1]
|
|
108
|
+
const hasLang = attr[1].match(new RegExp('(?:^| )' + opt.langPrefix + '(.*)(?: |$)'))
|
|
109
|
+
if (hasLang) lang = hasLang[1]
|
|
110
|
+
sAttr.clas.push([attr[0], sAttrClass])
|
|
111
|
+
} else if (attr[0].startsWith('data-') || /^(?:pre-)?start$/.test(attr[0])) {
|
|
112
|
+
if (/^(?:(?:data-)?pre-)?start$/.test(attr[0])) {
|
|
113
|
+
hasPreLineStart = true
|
|
114
|
+
preLineStart = attr[1]
|
|
115
|
+
attr[0] = 'data-pre-start'
|
|
116
|
+
}
|
|
117
|
+
sAttr.data.push(attr)
|
|
118
|
+
} else if (/^em(?:phasize)?-lines$/.test(attr[0])) {
|
|
119
|
+
emphasizeLines = parseEmphasizeLines(attr[1])
|
|
120
|
+
} else if (attr[0] === 'style') {
|
|
121
|
+
sAttr.style.push(attr)
|
|
122
|
+
} else {
|
|
123
|
+
sAttr.other.push(attr)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (sAttr.clas.length === 0 && langClass !== '') sAttr.clas.push(['class', langClass])
|
|
128
|
+
if (hasPreLineStart && preLineStart !== -1) {
|
|
129
|
+
if (sAttr.style.length === 0) {
|
|
130
|
+
sAttr.style.push(['style', 'counter-set:pre-line-number ' + preLineStart + ';'])
|
|
131
|
+
} else {
|
|
132
|
+
sAttr.style[0][1] = sAttr.style[0][1].replace(/;?$/, '; counter-set:pre-line-number ' + preLineStart + ';')
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//console.log(JSON.stringify(sAttr))
|
|
136
|
+
if (opt.setHighlight && md.options.highlight) {
|
|
137
|
+
if (lang && lang !== 'samp' ) {
|
|
138
|
+
content = md.options.highlight(content, lang)
|
|
139
|
+
/*
|
|
140
|
+
try {
|
|
141
|
+
content = highlightjs.highlight(token.content, {language: lang}).value
|
|
142
|
+
} catch (__) {}
|
|
143
|
+
*/
|
|
84
144
|
} else {
|
|
85
145
|
content = md.utils.escapeHtml(token.content)
|
|
86
146
|
}
|
|
87
147
|
} else {
|
|
88
148
|
content = md.utils.escapeHtml(token.content)
|
|
89
149
|
}
|
|
90
|
-
if (opt.setLineNumber) {
|
|
91
|
-
content = splitFenceBlockToLines(
|
|
150
|
+
if (opt.setLineNumber || opt.setEmphasizeLines) {
|
|
151
|
+
content = splitFenceBlockToLines(content, emphasizeLines, opt, hasPreLineStart)
|
|
92
152
|
}
|
|
93
153
|
|
|
94
154
|
let fenceHtml = '<pre>'
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
fenceHtml += fenceStartTag(token, 'samp', opt);
|
|
155
|
+
let isSamp = /^(?:samp|shell|console)$/.test(lang)
|
|
156
|
+
if (isSamp) {
|
|
157
|
+
fenceHtml += fenceStartTag('samp', sAttr)
|
|
99
158
|
} else {
|
|
100
|
-
fenceHtml += fenceStartTag(
|
|
159
|
+
fenceHtml += fenceStartTag('code', sAttr)
|
|
101
160
|
}
|
|
161
|
+
|
|
102
162
|
fenceHtml += content
|
|
103
|
-
if (
|
|
104
|
-
fenceHtml += '</samp>'
|
|
105
|
-
} else if (token.info === 'shell' || token.info === 'console') {
|
|
163
|
+
if (isSamp) {
|
|
106
164
|
fenceHtml += '</samp>'
|
|
107
165
|
} else {
|
|
108
166
|
fenceHtml += '</code>'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-renderer-fence",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "In code blocks, the `<samp>` tag is used with the language keywords `samp`, `shell`, and `console`, and provides an option to display line numbers.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"repository": "https://github.com/peaceroad/p7d-markdown-it-renderer-fence",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@peaceroad/markdown-it-figure-with-p-caption": "^0.
|
|
15
|
-
"highlight.js": "^11.9.0",
|
|
14
|
+
"@peaceroad/markdown-it-figure-with-p-caption": "^0.10.1",
|
|
16
15
|
"markdown-it": "^14.1.0",
|
|
17
|
-
"markdown-it-attrs": "^4.
|
|
16
|
+
"markdown-it-attrs": "^4.2.0",
|
|
17
|
+
"highlight.js": "^11.10.0"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
``` {em-lines="3-5"}
|
|
3
|
+
1
|
|
4
|
+
2
|
|
5
|
+
3
|
|
6
|
+
4
|
|
7
|
+
5
|
|
8
|
+
6
|
|
9
|
+
```
|
|
10
|
+
[HTML]
|
|
11
|
+
<pre><code>1
|
|
12
|
+
2
|
|
13
|
+
<span class="pre-lines-emphasis">3
|
|
14
|
+
4
|
|
15
|
+
5
|
|
16
|
+
</span>6
|
|
17
|
+
</code></pre>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
[Markdown]
|
|
21
|
+
``` {em-lines="1"}
|
|
22
|
+
1
|
|
23
|
+
2
|
|
24
|
+
3
|
|
25
|
+
4
|
|
26
|
+
5
|
|
27
|
+
6
|
|
28
|
+
```
|
|
29
|
+
[HTML]
|
|
30
|
+
<pre><code><span class="pre-lines-emphasis">1
|
|
31
|
+
</span>2
|
|
32
|
+
3
|
|
33
|
+
4
|
|
34
|
+
5
|
|
35
|
+
6
|
|
36
|
+
</code></pre>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
[Markdown]
|
|
40
|
+
``` {em-lines="1-3,5-6"}
|
|
41
|
+
1
|
|
42
|
+
2
|
|
43
|
+
3
|
|
44
|
+
4
|
|
45
|
+
5
|
|
46
|
+
6
|
|
47
|
+
```
|
|
48
|
+
[HTML]
|
|
49
|
+
<pre><code><span class="pre-lines-emphasis">1
|
|
50
|
+
2
|
|
51
|
+
3
|
|
52
|
+
</span>4
|
|
53
|
+
<span class="pre-lines-emphasis">5
|
|
54
|
+
6
|
|
55
|
+
</span></code></pre>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
[Markdown]
|
|
59
|
+
``` {em-lines="3-5" start="1"}
|
|
60
|
+
1
|
|
61
|
+
2
|
|
62
|
+
3
|
|
63
|
+
4
|
|
64
|
+
5
|
|
65
|
+
6
|
|
66
|
+
```
|
|
67
|
+
[HTML]
|
|
68
|
+
<pre><code data-pre-start="1" style="counter-set:pre-line-number 1;"><span class="pre-line">1</span>
|
|
69
|
+
<span class="pre-line">2</span>
|
|
70
|
+
<span class="pre-lines-emphasis"><span class="pre-line">3</span>
|
|
71
|
+
<span class="pre-line">4</span>
|
|
72
|
+
<span class="pre-line">5</span>
|
|
73
|
+
</span><span class="pre-line">6</span>
|
|
74
|
+
</code></pre>
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
[Markdown]
|
|
78
|
+
``` {em-lines="2,4-5"}
|
|
79
|
+
1
|
|
80
|
+
2
|
|
81
|
+
3
|
|
82
|
+
4
|
|
83
|
+
5
|
|
84
|
+
6
|
|
85
|
+
```
|
|
86
|
+
[HTML]
|
|
87
|
+
<pre><code>1
|
|
88
|
+
<span class="pre-lines-emphasis">2
|
|
89
|
+
</span>3
|
|
90
|
+
<span class="pre-lines-emphasis">4
|
|
91
|
+
5
|
|
92
|
+
</span>6
|
|
93
|
+
</code></pre>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
@@ -105,3 +105,71 @@ $ pwd
|
|
|
105
105
|
/home/User
|
|
106
106
|
</samp></pre>
|
|
107
107
|
|
|
108
|
+
[Markdown]
|
|
109
|
+
``` {}
|
|
110
|
+
console.log('A test.')
|
|
111
|
+
```
|
|
112
|
+
[HTML]
|
|
113
|
+
<pre><code>console.log('A test.')
|
|
114
|
+
</code></pre>
|
|
115
|
+
|
|
116
|
+
[Markdown]
|
|
117
|
+
```js
|
|
118
|
+
console.log('A test.')
|
|
119
|
+
```
|
|
120
|
+
[HTML]
|
|
121
|
+
<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'A test.'</span>)
|
|
122
|
+
</code></pre>
|
|
123
|
+
|
|
124
|
+
[Markdown]
|
|
125
|
+
```js {}
|
|
126
|
+
console.log('A test.')
|
|
127
|
+
```
|
|
128
|
+
[HTML]
|
|
129
|
+
<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'A test.'</span>)
|
|
130
|
+
</code></pre>
|
|
131
|
+
|
|
132
|
+
[Markdown]
|
|
133
|
+
```js {}
|
|
134
|
+
console.log('A test.')
|
|
135
|
+
```
|
|
136
|
+
[HTML]
|
|
137
|
+
<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'A test.'</span>)
|
|
138
|
+
</code></pre>
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
[Markdown]
|
|
142
|
+
~~~ {}
|
|
143
|
+
console.log('A test.')
|
|
144
|
+
~~~
|
|
145
|
+
[HTML]
|
|
146
|
+
<pre><code>console.log('A test.')
|
|
147
|
+
</code></pre>
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
[Markdown]
|
|
151
|
+
~~~js {}
|
|
152
|
+
console.log('A test.')
|
|
153
|
+
~~~
|
|
154
|
+
[HTML]
|
|
155
|
+
<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'A test.'</span>)
|
|
156
|
+
</code></pre>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
[Markdown]
|
|
160
|
+
```{.language-js}
|
|
161
|
+
console.log('A test.')
|
|
162
|
+
```
|
|
163
|
+
[HTML]
|
|
164
|
+
<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'A test.'</span>)
|
|
165
|
+
</code></pre>
|
|
166
|
+
|
|
167
|
+
[Markdown]
|
|
168
|
+
```conf
|
|
169
|
+
[Service]
|
|
170
|
+
Environment="OLLAMA_HOST=0.0.0.0"
|
|
171
|
+
```
|
|
172
|
+
[HTML]
|
|
173
|
+
<pre><code class="language-conf">[Service]
|
|
174
|
+
Environment="OLLAMA_HOST=0.0.0.0"
|
|
175
|
+
</code></pre>
|
package/test/examples.txt
CHANGED
|
@@ -41,3 +41,90 @@ $ pwd
|
|
|
41
41
|
/home/User
|
|
42
42
|
</samp></pre>
|
|
43
43
|
|
|
44
|
+
|
|
45
|
+
[Markdown]
|
|
46
|
+
```
|
|
47
|
+
console.log('A test.')
|
|
48
|
+
```
|
|
49
|
+
[HTML]
|
|
50
|
+
<pre><code>console.log('A test.')
|
|
51
|
+
</code></pre>
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
[Markdown]
|
|
55
|
+
``` {}
|
|
56
|
+
console.log('A test.')
|
|
57
|
+
```
|
|
58
|
+
[HTML]
|
|
59
|
+
<pre><code>console.log('A test.')
|
|
60
|
+
</code></pre>
|
|
61
|
+
|
|
62
|
+
[Markdown]
|
|
63
|
+
```js {}
|
|
64
|
+
console.log('A test.')
|
|
65
|
+
```
|
|
66
|
+
[HTML]
|
|
67
|
+
<pre><code class="language-js">console.log('A test.')
|
|
68
|
+
</code></pre>
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
[Markdown]
|
|
72
|
+
```js {}
|
|
73
|
+
console.log('A test.')
|
|
74
|
+
```
|
|
75
|
+
[HTML]
|
|
76
|
+
<pre><code class="language-js">console.log('A test.')
|
|
77
|
+
</code></pre>
|
|
78
|
+
|
|
79
|
+
[Markdown]
|
|
80
|
+
```js {.style #id}
|
|
81
|
+
console.log('A test.')
|
|
82
|
+
```
|
|
83
|
+
[HTML]
|
|
84
|
+
<pre><code id="id" class="language-js style">console.log('A test.')
|
|
85
|
+
</code></pre>
|
|
86
|
+
|
|
87
|
+
[Markdown]
|
|
88
|
+
```js {.style}
|
|
89
|
+
console.log('A test.')
|
|
90
|
+
```
|
|
91
|
+
[HTML]
|
|
92
|
+
<pre><code class="language-js style">console.log('A test.')
|
|
93
|
+
</code></pre>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
[Markdown]
|
|
97
|
+
~~~ {}
|
|
98
|
+
console.log('A test.')
|
|
99
|
+
~~~
|
|
100
|
+
[HTML]
|
|
101
|
+
<pre><code>console.log('A test.')
|
|
102
|
+
</code></pre>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
[Markdown]
|
|
106
|
+
~~~js {}
|
|
107
|
+
console.log('A test.')
|
|
108
|
+
~~~
|
|
109
|
+
[HTML]
|
|
110
|
+
<pre><code class="language-js">console.log('A test.')
|
|
111
|
+
</code></pre>
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
[Markdown]
|
|
115
|
+
```{.language-js}
|
|
116
|
+
console.log('A test.')
|
|
117
|
+
```
|
|
118
|
+
[HTML]
|
|
119
|
+
<pre><code class="language-js">console.log('A test.')
|
|
120
|
+
</code></pre>
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
[Markdown]
|
|
124
|
+
``` js {start="3" aria-label="LABEL"}
|
|
125
|
+
console.log('A test.')
|
|
126
|
+
```
|
|
127
|
+
[HTML]
|
|
128
|
+
<pre><code class="language-js" data-pre-start="3" style="counter-set:pre-line-number 3;" aria-label="LABEL"><span class="pre-line">console.log('A test.')</span>
|
|
129
|
+
</code></pre>
|
|
130
|
+
|
package/test/test.js
CHANGED
|
@@ -5,13 +5,13 @@ import mdit from 'markdown-it'
|
|
|
5
5
|
|
|
6
6
|
import mditFigureWithPCaption from '@peaceroad/markdown-it-figure-with-p-caption'
|
|
7
7
|
import mditRendererFence from '../index.js'
|
|
8
|
-
import
|
|
8
|
+
import mditAttrs from 'markdown-it-attrs'
|
|
9
9
|
import highlightjs from 'highlight.js'
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
let opt = {}
|
|
13
13
|
|
|
14
|
-
const md = mdit({ html: true }).use(mditRendererFence).use(
|
|
14
|
+
const md = mdit({ html: true }).use(mditRendererFence).use(mditAttrs)
|
|
15
15
|
const mdHighlightJs = mdit({
|
|
16
16
|
html: true,
|
|
17
17
|
langPrefix: 'language-',
|
|
@@ -22,10 +22,10 @@ const mdHighlightJs = mdit({
|
|
|
22
22
|
return highlightjs.highlight(str, { language: lang }).value
|
|
23
23
|
} catch (__) {}
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return str
|
|
26
26
|
}
|
|
27
|
-
}).use(mditRendererFence, opt).use(
|
|
28
|
-
|
|
27
|
+
}).use(mditRendererFence, opt).use(mditAttrs)
|
|
28
|
+
const mdLinesEmphasis = mdit({ html: true }).use(mditRendererFence).use(mditAttrs)
|
|
29
29
|
|
|
30
30
|
let __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
31
31
|
const isWindows = (process.platform === 'win32')
|
|
@@ -36,6 +36,7 @@ if (isWindows) {
|
|
|
36
36
|
const testData = {
|
|
37
37
|
noOption: __dirname + path.sep + 'examples.txt',
|
|
38
38
|
highlightjs: __dirname + path.sep + 'examples-highlightjs.txt',
|
|
39
|
+
linesEmphasis: __dirname + path.sep + 'example-lines-emphasis.txt',
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const getTestData = (pat) => {
|
|
@@ -87,7 +88,7 @@ const runTest = (process, pat, pass, testId) => {
|
|
|
87
88
|
|
|
88
89
|
while(n <= end) {
|
|
89
90
|
if (!ms[n]
|
|
90
|
-
|
|
91
|
+
//|| n != 2
|
|
91
92
|
) {
|
|
92
93
|
n++
|
|
93
94
|
continue
|
|
@@ -114,5 +115,6 @@ const runTest = (process, pat, pass, testId) => {
|
|
|
114
115
|
let pass = true
|
|
115
116
|
pass = runTest(md, testData.noOption, pass)
|
|
116
117
|
pass = runTest(mdHighlightJs, testData.highlightjs, pass)
|
|
118
|
+
pass = runTest(mdLinesEmphasis, testData.linesEmphasis, pass)
|
|
117
119
|
|
|
118
120
|
if (pass) console.log('Passed all test.')
|