Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
81 lines (71 loc) · 2.45 KB
/
Copy pathindex.js
File metadata and controls
81 lines (71 loc) · 2.45 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
constfs=require('fs')
constmarked=require('marked')
constsourcePath='index.md'
consttargetPath='index.html'
consthljsStyle='googlecode'
consthljsVersion='9.12.0'
marked.setOptions({
renderer: newmarked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
})
Object.prototype.pipe=function(fn){
returnfn(this)
}
constesc=s=>s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,'\\$&')
constexternalLink='<i class="fas fa-xs fa-external-link-alt"></i>'
consthtml=fs
.readFileSync(sourcePath)
.toString()
.pipe(s=>marked(String(s)))
.replace(/id="a-[^"]*"/g,'')
.replace(/+$/gm,'')
.replace(
/<ahref="(http[^"]*)">(([^<]|<[^/]|<[/][^a])*)<[/]a>/g,
(match,href,content)=>
content.startsWith('<img ')
? `<a target="_blank" href="${href}">${content}</a>`
: `<a target="_blank" href="${href}">${content}${externalLink}</a>`
)
.replace(/<codeclass="language-([a-z]*)">/g,'<code class="hljs lang-$1">')
.pipe(
s=>`<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="github.css">
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/${hljsVersion}/styles/${hljsStyle}.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<meta charset="utf-8">
<title>C++ submodule manager</title>
</head>
<body class="markdown-body">
${s}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/${hljsVersion}/highlight.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/${hljsVersion}/languages/bash.min.js"></script>
<script type="text/javascript" src="init-hljs.js"></script>
<script type="text/javascript" src="tooltips.js"></script>
</body>
</html>`
)
fs.writeFileSync(targetPath,html)
constidRE=/\bid\s*=\s*"([^"]+)"/g
constids=newMap()
for(;;){
constm=idRE.exec(html)
if(!m)break
if(ids.has(m[1]))console.warn(`Duplicate id '${m[1]}'`)
ids.set(m[1],1)
}
consthhrefRE=/\bhref="#([^"]+)"/g
for(;;){
constm=hhrefRE.exec(html)
if(!m)break
if(!ids.has(m[1]))
console.warn(`Target of internal link '${m[1]}' does not exist.`)
}