-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (29 loc) · 952 Bytes
/
index.js
File metadata and controls
32 lines (29 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
const converter = new (require('showdown').Converter)()
module.exports = () => [
{
type: 'lang',
filter: text => text.replace(
/^\[\^([\d\w]+)\]:\s*((\n+(\s{2,4}|\t).+)+)$/mg,
(str, name, rawContent, _, padding) => {
const content = converter.makeHtml(rawContent.replace(new RegExp(`^${padding}`, 'gm'), ''))
return `<div class="footnote" id="footnote-${name}"><a href="#footnote-${name}"><sup>[${name}]</sup></a>:${content}</div>`
}
)
},
{
type: 'lang',
filter: text => text.replace(
/^\[\^([\d\w]+)\]:( |\n)((.+\n)*.+)$/mg,
(str, name, _, content) =>
`<small class="footnote" id="footnote-${name}"><a href="#footnote-${name}"><sup>[${name}]</sup></a>: ${content}</small>`
)
},
{
type: 'lang',
filter: text => text.replace(
/\[\^([\d\w]+)\]/mg,
(str, name) => `<a href="#footnote-${name}"><sup>[${name}]</sup></a>`
)
}
]