@diplodoc/transform 4.17.1 → 4.18.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/print.css +12 -0
- package/dist/css/print.css.map +3 -3
- package/dist/css/yfm.css +2 -2
- 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/lib/liquid/conditions.js +1 -1
- package/lib/liquid/conditions.js.map +1 -1
- package/lib/liquid/index.js +3 -1
- package/lib/liquid/index.js.map +1 -1
- package/lib/liquid/lexical.d.ts +2 -0
- package/lib/liquid/lexical.js +4 -1
- package/lib/liquid/lexical.js.map +1 -1
- package/lib/liquid/substitutions.d.ts +1 -1
- package/lib/liquid/substitutions.js +29 -9
- package/lib/liquid/substitutions.js.map +1 -1
- package/package.json +1 -1
- package/src/scss/_anchor.scss +2 -2
- package/src/scss/print/cut.scss +1 -0
- package/src/scss/print/tabs.scss +6 -0
- package/src/scss/print/term.scss +10 -0
- package/src/scss/print.scss +2 -1
- package/src/transform/liquid/conditions.ts +1 -1
- package/src/transform/liquid/index.ts +4 -1
- package/src/transform/liquid/lexical.ts +2 -0
- package/src/transform/liquid/substitutions.ts +43 -9
package/package.json
CHANGED
package/src/scss/_anchor.scss
CHANGED
package/src/scss/print/cut.scss
CHANGED
package/src/scss/print/tabs.scss
CHANGED
package/src/scss/print.scss
CHANGED
|
@@ -225,7 +225,7 @@ export = function conditions(
|
|
|
225
225
|
|
|
226
226
|
// Consumes all between curly braces
|
|
227
227
|
// and all closest upon to first linebreak before and after braces.
|
|
228
|
-
const R_LIQUID = /((?:\n\
|
|
228
|
+
const R_LIQUID = /((?:\n[\t ]*)?{%-?([\s\S]*?)-?%}(?:[\t ]*\n)?)/g;
|
|
229
229
|
|
|
230
230
|
let match;
|
|
231
231
|
while ((match = R_LIQUID.exec(input)) !== null) {
|
|
@@ -124,7 +124,10 @@ function liquid<
|
|
|
124
124
|
output = applySubstitutions(output, vars, path);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
if (!conditionsInCode && typeof output === 'string') {
|
|
128
|
+
output = repairCode(output, codes);
|
|
129
|
+
}
|
|
130
|
+
|
|
128
131
|
codes.length = 0;
|
|
129
132
|
|
|
130
133
|
if (withSourceMap) {
|
|
@@ -6,6 +6,7 @@ const quoted = new RegExp(`${singleQuoted.source}|${doubleQuoted.source}`);
|
|
|
6
6
|
export const quoteBalanced = new RegExp(`(?:${quoted.source}|[^'"])*`);
|
|
7
7
|
|
|
8
8
|
export const vars = /((not_var)?({{2}([. \w-|(),]+)}{2}))/gm;
|
|
9
|
+
export const singleVariable = /^{{2}([. \w-|(),]+)}{2}$/;
|
|
9
10
|
|
|
10
11
|
// basic types
|
|
11
12
|
const number = /-?\d+\.?\d*|\.?\d+/;
|
|
@@ -66,6 +67,7 @@ export const getParsedMethod = (exp: String) => {
|
|
|
66
67
|
|
|
67
68
|
export const isLiteral = (str: string) => literalLine.test(str);
|
|
68
69
|
export const isVariable = (str: string) => variableLine.test(str);
|
|
70
|
+
export const isSingleVariable = (str: string) => singleVariable.test(str);
|
|
69
71
|
|
|
70
72
|
export function parseLiteral(str: string) {
|
|
71
73
|
let res = str.match(numberLine);
|
|
@@ -4,11 +4,35 @@ import ArgvService from './services/argv';
|
|
|
4
4
|
import getObject from '../getObject';
|
|
5
5
|
import {evalExp} from './evaluation';
|
|
6
6
|
import {log} from '../log';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isSingleVariable,
|
|
9
|
+
isVariable,
|
|
10
|
+
singleVariable as singleVariableRe,
|
|
11
|
+
vars as varsRe,
|
|
12
|
+
} from './lexical';
|
|
8
13
|
|
|
9
14
|
const substitutions = (str: string, builtVars: Record<string, unknown>, path?: string) => {
|
|
10
15
|
const {keepNotVar} = ArgvService.getConfig();
|
|
11
16
|
|
|
17
|
+
if (isSingleVariable(str)) {
|
|
18
|
+
const match = str.match(singleVariableRe);
|
|
19
|
+
|
|
20
|
+
if (!match) {
|
|
21
|
+
return str;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const trimVarPath = match[1].trim();
|
|
25
|
+
const value = substituteVariable(trimVarPath, builtVars);
|
|
26
|
+
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
logNotFoundVariable(trimVarPath, path);
|
|
29
|
+
|
|
30
|
+
return str;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
12
36
|
return str.replace(varsRe, (match, _groupNotVar, flag, groupVar, groupVarValue) => {
|
|
13
37
|
if (flag) {
|
|
14
38
|
return keepNotVar ? _groupNotVar : groupVar;
|
|
@@ -20,21 +44,31 @@ const substitutions = (str: string, builtVars: Record<string, unknown>, path?: s
|
|
|
20
44
|
return groupVar;
|
|
21
45
|
}
|
|
22
46
|
|
|
23
|
-
|
|
24
|
-
if (isVariable(trimVarPath)) {
|
|
25
|
-
value = getObject(trimVarPath, builtVars);
|
|
26
|
-
} else {
|
|
27
|
-
value = evalExp(trimVarPath, builtVars);
|
|
28
|
-
}
|
|
47
|
+
const value = substituteVariable(trimVarPath, builtVars);
|
|
29
48
|
|
|
30
49
|
if (value === undefined) {
|
|
31
|
-
|
|
50
|
+
logNotFoundVariable(trimVarPath, path);
|
|
32
51
|
|
|
33
|
-
|
|
52
|
+
return match;
|
|
34
53
|
}
|
|
35
54
|
|
|
36
55
|
return value;
|
|
37
56
|
});
|
|
38
57
|
};
|
|
39
58
|
|
|
59
|
+
function logNotFoundVariable(varPath: string, path?: string) {
|
|
60
|
+
log.warn(`Variable ${bold(varPath)} not found${path ? ` in ${bold(path)}` : ''}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function substituteVariable(varPath: string, builtVars: Record<string, unknown>) {
|
|
64
|
+
let value;
|
|
65
|
+
if (isVariable(varPath)) {
|
|
66
|
+
value = getObject(varPath, builtVars);
|
|
67
|
+
} else {
|
|
68
|
+
value = evalExp(varPath, builtVars);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
|
|
40
74
|
export = substitutions;
|