@diplodoc/transform 4.56.0 → 4.57.0
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/dist/css/_yfm-only.css.map +1 -1
- package/dist/css/_yfm-only.min.css.map +1 -1
- package/dist/css/base.css +69 -14
- package/dist/css/base.css.map +3 -3
- package/dist/css/base.min.css +1 -1
- package/dist/css/base.min.css.map +3 -3
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +69 -14
- package/dist/css/yfm.css.map +3 -3
- package/dist/css/yfm.min.css +1 -1
- package/dist/css/yfm.min.css.map +3 -3
- package/dist/js/_yfm-only.js.map +1 -1
- package/dist/js/_yfm-only.min.js.map +1 -1
- package/dist/js/base.js +40 -7
- package/dist/js/base.js.map +3 -3
- package/dist/js/base.min.js +1 -1
- package/dist/js/base.min.js.map +4 -4
- package/dist/js/yfm.js +40 -7
- package/dist/js/yfm.js.map +3 -3
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +4 -4
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +5 -0
- package/lib/constants.js.map +1 -0
- package/lib/md.js +4 -2
- package/lib/md.js.map +1 -1
- package/lib/plugins/anchors/constants.d.ts +2 -0
- package/lib/plugins/anchors/constants.js +19 -1
- package/lib/plugins/anchors/constants.js.map +1 -1
- package/lib/plugins/anchors/index.d.ts +1 -0
- package/lib/plugins/anchors/index.js +22 -5
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/notes/constants.d.ts +2 -1
- package/lib/plugins/notes/constants.js.map +1 -1
- package/lib/plugins/notes/index.js +1 -8
- package/lib/plugins/notes/index.js.map +1 -1
- package/lib/typings.d.ts +6 -1
- package/package.json +3 -3
- package/src/js/anchor.ts +18 -0
- package/src/js/base.ts +1 -0
- package/src/js/code.ts +1 -22
- package/src/js/utils.ts +20 -0
- package/src/scss/_anchor.scss +38 -8
- package/src/scss/_common.scss +11 -8
- package/src/transform/constants.ts +3 -0
- package/src/transform/md.ts +3 -0
- package/src/transform/plugins/anchors/constants.ts +21 -0
- package/src/transform/plugins/anchors/index.ts +52 -8
- package/src/transform/plugins/notes/constants.ts +3 -1
- package/src/transform/plugins/notes/index.ts +1 -10
- package/src/transform/typings.ts +23 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/transform/plugins/notes/constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/transform/plugins/notes/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAyC;IACxD,EAAE,EAAE;QACA,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,OAAO;KACnB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,SAAS;KACrB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,KAAK;KACjB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,YAAY;QACnB,OAAO,EAAE,UAAU;KACtB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,eAAe;KAC3B;IACD,EAAE,EAAE;QACA,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,OAAO;KACnB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,OAAO;KACnB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,WAAW;QACjB,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,OAAO;KACnB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,YAAY;QACnB,OAAO,EAAE,QAAQ;KACpB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,WAAW;KACvB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,YAAY;KACxB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,IAAI;QACV,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;KAChB;IACD,OAAO,EAAE;QACL,IAAI,EAAE,IAAI;QACV,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;KAChB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,iBAAiB;QACxB,OAAO,EAAE,SAAS;KACrB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,QAAQ;KACpB;IACD,EAAE,EAAE;QACA,IAAI,EAAE,OAAO;QACb,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,UAAU;KACtB;CACJ,CAAC"}
|
|
@@ -4,13 +4,6 @@ const utils_1 = require("../utils");
|
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/;
|
|
6
6
|
const WRONG_NOTES = /^{% note (.*)%}/;
|
|
7
|
-
function getTitle(type, originLang) {
|
|
8
|
-
let lang = originLang;
|
|
9
|
-
if (!lang || !Object.keys(constants_1.TITLES).includes(lang)) {
|
|
10
|
-
lang = 'ru';
|
|
11
|
-
}
|
|
12
|
-
return constants_1.TITLES[lang][type];
|
|
13
|
-
}
|
|
14
7
|
const matchCloseToken = (tokens, i) => {
|
|
15
8
|
return (tokens[i].type === 'paragraph_open' &&
|
|
16
9
|
tokens[i + 1].type === 'inline' &&
|
|
@@ -62,7 +55,7 @@ const index = (md, { lang, notesAutotitle, path: optPath, log }) => {
|
|
|
62
55
|
const titleClose = new state.Token('yfm_note_title_close', 'p', -1);
|
|
63
56
|
titleOpen.block = true;
|
|
64
57
|
titleClose.block = true;
|
|
65
|
-
const autotitle = notesAutotitle ?
|
|
58
|
+
const autotitle = notesAutotitle ? constants_1.TITLES[lang][type] : '';
|
|
66
59
|
titleInline.content = match[2] === undefined ? autotitle : match[2];
|
|
67
60
|
titleInline.children = [];
|
|
68
61
|
const contentOpen = new state.Token('yfm_note_content_open', 'div', 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/notes/index.ts"],"names":[],"mappings":";AAAA,iCAA2B;AAK3B,oCAA6F;AAE7F,2CAAmC;AAEnC,MAAM,QAAQ,GAAG,sDAAsD,CAAC;AACxE,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/notes/index.ts"],"names":[],"mappings":";AAAA,iCAA2B;AAK3B,oCAA6F;AAE7F,2CAAmC;AAEnC,MAAM,QAAQ,GAAG,sDAAsD,CAAC;AACxE,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,eAAe,GAAuB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACtD,OAAO,CACH,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAgB;QAC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,7 @@ export declare type Heading = {
|
|
|
22
22
|
level: number;
|
|
23
23
|
items?: Heading[];
|
|
24
24
|
};
|
|
25
|
+
export declare type Lang = 'ru' | 'en' | 'ar' | 'cs' | 'fr' | 'es' | 'he' | 'bg' | 'et' | 'el' | 'pt' | 'zh' | 'zh-tw' | 'kk' | 'tr' | 'uz';
|
|
25
26
|
export interface OptionsType {
|
|
26
27
|
tokens?: boolean;
|
|
27
28
|
vars?: Record<string, string>;
|
|
@@ -58,6 +59,10 @@ export interface OptionsType {
|
|
|
58
59
|
* Set value to `false` to disable it
|
|
59
60
|
*/
|
|
60
61
|
enableMarkdownAttrs?: boolean;
|
|
62
|
+
supportGithubAnchors?: boolean;
|
|
63
|
+
disableCommonAnchors?: boolean;
|
|
64
|
+
useCommonAnchorButtons?: boolean;
|
|
65
|
+
lang?: Lang;
|
|
61
66
|
[x: string]: unknown;
|
|
62
67
|
}
|
|
63
68
|
export interface OutputType {
|
|
@@ -77,7 +82,7 @@ export declare type EnvType<Extras extends {} = {}> = {
|
|
|
77
82
|
export interface MarkdownItPluginOpts {
|
|
78
83
|
path: string;
|
|
79
84
|
log: Logger;
|
|
80
|
-
lang:
|
|
85
|
+
lang: Lang;
|
|
81
86
|
root: string;
|
|
82
87
|
rootPublicPath: string;
|
|
83
88
|
isLintRun: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/transform",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.57.0",
|
|
4
4
|
"description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"artifact:pages": "npm run build && npm run artifact:playground",
|
|
40
40
|
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
41
41
|
"test": "jest --coverage",
|
|
42
|
-
"test:playwright:nobuild": "cd e2e && npm run playwright:docker",
|
|
43
|
-
"test:playwright": "npm run build && npm run test:playwright:nobuild",
|
|
42
|
+
"test:playwright:nobuild": "cd e2e && npm run playwright:docker --",
|
|
43
|
+
"test:playwright": "npm run build && npm run test:playwright:nobuild --",
|
|
44
44
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
45
|
"lint": "lint update && lint",
|
|
46
46
|
"lint:fix": "lint update && lint fix",
|
package/src/js/anchor.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {copyToClipboard, getEventTarget, isCustom} from './utils';
|
|
2
|
+
|
|
3
|
+
const ANCHOR_BUTTON_SELECTOR = '.yfm-clipboard-anchor';
|
|
4
|
+
|
|
5
|
+
if (typeof document !== 'undefined') {
|
|
6
|
+
document.addEventListener('click', (event) => {
|
|
7
|
+
const target = getEventTarget(event) as HTMLElement;
|
|
8
|
+
|
|
9
|
+
if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const href = target.getAttribute('data-href') || '';
|
|
14
|
+
const link = new URL(href, window.location.href).toString();
|
|
15
|
+
|
|
16
|
+
copyToClipboard(link);
|
|
17
|
+
});
|
|
18
|
+
}
|
package/src/js/base.ts
CHANGED
package/src/js/code.ts
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
import {getEventTarget, isCustom} from './utils';
|
|
1
|
+
import {copyToClipboard, getEventTarget, isCustom} from './utils';
|
|
2
2
|
|
|
3
3
|
const BUTTON_SELECTOR = '.yfm-clipboard-button';
|
|
4
4
|
|
|
5
|
-
function copyToClipboard(text: string) {
|
|
6
|
-
if (!text) {
|
|
7
|
-
return Promise.resolve();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (navigator.clipboard && typeof navigator.clipboard.writeText) {
|
|
11
|
-
return navigator.clipboard.writeText(text);
|
|
12
|
-
}
|
|
13
|
-
const textarea = document.createElement('textarea');
|
|
14
|
-
textarea.setAttribute('style', 'position: absolute; left: 1000%');
|
|
15
|
-
textarea.textContent = text;
|
|
16
|
-
document.body.append(textarea);
|
|
17
|
-
|
|
18
|
-
textarea.select();
|
|
19
|
-
document.execCommand('copy');
|
|
20
|
-
|
|
21
|
-
document.body.removeChild(textarea);
|
|
22
|
-
|
|
23
|
-
return Promise.resolve();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
5
|
function notifySuccess(svgButton: HTMLElement | null) {
|
|
27
6
|
if (!svgButton) {
|
|
28
7
|
return;
|
package/src/js/utils.ts
CHANGED
|
@@ -7,3 +7,23 @@ export const isCustom = (event: Event) => {
|
|
|
7
7
|
const target = getEventTarget(event);
|
|
8
8
|
return !target || !(target as HTMLElement).matches;
|
|
9
9
|
};
|
|
10
|
+
|
|
11
|
+
export const copyToClipboard = async (text: string) => {
|
|
12
|
+
if (!text) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText) {
|
|
17
|
+
return navigator.clipboard.writeText(text);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const textarea = document.createElement('textarea');
|
|
21
|
+
textarea.setAttribute('style', 'position: absolute; left: 1000%');
|
|
22
|
+
textarea.textContent = text;
|
|
23
|
+
document.body.append(textarea);
|
|
24
|
+
|
|
25
|
+
textarea.select();
|
|
26
|
+
document.execCommand('copy');
|
|
27
|
+
|
|
28
|
+
document.body.removeChild(textarea);
|
|
29
|
+
};
|
package/src/scss/_anchor.scss
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
.yfm {
|
|
2
|
-
h1,
|
|
3
|
-
|
|
2
|
+
h1,
|
|
3
|
+
h2,
|
|
4
|
+
h3,
|
|
5
|
+
h4,
|
|
6
|
+
h5,
|
|
7
|
+
h6 {
|
|
8
|
+
.yfm-clipboard-anchor {
|
|
9
|
+
//reset default button style
|
|
10
|
+
background: none;
|
|
11
|
+
color: var(--yfm-color-link);
|
|
12
|
+
border: none;
|
|
13
|
+
padding: 0;
|
|
14
|
+
font: inherit;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
|
|
17
|
+
&:hover {
|
|
18
|
+
color: var(--yfm-color-link-hover);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.yfm-anchor,
|
|
23
|
+
.yfm-clipboard-anchor {
|
|
4
24
|
display: inline-block;
|
|
5
25
|
width: 24px;
|
|
6
26
|
padding-right: 4px;
|
|
@@ -22,23 +42,33 @@
|
|
|
22
42
|
}
|
|
23
43
|
}
|
|
24
44
|
|
|
25
|
-
&:hover
|
|
26
|
-
|
|
45
|
+
&:hover {
|
|
46
|
+
.yfm-anchor::before,
|
|
47
|
+
.yfm-clipboard-anchor::before {
|
|
48
|
+
opacity: 1;
|
|
49
|
+
}
|
|
27
50
|
}
|
|
28
51
|
}
|
|
29
52
|
|
|
30
53
|
table {
|
|
31
|
-
h1,
|
|
32
|
-
|
|
54
|
+
h1,
|
|
55
|
+
h2,
|
|
56
|
+
h3,
|
|
57
|
+
h4,
|
|
58
|
+
h5,
|
|
59
|
+
h6 {
|
|
60
|
+
.yfm-anchor,
|
|
61
|
+
.yfm-clipboard-anchor {
|
|
33
62
|
width: 1em;
|
|
34
63
|
margin-left: -1em;
|
|
35
64
|
padding-right: 0;
|
|
36
65
|
}
|
|
37
66
|
}
|
|
38
|
-
}
|
|
67
|
+
}
|
|
39
68
|
|
|
40
69
|
.yfm-tabs {
|
|
41
|
-
.yfm-anchor::before
|
|
70
|
+
.yfm-anchor::before,
|
|
71
|
+
.yfm-clipboard-anchor::before {
|
|
42
72
|
position: absolute;
|
|
43
73
|
padding-right: 2px;
|
|
44
74
|
}
|
package/src/scss/_common.scss
CHANGED
|
@@ -297,10 +297,10 @@
|
|
|
297
297
|
padding-left: 2.2em;
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
ul ul,
|
|
301
|
-
ul ol,
|
|
302
|
-
ol ol,
|
|
303
|
-
ol ul {
|
|
300
|
+
ul ul:last-child,
|
|
301
|
+
ul ol:last-child,
|
|
302
|
+
ol ol:last-child,
|
|
303
|
+
ol ul:last-child {
|
|
304
304
|
margin-top: 0;
|
|
305
305
|
margin-bottom: 0;
|
|
306
306
|
}
|
|
@@ -309,6 +309,7 @@
|
|
|
309
309
|
word-wrap: break-word;
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
li:first-child,
|
|
312
313
|
li + li {
|
|
313
314
|
margin-block: var(--yfm-list-item-margin-block, 0.33em 0);
|
|
314
315
|
}
|
|
@@ -319,14 +320,16 @@
|
|
|
319
320
|
margin-block: var(--yfm-list-text-margin-block, 0 15px);
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
> p:only-
|
|
323
|
-
> blockquote:only-
|
|
323
|
+
> p:only-of-type,
|
|
324
|
+
> blockquote:only-of-type,
|
|
325
|
+
> p:first-child:has(+ ul),
|
|
326
|
+
> p:first-child:has(+ ol) {
|
|
324
327
|
margin-block: var(--yfm-list-text-only-margin-block, 0);
|
|
325
328
|
}
|
|
326
329
|
|
|
327
330
|
@supports selector(:has(br)) {
|
|
328
|
-
> p:only-
|
|
329
|
-
> blockquote:only-
|
|
331
|
+
> p:only-of-type:has(br),
|
|
332
|
+
> blockquote:only-of-type:has(br) {
|
|
330
333
|
margin-block: var(--yfm-list-text-margin-block, 0 15px);
|
|
331
334
|
}
|
|
332
335
|
}
|
package/src/transform/md.ts
CHANGED
|
@@ -12,6 +12,7 @@ import extractTitle from './title';
|
|
|
12
12
|
import getHeadings from './headings';
|
|
13
13
|
import sanitizeHtml, {defaultOptions, sanitizeStyles} from './sanitize';
|
|
14
14
|
import {olAttrConversion} from './plugins/ol-attr-conversion';
|
|
15
|
+
import {DEFAULT_LANG} from './constants';
|
|
15
16
|
|
|
16
17
|
function initMarkdownIt(options: OptionsType) {
|
|
17
18
|
const {
|
|
@@ -74,6 +75,7 @@ function getPluginOptions(options: OptionsType) {
|
|
|
74
75
|
extractTitle,
|
|
75
76
|
conditionsInCode = false,
|
|
76
77
|
disableLiquid = false,
|
|
78
|
+
lang = DEFAULT_LANG,
|
|
77
79
|
...customOptions
|
|
78
80
|
} = options;
|
|
79
81
|
|
|
@@ -85,6 +87,7 @@ function getPluginOptions(options: OptionsType) {
|
|
|
85
87
|
extractTitle,
|
|
86
88
|
disableLiquid,
|
|
87
89
|
log,
|
|
90
|
+
lang,
|
|
88
91
|
} as MarkdownItPluginOpts;
|
|
89
92
|
}
|
|
90
93
|
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
+
import {Lang} from '../typings';
|
|
2
|
+
|
|
1
3
|
export const CUSTOM_ID_REGEXP = /\[?{ ?#(\S+) ?}]?/g;
|
|
2
4
|
export const CUSTOM_ID_EXCEPTION = '[{#T}]';
|
|
5
|
+
|
|
6
|
+
export const ANCHOR_TITLES: Record<Lang, string> = {
|
|
7
|
+
ru: 'Скопировать ссылку',
|
|
8
|
+
en: 'Copy link',
|
|
9
|
+
ar: 'انسخ الرابط',
|
|
10
|
+
cs: 'Zkopírovat odkaz',
|
|
11
|
+
fr: 'Copier le lien',
|
|
12
|
+
es: 'Copiar enlace',
|
|
13
|
+
he: 'העתק קישור',
|
|
14
|
+
bg: 'Копиране на връзката',
|
|
15
|
+
et: 'Kopeeri viide',
|
|
16
|
+
el: 'Αντιγράψτε τον σύνδεσμο',
|
|
17
|
+
pt: 'Copiar o link',
|
|
18
|
+
zh: '复制链接',
|
|
19
|
+
'zh-tw': '複製連結',
|
|
20
|
+
kk: 'Сілтемені көшіру',
|
|
21
|
+
tr: 'Bağlantıyı kopyala',
|
|
22
|
+
uz: 'Havolani nusxalash',
|
|
23
|
+
};
|
|
@@ -8,14 +8,36 @@ import slugify from 'slugify';
|
|
|
8
8
|
import {headingInfo} from '../../utils';
|
|
9
9
|
import {MarkdownItPluginCb} from '../typings';
|
|
10
10
|
|
|
11
|
-
import {CUSTOM_ID_EXCEPTION, CUSTOM_ID_REGEXP} from './constants';
|
|
11
|
+
import {ANCHOR_TITLES, CUSTOM_ID_EXCEPTION, CUSTOM_ID_REGEXP} from './constants';
|
|
12
12
|
|
|
13
|
-
function
|
|
13
|
+
function createAnchorButtonTokens(
|
|
14
14
|
state: StateCore,
|
|
15
15
|
id: string,
|
|
16
|
+
setId = false,
|
|
17
|
+
href: string,
|
|
16
18
|
title: string,
|
|
19
|
+
) {
|
|
20
|
+
const open = new state.Token('anchor_open', 'button', 1);
|
|
21
|
+
const close = new state.Token('anchor_close', 'button', -1);
|
|
22
|
+
|
|
23
|
+
if (setId) {
|
|
24
|
+
open.attrSet('id', id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
open.attrSet('class', 'yfm-clipboard-anchor');
|
|
28
|
+
open.attrSet('data-href', href + '#' + id);
|
|
29
|
+
open.attrSet('aria-label', title);
|
|
30
|
+
open.attrSet('title', title);
|
|
31
|
+
|
|
32
|
+
return [open, close];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createAnchorLinkTokens(
|
|
36
|
+
state: StateCore,
|
|
37
|
+
id: string,
|
|
17
38
|
setId = false,
|
|
18
39
|
href: string,
|
|
40
|
+
title: string,
|
|
19
41
|
) {
|
|
20
42
|
const open = new state.Token('link_open', 'a', 1);
|
|
21
43
|
const close = new state.Token('link_close', 'a', -1);
|
|
@@ -76,13 +98,22 @@ interface Options {
|
|
|
76
98
|
extractTitle?: boolean;
|
|
77
99
|
supportGithubAnchors?: boolean;
|
|
78
100
|
disableCommonAnchors?: boolean;
|
|
101
|
+
useCommonAnchorButtons?: boolean;
|
|
79
102
|
transformLink: (v: string) => string;
|
|
80
103
|
getPublicPath?: (options: Options, v?: string) => string;
|
|
81
104
|
}
|
|
82
105
|
|
|
83
106
|
const index: MarkdownItPluginCb<Options> = (md, options) => {
|
|
84
|
-
const {
|
|
85
|
-
|
|
107
|
+
const {
|
|
108
|
+
extractTitle,
|
|
109
|
+
path,
|
|
110
|
+
log,
|
|
111
|
+
supportGithubAnchors,
|
|
112
|
+
getPublicPath,
|
|
113
|
+
disableCommonAnchors,
|
|
114
|
+
useCommonAnchorButtons,
|
|
115
|
+
lang,
|
|
116
|
+
} = options;
|
|
86
117
|
|
|
87
118
|
const plugin = (state: StateCore) => {
|
|
88
119
|
/* Do not use the plugin if it is included in the file */
|
|
@@ -97,6 +128,10 @@ const index: MarkdownItPluginCb<Options> = (md, options) => {
|
|
|
97
128
|
let i = 0;
|
|
98
129
|
const slugger = new GithubSlugger();
|
|
99
130
|
|
|
131
|
+
const createAnchorTokens = useCommonAnchorButtons
|
|
132
|
+
? createAnchorButtonTokens
|
|
133
|
+
: createAnchorLinkTokens;
|
|
134
|
+
|
|
100
135
|
while (i < tokens.length) {
|
|
101
136
|
const token = tokens[i];
|
|
102
137
|
const isHeading = token.type === 'heading_open';
|
|
@@ -141,22 +176,31 @@ const index: MarkdownItPluginCb<Options> = (md, options) => {
|
|
|
141
176
|
}
|
|
142
177
|
|
|
143
178
|
const allAnchorIds = customIds ? customIds : [id];
|
|
144
|
-
const anchorTitle =
|
|
179
|
+
const anchorTitle = useCommonAnchorButtons
|
|
180
|
+
? ANCHOR_TITLES[lang]
|
|
181
|
+
: removeCustomId(title).replace(/`/g, '');
|
|
182
|
+
|
|
145
183
|
allAnchorIds.forEach((customId) => {
|
|
146
184
|
const setId = id !== customId;
|
|
147
185
|
if (!disableCommonAnchors) {
|
|
148
|
-
const linkTokens =
|
|
186
|
+
const linkTokens = createAnchorTokens(
|
|
149
187
|
state,
|
|
150
188
|
customId,
|
|
151
|
-
anchorTitle,
|
|
152
189
|
setId,
|
|
153
190
|
href,
|
|
191
|
+
anchorTitle,
|
|
154
192
|
);
|
|
155
193
|
inlineToken.children?.unshift(...linkTokens);
|
|
156
194
|
}
|
|
157
195
|
|
|
158
196
|
if (supportGithubAnchors) {
|
|
159
|
-
const ghLinkTokens =
|
|
197
|
+
const ghLinkTokens = createAnchorTokens(
|
|
198
|
+
state,
|
|
199
|
+
ghId,
|
|
200
|
+
true,
|
|
201
|
+
href,
|
|
202
|
+
anchorTitle,
|
|
203
|
+
);
|
|
160
204
|
inlineToken.children?.unshift(...ghLinkTokens);
|
|
161
205
|
}
|
|
162
206
|
});
|
|
@@ -10,15 +10,6 @@ import {TITLES} from './constants';
|
|
|
10
10
|
const ALERT_RE = /^{% note (alert|info|tip|warning)\s*(?:"(.*?)")? %}$/;
|
|
11
11
|
const WRONG_NOTES = /^{% note (.*)%}/;
|
|
12
12
|
|
|
13
|
-
function getTitle(type: string, originLang: keyof typeof TITLES) {
|
|
14
|
-
let lang = originLang;
|
|
15
|
-
|
|
16
|
-
if (!lang || !Object.keys(TITLES).includes(lang)) {
|
|
17
|
-
lang = 'ru';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return TITLES[lang][type];
|
|
21
|
-
}
|
|
22
13
|
const matchCloseToken: MatchTokenFunction = (tokens, i) => {
|
|
23
14
|
return (
|
|
24
15
|
tokens[i].type === 'paragraph_open' &&
|
|
@@ -90,7 +81,7 @@ const index: MarkdownItPluginCb = (md, {lang, notesAutotitle, path: optPath, log
|
|
|
90
81
|
titleOpen.block = true;
|
|
91
82
|
titleClose.block = true;
|
|
92
83
|
|
|
93
|
-
const autotitle = notesAutotitle ?
|
|
84
|
+
const autotitle = notesAutotitle ? TITLES[lang][type] : '';
|
|
94
85
|
|
|
95
86
|
titleInline.content = match[2] === undefined ? autotitle : match[2];
|
|
96
87
|
titleInline.children = [];
|
package/src/transform/typings.ts
CHANGED
|
@@ -29,6 +29,24 @@ export type Heading = {
|
|
|
29
29
|
items?: Heading[];
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
export type Lang =
|
|
33
|
+
| 'ru'
|
|
34
|
+
| 'en'
|
|
35
|
+
| 'ar'
|
|
36
|
+
| 'cs'
|
|
37
|
+
| 'fr'
|
|
38
|
+
| 'es'
|
|
39
|
+
| 'he'
|
|
40
|
+
| 'bg'
|
|
41
|
+
| 'et'
|
|
42
|
+
| 'el'
|
|
43
|
+
| 'pt'
|
|
44
|
+
| 'zh'
|
|
45
|
+
| 'zh-tw'
|
|
46
|
+
| 'kk'
|
|
47
|
+
| 'tr'
|
|
48
|
+
| 'uz';
|
|
49
|
+
|
|
32
50
|
export interface OptionsType {
|
|
33
51
|
tokens?: boolean;
|
|
34
52
|
vars?: Record<string, string>;
|
|
@@ -67,6 +85,10 @@ export interface OptionsType {
|
|
|
67
85
|
* Set value to `false` to disable it
|
|
68
86
|
*/
|
|
69
87
|
enableMarkdownAttrs?: boolean;
|
|
88
|
+
supportGithubAnchors?: boolean;
|
|
89
|
+
disableCommonAnchors?: boolean;
|
|
90
|
+
useCommonAnchorButtons?: boolean;
|
|
91
|
+
lang?: Lang;
|
|
70
92
|
[x: string]: unknown;
|
|
71
93
|
}
|
|
72
94
|
|
|
@@ -89,7 +111,7 @@ export type EnvType<Extras extends {} = {}> = {
|
|
|
89
111
|
export interface MarkdownItPluginOpts {
|
|
90
112
|
path: string;
|
|
91
113
|
log: Logger;
|
|
92
|
-
lang:
|
|
114
|
+
lang: Lang;
|
|
93
115
|
root: string;
|
|
94
116
|
rootPublicPath: string;
|
|
95
117
|
isLintRun: boolean;
|