@diplodoc/transform 4.38.2 → 4.40.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 +0 -28
- package/dist/css/_yfm-only.css.map +3 -3
- package/dist/css/_yfm-only.min.css +1 -1
- package/dist/css/_yfm-only.min.css.map +3 -3
- package/dist/css/base.css.map +1 -1
- package/dist/css/base.min.css.map +1 -1
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +26 -29
- 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.js +8 -8
- package/lib/plugins/cut.js +1 -1
- package/lib/plugins/cut.js.map +1 -1
- package/lib/plugins/file/const.d.ts +1 -25
- package/lib/plugins/file/const.js +12 -43
- package/lib/plugins/file/const.js.map +1 -1
- package/lib/plugins/file/file.d.ts +1 -8
- package/lib/plugins/file/file.js +0 -60
- package/lib/plugins/file/file.js.map +1 -1
- package/lib/plugins/file/index.d.ts +2 -4
- package/lib/plugins/file/index.js +2 -7
- package/lib/plugins/file/index.js.map +1 -1
- package/package.json +3 -2
- package/src/scss/_yfm-only.scss +2 -3
- package/src/scss/yfm.scss +1 -0
- package/src/transform/plugins/cut.ts +1 -1
- package/src/transform/plugins/file/const.ts +13 -45
- package/src/transform/plugins/file/file.ts +1 -82
- package/src/transform/plugins/file/index.ts +2 -10
- package/src/scss/_file.scss +0 -33
- package/src/transform/plugins/file/README.md +0 -34
package/dist/js/yfm.js
CHANGED
|
@@ -60,15 +60,15 @@
|
|
|
60
60
|
|
|
61
61
|
// node_modules/@diplodoc/cut-extension/build/runtime/index.js
|
|
62
62
|
(() => {
|
|
63
|
-
var
|
|
64
|
-
var
|
|
63
|
+
var I = "yfm_cut", i = { CUT: ".yfm .yfm-cut", TITLE: ".yfm .yfm-cut-title", CONTENT: ".yfm .yfm-cut-content" }, o = { OPEN: "open" };
|
|
64
|
+
var C = (e) => {
|
|
65
65
|
let t = e.composedPath();
|
|
66
66
|
return Array.isArray(t) && t.length > 0 ? t[0] : e.target;
|
|
67
67
|
}, n = (e) => {
|
|
68
|
-
let t =
|
|
68
|
+
let t = C(e);
|
|
69
69
|
return !t || !t.matches;
|
|
70
70
|
};
|
|
71
|
-
var
|
|
71
|
+
var c = class {
|
|
72
72
|
constructor(t) {
|
|
73
73
|
__publicField(this, "__doc");
|
|
74
74
|
__publicField(this, "_onDocClick", (t) => {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
}
|
|
88
88
|
focusActiveCut() {
|
|
89
89
|
let t = window.location.hash.slice(1), g = document.getElementById(t);
|
|
90
|
-
g instanceof HTMLElement && g.matches(i.CUT) && (g.classList.toggle(
|
|
90
|
+
g instanceof HTMLElement && g.matches(i.CUT) && (g.classList.toggle(o.OPEN), g.setAttribute("open", "true"), setTimeout(() => {
|
|
91
91
|
g.classList.add("cut-highlight"), g.scrollIntoView();
|
|
92
92
|
}, 70), setTimeout(() => {
|
|
93
93
|
g.classList.remove("cut-highlight");
|
|
@@ -95,15 +95,15 @@
|
|
|
95
95
|
}
|
|
96
96
|
_findTitleInPath(t) {
|
|
97
97
|
var _a, _b;
|
|
98
|
-
let g =
|
|
98
|
+
let g = C(t);
|
|
99
99
|
return this._matchTitle(g) ? g : (_b = (_a = t.composedPath) == null ? void 0 : _a.call(t)) == null ? void 0 : _b.find(this._matchTitle);
|
|
100
100
|
}
|
|
101
101
|
_toggleCut(t) {
|
|
102
102
|
var _a;
|
|
103
|
-
(_a = t.parentElement) == null ? void 0 : _a.classList.toggle(
|
|
103
|
+
(_a = t.parentElement) == null ? void 0 : _a.classList.toggle(o.OPEN);
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
|
-
typeof window < "u" && typeof document < "u" && !window[
|
|
106
|
+
typeof window < "u" && typeof document < "u" && !window[I] && (window[I] = new c(document));
|
|
107
107
|
})();
|
|
108
108
|
|
|
109
109
|
// node_modules/@diplodoc/tabs-extension/build/runtime/index.js
|
package/lib/plugins/cut.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const cut_extension_1 = require("@diplodoc/cut-extension");
|
|
3
|
-
module.exports = (0, cut_extension_1.transform)({ bundle: false });
|
|
3
|
+
module.exports = (0, cut_extension_1.transform)({ bundle: false, directiveSyntax: 'disabled' });
|
|
4
4
|
//# sourceMappingURL=cut.js.map
|
package/lib/plugins/cut.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cut.js","sourceRoot":"","sources":["../../src/transform/plugins/cut.ts"],"names":[],"mappings":";AAAA,2DAAkD;AAElD,iBAAS,IAAA,yBAAS,EAAC,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"cut.js","sourceRoot":"","sources":["../../src/transform/plugins/cut.ts"],"names":[],"mappings":";AAAA,2DAAkD;AAElD,iBAAS,IAAA,yBAAS,EAAC,EAAC,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,UAAU,EAAC,CAAC,CAAC"}
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
Src = "src",
|
|
3
|
-
Name = "name",
|
|
4
|
-
Lang = "lang"
|
|
5
|
-
}
|
|
6
|
-
export declare enum LinkHtmlAttr {
|
|
7
|
-
Download = "download",
|
|
8
|
-
Href = "href",
|
|
9
|
-
HrefLang = "hreflang",
|
|
10
|
-
Media = "media",
|
|
11
|
-
Ping = "ping",
|
|
12
|
-
ReferrerPolicy = "referrerpolicy",
|
|
13
|
-
Rel = "rel",
|
|
14
|
-
Target = "target",
|
|
15
|
-
Type = "type"
|
|
16
|
-
}
|
|
17
|
-
export declare const FILE_TO_LINK_ATTRS_MAP: Record<FileSpecialAttr, LinkHtmlAttr>;
|
|
18
|
-
export declare const RULE_NAME = "yfm_file_inline";
|
|
19
|
-
export declare const KNOWN_ATTRS: readonly string[];
|
|
20
|
-
export declare const REQUIRED_ATTRS: readonly string[];
|
|
21
|
-
export declare const FILE_TOKEN = "yfm_file";
|
|
1
|
+
export { FileSpecialAttr, FILE_TO_LINK_ATTRS_MAP, FILE_REQUIRED_ATTRS as REQUIRED_ATTRS, FILE_TOKEN, FILE_KNOWN_ATTRS as KNOWN_ATTRS, FileClassName, FILE_RULE_NAME as RULE_NAME, FileHtmlAttr as LinkHtmlAttr, } from '@diplodoc/file-extension';
|
|
22
2
|
export declare const PREFIX = "{% file ";
|
|
23
3
|
export declare const PREFIX_LENGTH: number;
|
|
24
|
-
export declare enum FileClassName {
|
|
25
|
-
Link = "yfm-file",
|
|
26
|
-
Icon = "yfm-file__icon"
|
|
27
|
-
}
|
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(function (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
LinkHtmlAttr["HrefLang"] = "hreflang";
|
|
16
|
-
LinkHtmlAttr["Media"] = "media";
|
|
17
|
-
LinkHtmlAttr["Ping"] = "ping";
|
|
18
|
-
LinkHtmlAttr["ReferrerPolicy"] = "referrerpolicy";
|
|
19
|
-
LinkHtmlAttr["Rel"] = "rel";
|
|
20
|
-
LinkHtmlAttr["Target"] = "target";
|
|
21
|
-
LinkHtmlAttr["Type"] = "type";
|
|
22
|
-
})(LinkHtmlAttr = exports.LinkHtmlAttr || (exports.LinkHtmlAttr = {}));
|
|
23
|
-
exports.FILE_TO_LINK_ATTRS_MAP = {
|
|
24
|
-
[FileSpecialAttr.Src]: LinkHtmlAttr.Href,
|
|
25
|
-
[FileSpecialAttr.Name]: LinkHtmlAttr.Download,
|
|
26
|
-
[FileSpecialAttr.Lang]: LinkHtmlAttr.HrefLang,
|
|
27
|
-
};
|
|
28
|
-
exports.RULE_NAME = 'yfm_file_inline';
|
|
29
|
-
exports.KNOWN_ATTRS = [
|
|
30
|
-
FileSpecialAttr.Src,
|
|
31
|
-
FileSpecialAttr.Name,
|
|
32
|
-
FileSpecialAttr.Lang,
|
|
33
|
-
LinkHtmlAttr.ReferrerPolicy,
|
|
34
|
-
LinkHtmlAttr.Rel,
|
|
35
|
-
LinkHtmlAttr.Target,
|
|
36
|
-
LinkHtmlAttr.Type,
|
|
37
|
-
];
|
|
38
|
-
exports.REQUIRED_ATTRS = [FileSpecialAttr.Src, FileSpecialAttr.Name];
|
|
39
|
-
exports.FILE_TOKEN = 'yfm_file';
|
|
40
|
-
exports.PREFIX = '{% file ';
|
|
3
|
+
exports.PREFIX_LENGTH = exports.PREFIX = exports.LinkHtmlAttr = exports.RULE_NAME = exports.FileClassName = exports.KNOWN_ATTRS = exports.FILE_TOKEN = exports.REQUIRED_ATTRS = exports.FILE_TO_LINK_ATTRS_MAP = exports.FileSpecialAttr = void 0;
|
|
4
|
+
const file_extension_1 = require("@diplodoc/file-extension");
|
|
5
|
+
var file_extension_2 = require("@diplodoc/file-extension");
|
|
6
|
+
Object.defineProperty(exports, "FileSpecialAttr", { enumerable: true, get: function () { return file_extension_2.FileSpecialAttr; } });
|
|
7
|
+
Object.defineProperty(exports, "FILE_TO_LINK_ATTRS_MAP", { enumerable: true, get: function () { return file_extension_2.FILE_TO_LINK_ATTRS_MAP; } });
|
|
8
|
+
Object.defineProperty(exports, "REQUIRED_ATTRS", { enumerable: true, get: function () { return file_extension_2.FILE_REQUIRED_ATTRS; } });
|
|
9
|
+
Object.defineProperty(exports, "FILE_TOKEN", { enumerable: true, get: function () { return file_extension_2.FILE_TOKEN; } });
|
|
10
|
+
Object.defineProperty(exports, "KNOWN_ATTRS", { enumerable: true, get: function () { return file_extension_2.FILE_KNOWN_ATTRS; } });
|
|
11
|
+
Object.defineProperty(exports, "FileClassName", { enumerable: true, get: function () { return file_extension_2.FileClassName; } });
|
|
12
|
+
Object.defineProperty(exports, "RULE_NAME", { enumerable: true, get: function () { return file_extension_2.FILE_RULE_NAME; } });
|
|
13
|
+
Object.defineProperty(exports, "LinkHtmlAttr", { enumerable: true, get: function () { return file_extension_2.FileHtmlAttr; } });
|
|
14
|
+
exports.PREFIX = file_extension_1.FILE_MARKUP_PREFIX;
|
|
41
15
|
exports.PREFIX_LENGTH = exports.PREFIX.length;
|
|
42
|
-
var FileClassName;
|
|
43
|
-
(function (FileClassName) {
|
|
44
|
-
FileClassName["Link"] = "yfm-file";
|
|
45
|
-
FileClassName["Icon"] = "yfm-file__icon";
|
|
46
|
-
})(FileClassName = exports.FileClassName || (exports.FileClassName = {}));
|
|
47
16
|
//# sourceMappingURL=const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/transform/plugins/file/const.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/transform/plugins/file/const.ts"],"names":[],"mappings":";;;AAAA,6DAA4D;AAC5D,2DASkC;AAR9B,iHAAA,eAAe,OAAA;AACf,wHAAA,sBAAsB,OAAA;AACtB,gHAAA,mBAAmB,OAAkB;AACrC,4GAAA,UAAU,OAAA;AACV,6GAAA,gBAAgB,OAAe;AAC/B,+GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAa;AAC3B,8GAAA,YAAY,OAAgB;AAGnB,QAAA,MAAM,GAAG,mCAAkB,CAAC;AAC5B,QAAA,aAAa,GAAG,cAAM,CAAC,MAAM,CAAC"}
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type ParserInline from 'markdown-it/lib/parser_inline';
|
|
3
|
-
import type Renderer from 'markdown-it/lib/renderer';
|
|
4
|
-
export declare type FileOptions = {
|
|
5
|
-
fileExtraAttrs: [string, string][];
|
|
6
|
-
};
|
|
7
|
-
export declare const fileRenderer: (md: MarkdownIt) => Renderer.RenderRule;
|
|
8
|
-
export declare const fileParser: (_md: MarkdownIt, opts?: FileOptions) => ParserInline.RuleInline;
|
|
1
|
+
export type { PluginOptions as FileOptions } from '@diplodoc/file-extension';
|
package/lib/plugins/file/file.js
CHANGED
|
@@ -1,63 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fileParser = exports.fileRenderer = void 0;
|
|
4
|
-
const const_1 = require("./const");
|
|
5
|
-
const fileRenderer = (md) => {
|
|
6
|
-
const iconHtml = `<span class="${md.utils.escapeHtml(const_1.FileClassName.Icon)}"></span>`;
|
|
7
|
-
return (tokens, idx, _opts, _env, self) => {
|
|
8
|
-
const token = tokens[idx];
|
|
9
|
-
return `<a${self.renderAttrs(token)}>${iconHtml}${md.utils.escapeHtml(token.content)}</a>`;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
exports.fileRenderer = fileRenderer;
|
|
13
|
-
const fileParser = (_md, opts) => {
|
|
14
|
-
return (state, silent) => {
|
|
15
|
-
if (state.src.substring(state.pos, state.pos + const_1.PREFIX_LENGTH) !== const_1.PREFIX)
|
|
16
|
-
return false;
|
|
17
|
-
// the rest of line after '{% file '
|
|
18
|
-
const searchStr = state.src.slice(state.pos + const_1.PREFIX_LENGTH, state.posMax);
|
|
19
|
-
// loking for pattern 'src="..." name="..." etc="value" %}'
|
|
20
|
-
const matchResult = searchStr.match(/^((?:\s*\w+=(?:"[^"]+"|'[^']+')\s)+)\s*%}/);
|
|
21
|
-
if (!matchResult)
|
|
22
|
-
return false;
|
|
23
|
-
const paramsGroupLength = matchResult[0].length; // '(src="..." name="...")'.length
|
|
24
|
-
const paramsStr = matchResult[1]; // 'src="..." name="..."'
|
|
25
|
-
// find pairs of key="foo" or key='bar'
|
|
26
|
-
const params = paramsStr.match(/\w+=(?:"[^"]+"|'[^']+')/g);
|
|
27
|
-
if (!params)
|
|
28
|
-
return false;
|
|
29
|
-
const attrsObj = {};
|
|
30
|
-
params.forEach((param) => {
|
|
31
|
-
const indexKey = param.indexOf('=');
|
|
32
|
-
const key = param.slice(0, indexKey);
|
|
33
|
-
const value = param.slice(indexKey + 2, -1);
|
|
34
|
-
if (const_1.KNOWN_ATTRS.includes(key) && value) {
|
|
35
|
-
attrsObj[key] = value;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const hasAllRequiredAttrs = const_1.REQUIRED_ATTRS.every((attr) => attr in attrsObj);
|
|
39
|
-
if (!hasAllRequiredAttrs)
|
|
40
|
-
return false;
|
|
41
|
-
if (!silent) {
|
|
42
|
-
const token = state.push(const_1.FILE_TOKEN, '', 0);
|
|
43
|
-
token.block = false;
|
|
44
|
-
token.markup = const_1.PREFIX;
|
|
45
|
-
token.content = attrsObj[const_1.FileSpecialAttr.Name];
|
|
46
|
-
token.attrs = Object.entries(attrsObj);
|
|
47
|
-
token.attrSet('class', const_1.FileClassName.Link);
|
|
48
|
-
for (const attr of token.attrs) {
|
|
49
|
-
if (attr[0] in const_1.FILE_TO_LINK_ATTRS_MAP) {
|
|
50
|
-
attr[0] = const_1.FILE_TO_LINK_ATTRS_MAP[attr[0]];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (Array.isArray(opts === null || opts === void 0 ? void 0 : opts.fileExtraAttrs)) {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
55
|
-
token.attrs.push(...opts.fileExtraAttrs);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
state.pos = state.pos + const_1.PREFIX_LENGTH + paramsGroupLength;
|
|
59
|
-
return true;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
exports.fileParser = fileParser;
|
|
63
3
|
//# sourceMappingURL=file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/transform/plugins/file/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/transform/plugins/file/file.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const filePlugin: PluginWithOptions<FileOptions>;
|
|
4
|
-
export = filePlugin;
|
|
1
|
+
declare const _default: import("markdown-it").PluginWithOptions<import("@diplodoc/file-extension").PluginOptions>;
|
|
2
|
+
export = _default;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const filePlugin = (md, opts) => {
|
|
5
|
-
md.inline.ruler.push(const_1.RULE_NAME, (0, file_1.fileParser)(md, opts));
|
|
6
|
-
md.renderer.rules[const_1.FILE_TOKEN] = (0, file_1.fileRenderer)(md);
|
|
7
|
-
};
|
|
8
|
-
module.exports = filePlugin;
|
|
2
|
+
const file_extension_1 = require("@diplodoc/file-extension");
|
|
3
|
+
module.exports = (0, file_extension_1.transform)({ bundle: false, directiveSyntax: 'disabled' });
|
|
9
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/file/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/file/index.ts"],"names":[],"mappings":";AAAA,6DAAmD;AAEnD,iBAAS,IAAA,0BAAS,EAAC,EAAC,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,UAAU,EAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/transform",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.0",
|
|
4
4
|
"description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"prepare": "husky"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@diplodoc/cut-extension": "^0.
|
|
44
|
+
"@diplodoc/cut-extension": "^0.5.0",
|
|
45
|
+
"@diplodoc/file-extension": "^0.2.0",
|
|
45
46
|
"@diplodoc/tabs-extension": "^3.5.0",
|
|
46
47
|
"chalk": "^4.1.2",
|
|
47
48
|
"cheerio": "^1.0.0",
|
package/src/scss/_yfm-only.scss
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Note: This file excludes "cut" and "tabs" as they are handled separately
|
|
3
|
-
in dedicated extensions (packages). In the future, "note", "
|
|
2
|
+
Note: This file excludes "cut", "file" and "tabs" as they are handled separately
|
|
3
|
+
in dedicated extensions (packages). In the future, "note", "term"
|
|
4
4
|
and "table" will also be excluded from this file and moved to yfm.scss,
|
|
5
5
|
once they are moved to separate packages. Direct usage is not recommended,
|
|
6
6
|
as the file is subject to changes without prior notice.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
@import 'note';
|
|
10
|
-
@import 'file';
|
|
11
10
|
@import 'table';
|
|
12
11
|
@import 'term';
|
package/src/scss/yfm.scss
CHANGED
|
@@ -1,46 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ReferrerPolicy = 'referrerpolicy',
|
|
15
|
-
Rel = 'rel',
|
|
16
|
-
Target = 'target',
|
|
17
|
-
Type = 'type',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const FILE_TO_LINK_ATTRS_MAP: Record<FileSpecialAttr, LinkHtmlAttr> = {
|
|
21
|
-
[FileSpecialAttr.Src]: LinkHtmlAttr.Href,
|
|
22
|
-
[FileSpecialAttr.Name]: LinkHtmlAttr.Download,
|
|
23
|
-
[FileSpecialAttr.Lang]: LinkHtmlAttr.HrefLang,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const RULE_NAME = 'yfm_file_inline';
|
|
27
|
-
export const KNOWN_ATTRS: readonly string[] = [
|
|
28
|
-
FileSpecialAttr.Src,
|
|
29
|
-
FileSpecialAttr.Name,
|
|
30
|
-
FileSpecialAttr.Lang,
|
|
31
|
-
LinkHtmlAttr.ReferrerPolicy,
|
|
32
|
-
LinkHtmlAttr.Rel,
|
|
33
|
-
LinkHtmlAttr.Target,
|
|
34
|
-
LinkHtmlAttr.Type,
|
|
35
|
-
];
|
|
36
|
-
export const REQUIRED_ATTRS: readonly string[] = [FileSpecialAttr.Src, FileSpecialAttr.Name];
|
|
37
|
-
|
|
38
|
-
export const FILE_TOKEN = 'yfm_file';
|
|
39
|
-
|
|
40
|
-
export const PREFIX = '{% file ';
|
|
1
|
+
import {FILE_MARKUP_PREFIX} from '@diplodoc/file-extension';
|
|
2
|
+
export {
|
|
3
|
+
FileSpecialAttr,
|
|
4
|
+
FILE_TO_LINK_ATTRS_MAP,
|
|
5
|
+
FILE_REQUIRED_ATTRS as REQUIRED_ATTRS,
|
|
6
|
+
FILE_TOKEN,
|
|
7
|
+
FILE_KNOWN_ATTRS as KNOWN_ATTRS,
|
|
8
|
+
FileClassName,
|
|
9
|
+
FILE_RULE_NAME as RULE_NAME,
|
|
10
|
+
FileHtmlAttr as LinkHtmlAttr,
|
|
11
|
+
} from '@diplodoc/file-extension';
|
|
12
|
+
|
|
13
|
+
export const PREFIX = FILE_MARKUP_PREFIX;
|
|
41
14
|
export const PREFIX_LENGTH = PREFIX.length;
|
|
42
|
-
|
|
43
|
-
export enum FileClassName {
|
|
44
|
-
Link = 'yfm-file',
|
|
45
|
-
Icon = 'yfm-file__icon',
|
|
46
|
-
}
|
|
@@ -1,82 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type ParserInline from 'markdown-it/lib/parser_inline';
|
|
3
|
-
import type Renderer from 'markdown-it/lib/renderer';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
FILE_TOKEN,
|
|
7
|
-
FILE_TO_LINK_ATTRS_MAP,
|
|
8
|
-
FileClassName,
|
|
9
|
-
FileSpecialAttr,
|
|
10
|
-
KNOWN_ATTRS,
|
|
11
|
-
PREFIX,
|
|
12
|
-
PREFIX_LENGTH,
|
|
13
|
-
REQUIRED_ATTRS,
|
|
14
|
-
} from './const';
|
|
15
|
-
|
|
16
|
-
export type FileOptions = {
|
|
17
|
-
fileExtraAttrs: [string, string][];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const fileRenderer = (md: MarkdownIt): Renderer.RenderRule => {
|
|
21
|
-
const iconHtml = `<span class="${md.utils.escapeHtml(FileClassName.Icon)}"></span>`;
|
|
22
|
-
return (tokens, idx, _opts, _env, self) => {
|
|
23
|
-
const token = tokens[idx];
|
|
24
|
-
return `<a${self.renderAttrs(token)}>${iconHtml}${md.utils.escapeHtml(token.content)}</a>`;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const fileParser = (_md: MarkdownIt, opts?: FileOptions): ParserInline.RuleInline => {
|
|
29
|
-
return (state, silent) => {
|
|
30
|
-
if (state.src.substring(state.pos, state.pos + PREFIX_LENGTH) !== PREFIX) return false;
|
|
31
|
-
|
|
32
|
-
// the rest of line after '{% file '
|
|
33
|
-
const searchStr = state.src.slice(state.pos + PREFIX_LENGTH, state.posMax);
|
|
34
|
-
// loking for pattern 'src="..." name="..." etc="value" %}'
|
|
35
|
-
const matchResult = searchStr.match(/^((?:\s*\w+=(?:"[^"]+"|'[^']+')\s)+)\s*%}/);
|
|
36
|
-
if (!matchResult) return false;
|
|
37
|
-
|
|
38
|
-
const paramsGroupLength = matchResult[0].length; // '(src="..." name="...")'.length
|
|
39
|
-
const paramsStr = matchResult[1]; // 'src="..." name="..."'
|
|
40
|
-
|
|
41
|
-
// find pairs of key="foo" or key='bar'
|
|
42
|
-
const params = paramsStr.match(/\w+=(?:"[^"]+"|'[^']+')/g);
|
|
43
|
-
if (!params) return false;
|
|
44
|
-
|
|
45
|
-
const attrsObj: Record<string, string> = {};
|
|
46
|
-
params.forEach((param) => {
|
|
47
|
-
const indexKey = param.indexOf('=');
|
|
48
|
-
const key = param.slice(0, indexKey);
|
|
49
|
-
const value = param.slice(indexKey + 2, -1);
|
|
50
|
-
if (KNOWN_ATTRS.includes(key) && value) {
|
|
51
|
-
attrsObj[key] = value;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const hasAllRequiredAttrs = REQUIRED_ATTRS.every((attr) => attr in attrsObj);
|
|
56
|
-
if (!hasAllRequiredAttrs) return false;
|
|
57
|
-
|
|
58
|
-
if (!silent) {
|
|
59
|
-
const token = state.push(FILE_TOKEN, '', 0);
|
|
60
|
-
token.block = false;
|
|
61
|
-
token.markup = PREFIX;
|
|
62
|
-
token.content = attrsObj[FileSpecialAttr.Name];
|
|
63
|
-
token.attrs = Object.entries(attrsObj);
|
|
64
|
-
token.attrSet('class', FileClassName.Link);
|
|
65
|
-
|
|
66
|
-
for (const attr of token.attrs) {
|
|
67
|
-
if (attr[0] in FILE_TO_LINK_ATTRS_MAP) {
|
|
68
|
-
attr[0] = FILE_TO_LINK_ATTRS_MAP[attr[0] as FileSpecialAttr];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (Array.isArray(opts?.fileExtraAttrs)) {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
74
|
-
token.attrs.push(...opts!.fileExtraAttrs);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
state.pos = state.pos + PREFIX_LENGTH + paramsGroupLength;
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
1
|
+
export type {PluginOptions as FileOptions} from '@diplodoc/file-extension';
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {transform} from '@diplodoc/file-extension';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import {FileOptions, fileParser, fileRenderer} from './file';
|
|
5
|
-
|
|
6
|
-
const filePlugin: PluginWithOptions<FileOptions> = (md, opts) => {
|
|
7
|
-
md.inline.ruler.push(RULE_NAME, fileParser(md, opts));
|
|
8
|
-
md.renderer.rules[FILE_TOKEN] = fileRenderer(md);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export = filePlugin;
|
|
3
|
+
export = transform({bundle: false, directiveSyntax: 'disabled'});
|
package/src/scss/_file.scss
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
$defaultIcon: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzODQgNTEyIj48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0zNjkuOSA5Ny45TDI4NiAxNEMyNzcgNSAyNjQuOC0uMSAyNTIuMS0uMUg0OEMyMS41IDAgMCAyMS41IDAgNDh2NDE2YzAgMjYuNSAyMS41IDQ4IDQ4IDQ4aDI4OGMyNi41IDAgNDgtMjEuNSA0OC00OFYxMzEuOWMwLTEyLjctNS4xLTI1LTE0LjEtMzR6bS0yMi42IDIyLjdjMi4xIDIuMSAzLjUgNC42IDQuMiA3LjRIMjU2VjMyLjVjMi44LjcgNS4zIDIuMSA3LjQgNC4ybDgzLjkgODMuOXpNMzM2IDQ4MEg0OGMtOC44IDAtMTYtNy4yLTE2LTE2VjQ4YzAtOC44IDcuMi0xNiAxNi0xNmgxNzZ2MTA0YzAgMTMuMyAxMC43IDI0IDI0IDI0aDEwNHYzMDRjMCA4LjgtNy4yIDE2LTE2IDE2em0tNDgtMjQ0djhjMCA2LjYtNS40IDEyLTEyIDEySDEwOGMtNi42IDAtMTItNS40LTEyLTEydi04YzAtNi42IDUuNC0xMiAxMi0xMmgxNjhjNi42IDAgMTIgNS40IDEyIDEyem0wIDY0djhjMCA2LjYtNS40IDEyLTEyIDEySDEwOGMtNi42IDAtMTItNS40LTEyLTEydi04YzAtNi42IDUuNC0xMiAxMi0xMmgxNjhjNi42IDAgMTIgNS40IDEyIDEyem0wIDY0djhjMCA2LjYtNS40IDEyLTEyIDEySDEwOGMtNi42IDAtMTItNS40LTEyLTEydi04YzAtNi42IDUuNC0xMiAxMi0xMmgxNjhjNi42IDAgMTIgNS40IDEyIDEyeiIvPjwvc3ZnPg==');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
Public CSS variables:
|
|
5
|
-
--yfm-file-icon sets file icon image
|
|
6
|
-
--yfm-file-icon-color sets file icon color
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
.yfm-file {
|
|
10
|
-
&__icon {
|
|
11
|
-
---yfm-file-icon-img: var(--yfm-file-icon, #{$defaultIcon});
|
|
12
|
-
|
|
13
|
-
display: inline-block;
|
|
14
|
-
user-select: none;
|
|
15
|
-
|
|
16
|
-
width: 16px;
|
|
17
|
-
margin: 0 2px;
|
|
18
|
-
|
|
19
|
-
color: var(--yfm-file-icon-color, --yfm-color-text);
|
|
20
|
-
background-color: currentColor;
|
|
21
|
-
background-repeat: no-repeat;
|
|
22
|
-
background-position: 50%;
|
|
23
|
-
background-size: 100%;
|
|
24
|
-
|
|
25
|
-
mask-image: var(---yfm-file-icon-img);
|
|
26
|
-
mask-position: center;
|
|
27
|
-
mask-repeat: no-repeat;
|
|
28
|
-
|
|
29
|
-
&::before {
|
|
30
|
-
content: '\a0';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# YFM File plugin
|
|
2
|
-
|
|
3
|
-
```md
|
|
4
|
-
{% file src="path/to/file" name='readme.md' %}
|
|
5
|
-
|
|
6
|
-
==>
|
|
7
|
-
|
|
8
|
-
<a href="path/to/file" download="readme.md" class="yfm-file"><span class="yfm-file__icon"></span>readme.md</a>
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Attributes
|
|
12
|
-
|
|
13
|
-
| Name | Required | Description |
|
|
14
|
-
| ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
-
| `src` | yes | URL of the file. Will be mapped to [`href` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href) |
|
|
16
|
-
| `name` | yes | Name of the file. Will be mapped to [`download` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download) |
|
|
17
|
-
| `lang` | - | Language of the file content. Will be mapped to [`hreflang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-hreflang) |
|
|
18
|
-
| `referrerpolicy` | - | [`referrerpolicy` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-referrerpolicy) |
|
|
19
|
-
| `rel` | - | [`rel` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-rel) |
|
|
20
|
-
| `target` | - | [`target` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target) |
|
|
21
|
-
| `type` | - | [`type` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-type) |
|
|
22
|
-
|
|
23
|
-
> _Note: other attributes will be ignored_
|
|
24
|
-
|
|
25
|
-
## Plugin options
|
|
26
|
-
|
|
27
|
-
| Name | Type | Description |
|
|
28
|
-
| ---------------- | -------------------- | ------------------------------------------------ |
|
|
29
|
-
| `fileExtraAttrs` | `[string, string][]` | Adds additional attributes to rendered hyperlink |
|
|
30
|
-
|
|
31
|
-
## CSS public variables
|
|
32
|
-
|
|
33
|
-
- `--yfm-file-icon` – sets custom file icon image
|
|
34
|
-
- `--yfm-file-icon-color` – sets custom file icon color
|