-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-support.js
77 lines (70 loc) · 1.75 KB
/
build-support.js
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
/**
* @import {Root, Table} from 'mdast'
*/
import {zone} from 'mdast-zone'
import {udhr} from 'udhr'
import {min} from '../index.js'
const data = await min()
/**
* @returns
* Transform.
*/
export default function remarkInjectSupport() {
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
return function (tree) {
zone(tree, 'support', function (start, _, end) {
/** @type {Table} */
const table = {
type: 'table',
align: [],
children: [
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'Code'}]},
{type: 'tableCell', children: [{type: 'text', value: 'Name'}]}
]
}
]
}
for (const info of Object.values(udhr)) {
if (!(info.code in data)) {
continue
}
const ohchrUrl = info.ohchr
? /^https?:/.test(info.ohchr)
? info.ohchr
: 'https://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=' +
info.ohchr
: undefined
table.children.push({
type: 'tableRow',
children: [
{
type: 'tableCell',
children: [{type: 'inlineCode', value: info.code}]
},
{
type: 'tableCell',
children: ohchrUrl
? [
{
type: 'link',
url: ohchrUrl,
children: [{type: 'text', value: info.name}]
}
]
: [{type: 'text', value: info.name}]
}
]
})
}
return [start, table, end]
})
}
}