@diplodoc/transform 4.31.3 → 4.32.1
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/README.md +27 -27
- package/README.ru.md +30 -27
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +115 -60
- 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 +29 -33
- package/dist/js/yfm.js.map +3 -3
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +3 -3
- package/lib/frontmatter/common.d.ts +21 -0
- package/lib/frontmatter/common.js +24 -0
- package/lib/frontmatter/common.js.map +1 -0
- package/lib/frontmatter/emplace.d.ts +4 -0
- package/lib/frontmatter/emplace.js +21 -0
- package/lib/frontmatter/emplace.js.map +1 -0
- package/lib/frontmatter/extract.d.ts +8 -0
- package/lib/frontmatter/extract.js +65 -0
- package/lib/frontmatter/extract.js.map +1 -0
- package/lib/frontmatter/index.d.ts +4 -0
- package/lib/frontmatter/index.js +23 -0
- package/lib/frontmatter/index.js.map +1 -0
- package/lib/frontmatter/transformValues.d.ts +2 -0
- package/lib/frontmatter/transformValues.js +17 -0
- package/lib/frontmatter/transformValues.js.map +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/liquid/index.d.ts +9 -2
- package/lib/liquid/index.js +34 -4
- package/lib/liquid/index.js.map +1 -1
- package/lib/utilsFS.js.map +1 -1
- package/package.json +5 -5
- package/src/scss/_common.scss +60 -48
- package/src/scss/_cut.scss +1 -1
- package/src/scss/_file.scss +2 -4
- package/src/scss/_highlight.scss +0 -16
- package/src/scss/_modal.scss +15 -13
- package/src/scss/_note.scss +12 -21
- package/src/scss/_term.scss +6 -9
- package/src/scss/brand.scss +48 -0
- package/src/scss/private.scss +44 -0
- package/src/transform/frontmatter/common.ts +27 -0
- package/src/transform/frontmatter/emplace.ts +24 -0
- package/src/transform/frontmatter/extract.ts +94 -0
- package/src/transform/frontmatter/index.ts +4 -0
- package/src/transform/frontmatter/transformValues.ts +22 -0
- package/src/transform/index.ts +4 -2
- package/src/transform/liquid/index.ts +73 -4
- package/src/transform/plugins/file/README.md +68 -14
- package/src/transform/utilsFS.ts +2 -2
- package/src/scss/_variables.scss +0 -16
package/src/scss/_term.scss
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.yfm-term {
|
|
2
2
|
&_title {
|
|
3
|
-
color:
|
|
3
|
+
color: var(--yfm-color-term-title);
|
|
4
4
|
cursor: pointer;
|
|
5
5
|
|
|
6
6
|
border-bottom: 1px dotted;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
font-style: normal;
|
|
11
11
|
|
|
12
12
|
&:hover {
|
|
13
|
-
color:
|
|
13
|
+
color: var(--yfm-color-term-title-hover);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
padding: 10px;
|
|
34
34
|
|
|
35
|
-
background-color:
|
|
35
|
+
background-color: var(--yfm-color-term-dfn-background);
|
|
36
36
|
|
|
37
37
|
font-size: inherit;
|
|
38
38
|
line-height: inherit;
|
|
@@ -40,20 +40,17 @@
|
|
|
40
40
|
|
|
41
41
|
border-radius: 4px;
|
|
42
42
|
|
|
43
|
-
box-shadow: 0 8px 20px
|
|
43
|
+
box-shadow: 0 8px 20px var(--yfm-color-term-dfn-shadow);
|
|
44
44
|
outline: none;
|
|
45
45
|
|
|
46
46
|
&::before {
|
|
47
47
|
content: '';
|
|
48
48
|
position: absolute;
|
|
49
49
|
z-index: -1;
|
|
50
|
-
|
|
51
|
-
right: 0;
|
|
52
|
-
bottom: 0;
|
|
53
|
-
left: 0;
|
|
50
|
+
inset: 0;
|
|
54
51
|
|
|
55
52
|
border-radius: inherit;
|
|
56
|
-
box-shadow: 0 0 0 1px
|
|
53
|
+
box-shadow: 0 0 0 1px var(--yfm-color-term-dfn-pseudo-shadow);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
&.open {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
@mixin brand {
|
|
2
|
+
--yfm-color-base: var(--yfm-color-base-private);
|
|
3
|
+
|
|
4
|
+
--yfm-color-text: var(--yfm-color-text-private);
|
|
5
|
+
--yfm-color-link: var(--yfm-color-link-private);
|
|
6
|
+
--yfm-color-link-hover: var(--yfm-color-link-hover-private);
|
|
7
|
+
|
|
8
|
+
--yfm-color-table: var(--yfm-color-table-private);
|
|
9
|
+
--yfm-color-table-row-background: var(--yfm-color-table-row-background-private);
|
|
10
|
+
|
|
11
|
+
--yfm-color-border: var(--yfm-color-border-private);
|
|
12
|
+
|
|
13
|
+
--yfm-color-accent: var(--yfm-color-accent-private);
|
|
14
|
+
|
|
15
|
+
--yfm-color-inline-code: var(--yfm-color-inline-code-private);
|
|
16
|
+
--yfm-color-inline-code-background: var(--yfm-color-inline-code-background-private);
|
|
17
|
+
--yfm-color-code-background: var(--yfm-color-code-background-private);
|
|
18
|
+
|
|
19
|
+
--yfm-color-hljs-background: var(--yfm-color-hljs-background-private);
|
|
20
|
+
--yfm-color-hljs-subst: var(--yfm-color-hljs-subst-private);
|
|
21
|
+
--yfm-color-hljs-comment: var(--yfm-color-hljs-comment-private);
|
|
22
|
+
--yfm-color-hljs-deletion: var(--yfm-color-hljs-deletion-private);
|
|
23
|
+
--yfm-color-hljs-section: var(--yfm-color-hljs-section-private);
|
|
24
|
+
--yfm-color-hljs-pseudo: var(--yfm-color-hljs-pseudo-private);
|
|
25
|
+
--yfm-color-hljs-literal: var(--yfm-color-hljs-literal-private);
|
|
26
|
+
--yfm-color-hljs-addition: var(--yfm-color-hljs-addition-private);
|
|
27
|
+
--yfm-color-hljs-meta: var(--yfm-color-hljs-meta-private);
|
|
28
|
+
--yfm-color-hljs-meta-string: var(--yfm-color-hljs-meta-string-private);
|
|
29
|
+
|
|
30
|
+
--yfm-color-note-tip: var(--yfm-color-note-tip-private);
|
|
31
|
+
--yfm-color-note-tip-background: var(--yfm-color-note-tip-background-private);
|
|
32
|
+
--yfm-color-note-warning: var(--yfm-color-note-warning-private);
|
|
33
|
+
--yfm-color-note-warning-background: var(--yfm-color-note-warning-background-private);
|
|
34
|
+
--yfm-color-note-important: var(--yfm-color-note-important-private);
|
|
35
|
+
--yfm-color-note-important-background: var(--yfm-color-note-important-background-private);
|
|
36
|
+
--yfm-color-note-info-background: var(--yfm-color-note-info-background-private);
|
|
37
|
+
|
|
38
|
+
--yfm-color-term-title: var(--yfm-color-term-title-private);
|
|
39
|
+
--yfm-color-term-title-hover: var(--yfm-color-term-title-hover-private);
|
|
40
|
+
--yfm-color-term-dfn-background: var(--yfm-color-term-dfn-background-private);
|
|
41
|
+
--yfm-color-term-dfn-shadow: var(--yfm-color-term-dfn-shadow-private);
|
|
42
|
+
--yfm-color-term-dfn-pseudo-shadow: var(--yfm-color-term-dfn-presudo-shadow-private);
|
|
43
|
+
|
|
44
|
+
--yfm-color-modal-content: var(--yfm-color-modal-content-private);
|
|
45
|
+
--yfm-color-modal-actions-hover: var(--yfm-color-modal-actions-hover-private);
|
|
46
|
+
--yfm-color-modal-wide-content: var(--yfm-color-modal-wide-content-private);
|
|
47
|
+
--yfm-color-modal-wide-content-overlay: var(--yfm-color-modal-wide-content-overlay-private);
|
|
48
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
@mixin private-brand {
|
|
2
|
+
--yfm-color-text-private: rgba(0, 0, 0, 0.7);
|
|
3
|
+
--yfm-color-link-private: #027bf3;
|
|
4
|
+
--yfm-color-link-hover-private: #004080;
|
|
5
|
+
--yfm-color-base-private: #ffffff;
|
|
6
|
+
--yfm-color-table-private: #333;
|
|
7
|
+
--yfm-color-border-private: rgba(0, 0, 0, 0.07);
|
|
8
|
+
--yfm-color-table-row-background-private: rgba(0, 0, 0, 0.02);
|
|
9
|
+
--yfm-color-accent-private: #027bf3;
|
|
10
|
+
|
|
11
|
+
--yfm-color-inline-code-private: rgba(59, 96, 128, 1);
|
|
12
|
+
--yfm-color-inline-code-background-private: rgba(107, 132, 153, 0.12);
|
|
13
|
+
--yfm-color-code-background-private: rgba(107, 132, 153, 0.12);
|
|
14
|
+
|
|
15
|
+
--yfm-color-hljs-background-private: rgba(107, 132, 153, 0.12);
|
|
16
|
+
--yfm-color-hljs-subst-private: #444;
|
|
17
|
+
--yfm-color-hljs-comment-private: #888888;
|
|
18
|
+
--yfm-color-hljs-deletion-private: #880000;
|
|
19
|
+
--yfm-color-hljs-section-private: #880000;
|
|
20
|
+
--yfm-color-hljs-pseudo-private: #bc6060;
|
|
21
|
+
--yfm-color-hljs-literal-private: #78a960;
|
|
22
|
+
--yfm-color-hljs-addition-private: #397300;
|
|
23
|
+
--yfm-color-hljs-meta-private: #1f7199;
|
|
24
|
+
--yfm-color-hljs-meta-string-private: #4d99bf;
|
|
25
|
+
|
|
26
|
+
--yfm-color-note-tip-private: #56bd67;
|
|
27
|
+
--yfm-color-note-tip-background-private: rgba(63, 201, 46, 0.1);
|
|
28
|
+
--yfm-color-note-warning-private: #f19518;
|
|
29
|
+
--yfm-color-note-warning-background-private: rgba(255, 136, 0, 0.15);
|
|
30
|
+
--yfm-color-note-important-private: #ff4645;
|
|
31
|
+
--yfm-color-note-important-background-private: rgba(235, 50, 38, 0.08);
|
|
32
|
+
--yfm-color-note-info-background-private: rgba(2, 123, 243, 0.08);
|
|
33
|
+
|
|
34
|
+
--yfm-color-term-title-private: #027bf3;
|
|
35
|
+
--yfm-color-term-title-hover-private: #004080;
|
|
36
|
+
--yfm-color-term-dfn-background-private: rgb(255, 255, 255);
|
|
37
|
+
--yfm-color-term-dfn-shadow-private: rgba(0, 0, 0, 0.15);
|
|
38
|
+
--yfm-color-term-dfn-presudo-shadow-private: rgb(229, 229, 229);
|
|
39
|
+
|
|
40
|
+
--yfm-color-modal-content-private: rgb(255, 255, 255);
|
|
41
|
+
--yfm-color-modal-actions-hover-private: rgba(0, 0, 0, 0.05);
|
|
42
|
+
--yfm-color-modal-wide-content-private: rgba(0, 0, 0, 0.85);
|
|
43
|
+
--yfm-color-modal-wide-content-overlay-private: rgb(0, 0, 0);
|
|
44
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type FrontMatter = {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
metadata?: Record<string, unknown>[];
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const frontMatterFence = '---';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Temporary workaround to enable parsing YAML metadata from potentially
|
|
10
|
+
* Liquid-aware source files
|
|
11
|
+
* @param content Input string which could contain Liquid-style substitution syntax (which clashes with YAML
|
|
12
|
+
* object syntax)
|
|
13
|
+
* @returns String with `{}` escaped, ready to be parsed with `js-yaml`
|
|
14
|
+
*/
|
|
15
|
+
export const escapeLiquidSubstitutionSyntax = (content: string): string =>
|
|
16
|
+
content.replace(/{{/g, '(({{').replace(/}}/g, '}}))');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Inverse of a workaround defined above.
|
|
20
|
+
* @see `escapeLiquidSubstitutionSyntax`
|
|
21
|
+
* @param escapedContent Input string with `{}` escaped with backslashes
|
|
22
|
+
* @returns Unescaped string
|
|
23
|
+
*/
|
|
24
|
+
export const unescapeLiquidSubstitutionSyntax = (escapedContent: string): string =>
|
|
25
|
+
escapedContent.replace(/\(\({{/g, '{{').replace(/}}\)\)/g, '}}');
|
|
26
|
+
|
|
27
|
+
export const countLineAmount = (str: string) => str.split(/\r?\n/).length;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {dump} from 'js-yaml';
|
|
2
|
+
|
|
3
|
+
import {FrontMatter, frontMatterFence} from './common';
|
|
4
|
+
|
|
5
|
+
export const serializeFrontMatter = (frontMatter: FrontMatter) => {
|
|
6
|
+
const dumped = dump(frontMatter, {lineWidth: -1}).trim();
|
|
7
|
+
|
|
8
|
+
// This empty object check is a bit naive
|
|
9
|
+
// The other option would be to check if all own fields are `undefined`,
|
|
10
|
+
// since we exploit passing in `undefined` to remove a field quite a bit
|
|
11
|
+
if (dumped === '{}') {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return `${frontMatterFence}\n${dumped}\n${frontMatterFence}\n`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const emplaceSerializedFrontMatter = (
|
|
19
|
+
frontMatterStrippedContent: string,
|
|
20
|
+
frontMatter: string,
|
|
21
|
+
) => `${frontMatter}${frontMatterStrippedContent}`;
|
|
22
|
+
|
|
23
|
+
export const emplaceFrontMatter = (frontMatterStrippedContent: string, frontMatter: FrontMatter) =>
|
|
24
|
+
emplaceSerializedFrontMatter(frontMatterStrippedContent, serializeFrontMatter(frontMatter));
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {YAMLException, load} from 'js-yaml';
|
|
2
|
+
|
|
3
|
+
import {log} from '../log';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
FrontMatter,
|
|
7
|
+
countLineAmount,
|
|
8
|
+
escapeLiquidSubstitutionSyntax,
|
|
9
|
+
frontMatterFence,
|
|
10
|
+
unescapeLiquidSubstitutionSyntax,
|
|
11
|
+
} from './common';
|
|
12
|
+
import {transformFrontMatterValues} from './transformValues';
|
|
13
|
+
|
|
14
|
+
type ParseExistingMetadataReturn = {
|
|
15
|
+
frontMatter: FrontMatter;
|
|
16
|
+
frontMatterStrippedContent: string;
|
|
17
|
+
frontMatterLineCount: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const matchMetadata = (fileContent: string) => {
|
|
21
|
+
if (!fileContent.startsWith(frontMatterFence)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Search by format:
|
|
26
|
+
// ---
|
|
27
|
+
// metaName1: metaValue1
|
|
28
|
+
// metaName2: meta value2
|
|
29
|
+
// incorrectMetadata
|
|
30
|
+
// ---
|
|
31
|
+
const regexpMetadata = '(?<=-{3}\\r?\\n)((.*\\r?\\n)*?)(?=-{3}\\r?\\n)';
|
|
32
|
+
// Search by format:
|
|
33
|
+
// ---
|
|
34
|
+
// main content 123
|
|
35
|
+
const regexpFileContent = '-{3}\\r?\\n((.*[\r?\n]*)*)';
|
|
36
|
+
|
|
37
|
+
const regexpParseFileContent = new RegExp(`${regexpMetadata}${regexpFileContent}`, 'gm');
|
|
38
|
+
|
|
39
|
+
return regexpParseFileContent.exec(fileContent);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const duplicateKeysCompatibleLoad = (yaml: string, filePath: string | undefined) => {
|
|
43
|
+
try {
|
|
44
|
+
return load(yaml);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (e instanceof YAMLException) {
|
|
47
|
+
const duplicateKeysDeprecationWarning = `
|
|
48
|
+
In ${filePath ?? '(unknown)'}: Encountered a YAML parsing exception when processing file metadata: ${e.reason}.
|
|
49
|
+
It's highly possible the input file contains duplicate mapping keys.
|
|
50
|
+
Will retry processing with necessary compatibility flags.
|
|
51
|
+
Please note that this behaviour is DEPRECATED and WILL be removed in a future version
|
|
52
|
+
without further notice, so the build WILL fail when supplied with YAML-incompatible meta.
|
|
53
|
+
`
|
|
54
|
+
.replace(/^\s+/gm, '')
|
|
55
|
+
.replace(/\n/g, ' ')
|
|
56
|
+
.trim();
|
|
57
|
+
|
|
58
|
+
log.warn(duplicateKeysDeprecationWarning);
|
|
59
|
+
|
|
60
|
+
return load(yaml, {json: true});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const separateAndExtractFrontMatter = (
|
|
68
|
+
fileContent: string,
|
|
69
|
+
filePath?: string,
|
|
70
|
+
): ParseExistingMetadataReturn => {
|
|
71
|
+
const matches = matchMetadata(fileContent);
|
|
72
|
+
|
|
73
|
+
if (matches && matches.length > 0) {
|
|
74
|
+
const [, metadata, , metadataStrippedContent] = matches;
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
frontMatter: transformFrontMatterValues(
|
|
78
|
+
duplicateKeysCompatibleLoad(
|
|
79
|
+
escapeLiquidSubstitutionSyntax(metadata),
|
|
80
|
+
filePath,
|
|
81
|
+
) as FrontMatter,
|
|
82
|
+
(v) => (typeof v === 'string' ? unescapeLiquidSubstitutionSyntax(v) : v),
|
|
83
|
+
),
|
|
84
|
+
frontMatterStrippedContent: metadataStrippedContent,
|
|
85
|
+
frontMatterLineCount: countLineAmount(metadata),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
frontMatter: {},
|
|
91
|
+
frontMatterStrippedContent: fileContent,
|
|
92
|
+
frontMatterLineCount: 0,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {FrontMatter} from './common';
|
|
2
|
+
|
|
3
|
+
export const transformFrontMatterValues = (
|
|
4
|
+
frontMatter: FrontMatter,
|
|
5
|
+
valueMapper: (v: unknown) => unknown,
|
|
6
|
+
): FrontMatter => {
|
|
7
|
+
const transformInner = (something: unknown): unknown => {
|
|
8
|
+
if (typeof something === 'object' && something !== null) {
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(something).map(([k, v]) => [k, transformInner(v)]),
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (Array.isArray(something)) {
|
|
15
|
+
return something.map((el) => transformInner(el));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return valueMapper(something);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return transformInner(frontMatter) as FrontMatter;
|
|
22
|
+
};
|
package/src/transform/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {EnvType, OptionsType, OutputType} from './typings';
|
|
|
3
3
|
import {bold} from 'chalk';
|
|
4
4
|
|
|
5
5
|
import {log} from './log';
|
|
6
|
-
import
|
|
6
|
+
import liquidSnippet from './liquid';
|
|
7
7
|
import initMarkdownit from './md';
|
|
8
8
|
|
|
9
9
|
function applyLiquid(input: string, options: OptionsType) {
|
|
@@ -15,7 +15,9 @@ function applyLiquid(input: string, options: OptionsType) {
|
|
|
15
15
|
isLiquided = false,
|
|
16
16
|
} = options;
|
|
17
17
|
|
|
18
|
-
return disableLiquid || isLiquided
|
|
18
|
+
return disableLiquid || isLiquided
|
|
19
|
+
? input
|
|
20
|
+
: liquidSnippet(input, vars, path, {conditionsInCode});
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
function handleError(error: unknown, path?: string): never {
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type {Dictionary} from 'lodash';
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
countLineAmount,
|
|
5
|
+
emplaceSerializedFrontMatter,
|
|
6
|
+
separateAndExtractFrontMatter,
|
|
7
|
+
serializeFrontMatter,
|
|
8
|
+
transformFrontMatterValues,
|
|
9
|
+
} from '../frontmatter';
|
|
10
|
+
|
|
3
11
|
import applySubstitutions from './substitutions';
|
|
4
12
|
import {prepareSourceMap} from './sourceMap';
|
|
5
13
|
import applyCycles from './cycles';
|
|
@@ -66,7 +74,7 @@ function repairCode(str: string, codes: string[]) {
|
|
|
66
74
|
return replace(fence, fence, (code) => codes[Number(code)], str);
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
function
|
|
77
|
+
function liquidSnippet<
|
|
70
78
|
B extends boolean = false,
|
|
71
79
|
C = B extends false ? string : {output: string; sourceMap: Dictionary<string>},
|
|
72
80
|
>(
|
|
@@ -141,6 +149,67 @@ function liquid<
|
|
|
141
149
|
return output as unknown as C;
|
|
142
150
|
}
|
|
143
151
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
type TransformSourceMapOptions = {
|
|
153
|
+
emplacedResultOffset: number;
|
|
154
|
+
emplacedSourceOffset: number;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
function transformSourceMap(
|
|
158
|
+
sourceMap: Dictionary<string>,
|
|
159
|
+
{emplacedResultOffset, emplacedSourceOffset}: TransformSourceMapOptions,
|
|
160
|
+
) {
|
|
161
|
+
return Object.fromEntries(
|
|
162
|
+
Object.entries(sourceMap).map(([lineInResult, lineInSource]) => [
|
|
163
|
+
(Number(lineInResult) + emplacedResultOffset).toString(),
|
|
164
|
+
(Number(lineInSource) + emplacedSourceOffset).toString(),
|
|
165
|
+
]),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function liquidDocument<
|
|
170
|
+
B extends boolean = false,
|
|
171
|
+
C = B extends false ? string : {output: string; sourceMap: Dictionary<string>},
|
|
172
|
+
>(
|
|
173
|
+
originInput: string,
|
|
174
|
+
vars: Record<string, unknown>,
|
|
175
|
+
path?: string,
|
|
176
|
+
settings?: ArgvSettings & {withSourceMap?: B},
|
|
177
|
+
): C {
|
|
178
|
+
const {frontMatter, frontMatterStrippedContent, frontMatterLineCount} =
|
|
179
|
+
separateAndExtractFrontMatter(originInput, path);
|
|
180
|
+
|
|
181
|
+
const transformedFrontMatter = transformFrontMatterValues(frontMatter, (v) =>
|
|
182
|
+
typeof v === 'string'
|
|
183
|
+
? liquidSnippet(v, vars, path, {...settings, withSourceMap: false})
|
|
184
|
+
: v,
|
|
185
|
+
);
|
|
186
|
+
const transformedAndSerialized = serializeFrontMatter(transformedFrontMatter);
|
|
187
|
+
|
|
188
|
+
// -1 comes from the fact that the last line in serialized FM is the same as the first line in stripped content
|
|
189
|
+
const resultFrontMatterOffset = Math.max(0, countLineAmount(transformedAndSerialized) - 1);
|
|
190
|
+
const sourceFrontMatterOffset = Math.max(0, frontMatterLineCount - 1);
|
|
191
|
+
|
|
192
|
+
const liquidProcessedContent = liquidSnippet(frontMatterStrippedContent, vars, path, settings);
|
|
193
|
+
|
|
194
|
+
// typeof check for better inference; the catch is that return of liquidSnippet can be an
|
|
195
|
+
// object even with source maps off, see `substitutions.test.ts`
|
|
196
|
+
return (settings?.withSourceMap && typeof liquidProcessedContent === 'object'
|
|
197
|
+
? {
|
|
198
|
+
output: emplaceSerializedFrontMatter(
|
|
199
|
+
liquidProcessedContent.output,
|
|
200
|
+
transformedAndSerialized,
|
|
201
|
+
),
|
|
202
|
+
sourceMap: transformSourceMap(liquidProcessedContent.sourceMap, {
|
|
203
|
+
emplacedResultOffset: resultFrontMatterOffset,
|
|
204
|
+
emplacedSourceOffset: sourceFrontMatterOffset,
|
|
205
|
+
}),
|
|
206
|
+
}
|
|
207
|
+
: emplaceSerializedFrontMatter(
|
|
208
|
+
liquidProcessedContent as string,
|
|
209
|
+
transformedAndSerialized,
|
|
210
|
+
)) as unknown as C;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// both default and named exports for convenience
|
|
214
|
+
export {liquidDocument, liquidSnippet};
|
|
215
|
+
export default liquidDocument;
|
|
@@ -10,25 +10,79 @@
|
|
|
10
10
|
|
|
11
11
|
## Attributes
|
|
12
12
|
|
|
13
|
-
|Name|Required|Description|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
22
|
|
|
23
23
|
> _Note: other attributes will be ignored_
|
|
24
24
|
|
|
25
25
|
## Plugin options
|
|
26
26
|
|
|
27
|
-
|Name|Type|Description|
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
| Name | Type | Description |
|
|
28
|
+
| ---------------- | -------------------- | ------------------------------------------------ |
|
|
29
|
+
| `fileExtraAttrs` | `[string, string][]` | Adds additional attributes to rendered hyperlink |
|
|
30
30
|
|
|
31
31
|
## CSS public variables
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
- `--yfm-file-icon` – sets custom file icon image
|
|
34
|
+
- `--yfm-file-icon-color` – sets custom file icon color
|
|
35
|
+
|
|
36
|
+
_common_
|
|
37
|
+
|
|
38
|
+
- `--yfm-color-text`
|
|
39
|
+
- `--yfm-color-link`
|
|
40
|
+
- `--yfm-color-base`
|
|
41
|
+
- `--yfm-color-link-hover`
|
|
42
|
+
- `--yfm-color-table`
|
|
43
|
+
- `--yfm-color-table-row-background`
|
|
44
|
+
- `--yfm-color-border`
|
|
45
|
+
- `--yfm-color-accent`
|
|
46
|
+
|
|
47
|
+
_code_
|
|
48
|
+
|
|
49
|
+
- `--yfm-color-inline-code`
|
|
50
|
+
- `--yfm-color-inline-code-background`
|
|
51
|
+
- `--yfm-color-code-background`
|
|
52
|
+
|
|
53
|
+
_hightlight_
|
|
54
|
+
|
|
55
|
+
- `--yfm-color-hljs-background`
|
|
56
|
+
- `--yfm-color-hljs-subst`
|
|
57
|
+
- `--yfm-color-hljs-comment`
|
|
58
|
+
- `--yfm-color-hljs-deletion`
|
|
59
|
+
- `--yfm-color-hljs-section`
|
|
60
|
+
- `--yfm-color-hljs-pseudo`
|
|
61
|
+
- `--yfm-color-hljs-literal`
|
|
62
|
+
- `--yfm-color-hljs-addition`
|
|
63
|
+
- `--yfm-color-hljs-meta`
|
|
64
|
+
- `--yfm-color-hljs-meta-string`
|
|
65
|
+
|
|
66
|
+
_note_
|
|
67
|
+
|
|
68
|
+
- `--yfm-color-note-tip`
|
|
69
|
+
- `--yfm-color-note-tip-background`
|
|
70
|
+
- `--yfm-color-note-warning`
|
|
71
|
+
- `--yfm-color-note-warning-background`
|
|
72
|
+
- `--yfm-color-note-important-background`
|
|
73
|
+
- `--yfm-color-note-info-background`
|
|
74
|
+
|
|
75
|
+
_term_
|
|
76
|
+
|
|
77
|
+
- `--yfm-color-term-title`
|
|
78
|
+
- `--yfm-color-term-title-hover`
|
|
79
|
+
- `--yfm-color-term-dfn-background`
|
|
80
|
+
- `--yfm-color-term-dfn-shadow`
|
|
81
|
+
- `--yfm-color-term-dfn-pseudo-shadow`
|
|
82
|
+
|
|
83
|
+
_modal_
|
|
84
|
+
|
|
85
|
+
- `--yfm-color-modal-content`
|
|
86
|
+
- `--yfm-color-modal-actions-hover`
|
|
87
|
+
- `--yfm-color-modal-wide-content`
|
|
88
|
+
- `--yfm-color-modal-wide-content-overlay`
|
package/src/transform/utilsFS.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {readFileSync, statSync} from 'fs';
|
|
|
4
4
|
import escapeRegExp from 'lodash/escapeRegExp';
|
|
5
5
|
import {join, parse, relative, resolve, sep} from 'path';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import liquidSnippet from './liquid';
|
|
8
8
|
import {StateCore} from './typings';
|
|
9
9
|
import {defaultTransformLink} from './utils';
|
|
10
10
|
|
|
@@ -68,7 +68,7 @@ export function getFileTokens(path: string, state: StateCore, options: GetFileTo
|
|
|
68
68
|
let sourceMap;
|
|
69
69
|
|
|
70
70
|
if (!disableLiquid) {
|
|
71
|
-
const liquidResult =
|
|
71
|
+
const liquidResult = liquidSnippet(content, builtVars, path, {
|
|
72
72
|
withSourceMap: true,
|
|
73
73
|
conditionsInCode,
|
|
74
74
|
});
|
package/src/scss/_variables.scss
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
$baseColor: #ffffff;
|
|
2
|
-
$accentColor: #027bf3;
|
|
3
|
-
|
|
4
|
-
$textColor: rgba(0, 0, 0, 0.7);
|
|
5
|
-
$borderColor: rgba(0, 0, 0, 0.07);
|
|
6
|
-
$backgroundColor: rgba(0, 0, 0, 0.02);
|
|
7
|
-
|
|
8
|
-
$inlineCodeColor: rgba(59, 96, 128, 1);
|
|
9
|
-
$inlineCodeBackgroundColor: rgba(107, 132, 153, 0.12);
|
|
10
|
-
|
|
11
|
-
$codeBackgroundColor: rgba(107, 132, 153, 0.12);
|
|
12
|
-
|
|
13
|
-
$tableRowBackgroundColor: rgba(0, 0, 0, 0.02);
|
|
14
|
-
|
|
15
|
-
$linkColor: $accentColor;
|
|
16
|
-
$linkHoverColor: #004080;
|