@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/transform",
3
- "version": "4.17.1",
3
+ "version": "4.18.0",
4
4
  "description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
5
5
  "keywords": [
6
6
  "markdown",
@@ -13,11 +13,11 @@
13
13
 
14
14
  .yfm-anchor::before {
15
15
  content: '#';
16
- visibility: hidden;
16
+ opacity: 0;
17
17
  }
18
18
 
19
19
  &:hover .yfm-anchor::before {
20
- visibility: visible;
20
+ opacity: 1;
21
21
  }
22
22
  }
23
23
 
@@ -11,6 +11,7 @@
11
11
 
12
12
  &-content {
13
13
  height: auto;
14
+ display: block;
14
15
  padding: 5px 0 15px 30px;
15
16
  }
16
17
  }
@@ -5,6 +5,12 @@
5
5
  display: none;
6
6
  }
7
7
 
8
+ &-panel {
9
+ visibility: visible;
10
+ height: auto;
11
+ display: block;
12
+ }
13
+
8
14
  &-panel:before {
9
15
  content: attr(data-title);
10
16
  margin-bottom: -1px;
@@ -0,0 +1,10 @@
1
+ @media print {
2
+ .yfm {
3
+ .yfm-term {
4
+ &_title {
5
+ color: currentColor;
6
+ border-bottom: none;
7
+ }
8
+ }
9
+ }
10
+ }
@@ -3,4 +3,5 @@
3
3
  @import 'print/cut';
4
4
  @import 'print/note';
5
5
  @import 'print/table';
6
- @import 'print/tabs';
6
+ @import 'print/tabs';
7
+ @import 'print/term';
@@ -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\s*)?{%-?([\s\S]*?)-?%}(?:\s*\n)?)/g;
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
- output = conditionsInCode ? output : repairCode(output, codes);
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 {isVariable, vars as varsRe} from './lexical';
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
- let value;
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
- value = match;
50
+ logNotFoundVariable(trimVarPath, path);
32
51
 
33
- log.warn(`Variable ${bold(trimVarPath)} not found${path ? ` in ${bold(path)}` : ''}`);
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;