@diplodoc/transform 4.14.2 → 4.16.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.map +1 -1
- package/dist/css/yfm.css.map +1 -1
- package/dist/css/yfm.min.css.map +1 -1
- package/lib/getObject.d.ts +1 -1
- package/lib/getObject.js +10 -7
- package/lib/getObject.js.map +1 -1
- package/lib/liquid/conditions.d.ts +2 -1
- package/lib/liquid/conditions.js +141 -116
- package/lib/liquid/conditions.js.map +1 -1
- package/lib/liquid/cycles.js +2 -5
- package/lib/liquid/cycles.js.map +1 -1
- package/lib/liquid/evaluation.d.ts +3 -2
- package/lib/liquid/evaluation.js +25 -20
- package/lib/liquid/evaluation.js.map +1 -1
- package/lib/liquid/index.js +2 -1
- package/lib/liquid/index.js.map +1 -1
- package/lib/liquid/services/argv.d.ts +1 -1
- package/lib/liquid/sourceMap.d.ts +2 -7
- package/lib/liquid/sourceMap.js +1 -6
- package/lib/liquid/sourceMap.js.map +1 -1
- package/lib/md.js +2 -2
- package/lib/md.js.map +1 -1
- package/lib/plugins/anchors/index.d.ts +1 -0
- package/lib/plugins/anchors/index.js +2 -2
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/links/index.d.ts +1 -0
- package/lib/plugins/links/index.js +6 -3
- package/lib/plugins/links/index.js.map +1 -1
- package/lib/typings.d.ts +1 -0
- package/lib/utils.d.ts +1 -3
- package/lib/utils.js +5 -6
- package/lib/utils.js.map +1 -1
- package/lib/utilsFS.d.ts +6 -0
- package/lib/utilsFS.js +10 -1
- package/lib/utilsFS.js.map +1 -1
- package/package.json +1 -1
- package/src/.eslintrc.js +9 -0
- package/src/transform/getObject.ts +14 -7
- package/src/transform/liquid/conditions.ts +184 -155
- package/src/transform/liquid/cycles.ts +2 -5
- package/src/transform/liquid/evaluation.ts +44 -25
- package/src/transform/liquid/index.ts +2 -1
- package/src/transform/liquid/services/argv.ts +1 -1
- package/src/transform/liquid/sourceMap.ts +3 -13
- package/src/transform/md.ts +7 -2
- package/src/transform/plugins/anchors/index.ts +9 -2
- package/src/transform/plugins/links/index.ts +27 -4
- package/src/transform/typings.ts +1 -0
- package/src/transform/utils.ts +2 -8
- package/src/transform/utilsFS.ts +23 -2
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
defaultTransformLink,
|
|
6
6
|
findBlockTokens,
|
|
7
7
|
getHrefTokenAttr,
|
|
8
|
-
getPublicPath,
|
|
9
8
|
headingInfo,
|
|
10
9
|
isLocalUrl,
|
|
11
10
|
} from '../../utils';
|
|
@@ -13,7 +12,7 @@ import {getFileTokens, isFileExists} from '../../utilsFS';
|
|
|
13
12
|
import Token from 'markdown-it/lib/token';
|
|
14
13
|
import {Logger} from 'src/transform/log';
|
|
15
14
|
import {MarkdownItPluginCb, MarkdownItPluginOpts} from '../typings';
|
|
16
|
-
import path, {isAbsolute, resolve} from 'path';
|
|
15
|
+
import path, {isAbsolute, parse, relative, resolve} from 'path';
|
|
17
16
|
import {StateCore} from 'src/transform/typings';
|
|
18
17
|
|
|
19
18
|
function getTitleFromTokens(tokens: Token[]) {
|
|
@@ -84,11 +83,34 @@ interface ProcOpts extends MarkdownItPluginOpts {
|
|
|
84
83
|
transformLink: (v: string) => string;
|
|
85
84
|
notFoundCb: (v: string) => void;
|
|
86
85
|
needSkipLinkFn: (v: string) => boolean;
|
|
86
|
+
getPublicPath: (options: ProcOpts, v?: string) => string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getDefaultPublicPath(
|
|
90
|
+
{
|
|
91
|
+
file,
|
|
92
|
+
path,
|
|
93
|
+
}: {
|
|
94
|
+
file?: string;
|
|
95
|
+
path?: string;
|
|
96
|
+
},
|
|
97
|
+
input?: string | null,
|
|
98
|
+
) {
|
|
99
|
+
return relative(parse(path || '').dir, input || file || '');
|
|
87
100
|
}
|
|
88
101
|
|
|
89
102
|
// eslint-disable-next-line complexity
|
|
90
103
|
function processLink(state: StateCore, tokens: Token[], idx: number, opts: ProcOpts) {
|
|
91
|
-
const {
|
|
104
|
+
const {
|
|
105
|
+
path: startPath,
|
|
106
|
+
root,
|
|
107
|
+
transformLink,
|
|
108
|
+
notFoundCb,
|
|
109
|
+
needSkipLinkFn,
|
|
110
|
+
log,
|
|
111
|
+
getPublicPath = getDefaultPublicPath,
|
|
112
|
+
} = opts;
|
|
113
|
+
|
|
92
114
|
const currentPath = state.env.path || startPath;
|
|
93
115
|
const linkToken = tokens[idx];
|
|
94
116
|
const nextToken = tokens[idx + 1];
|
|
@@ -162,7 +184,8 @@ function processLink(state: StateCore, tokens: Token[], idx: number, opts: ProcO
|
|
|
162
184
|
}
|
|
163
185
|
|
|
164
186
|
let newPathname = '';
|
|
165
|
-
|
|
187
|
+
|
|
188
|
+
if (!isAbsolute(href) && !href.includes('//')) {
|
|
166
189
|
newPathname = getPublicPath(opts, file);
|
|
167
190
|
|
|
168
191
|
href = url.format({
|
package/src/transform/typings.ts
CHANGED
package/src/transform/utils.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import url from 'url';
|
|
2
|
-
import {relative, resolve} from 'path';
|
|
3
2
|
import Token from 'markdown-it/lib/token';
|
|
4
3
|
|
|
5
4
|
export function isLocalUrl(url: string) {
|
|
@@ -104,23 +103,18 @@ export function defaultTransformLink(href: string) {
|
|
|
104
103
|
return href;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
export function
|
|
106
|
+
export function getDefaultPublicPath(
|
|
108
107
|
{
|
|
109
108
|
path,
|
|
110
|
-
root,
|
|
111
|
-
rootPublicPath,
|
|
112
109
|
transformLink,
|
|
113
110
|
}: {
|
|
114
111
|
path?: string;
|
|
115
|
-
root?: string;
|
|
116
|
-
rootPublicPath?: string;
|
|
117
112
|
transformLink?: (href: string) => string;
|
|
118
113
|
},
|
|
119
114
|
input?: string | null,
|
|
120
115
|
) {
|
|
121
116
|
const currentPath = input || path || '';
|
|
122
|
-
const filePath = relative(resolve(root || '', rootPublicPath || ''), currentPath);
|
|
123
117
|
const transformer = transformLink || defaultTransformLink;
|
|
124
|
-
const href = transformer(
|
|
118
|
+
const href = transformer?.(currentPath) ?? currentPath;
|
|
125
119
|
return href;
|
|
126
120
|
}
|
package/src/transform/utilsFS.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {readFileSync, statSync} from 'fs';
|
|
2
2
|
import type {Dictionary} from 'lodash';
|
|
3
3
|
import escapeRegExp from 'lodash/escapeRegExp';
|
|
4
|
-
|
|
5
|
-
import {join, parse, resolve, sep} from 'path';
|
|
4
|
+
import {join, parse, relative, resolve, sep} from 'path';
|
|
6
5
|
|
|
7
6
|
import liquid from './liquid';
|
|
8
7
|
import {StateCore} from './typings';
|
|
8
|
+
import {defaultTransformLink} from './utils';
|
|
9
9
|
|
|
10
10
|
const filesCache: Record<string, string> = {};
|
|
11
11
|
|
|
@@ -127,3 +127,24 @@ export function getSinglePageAnchorId(args: {
|
|
|
127
127
|
|
|
128
128
|
return `#${resultAnchor}`;
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
export function getPublicPath(
|
|
132
|
+
{
|
|
133
|
+
path,
|
|
134
|
+
root,
|
|
135
|
+
rootPublicPath,
|
|
136
|
+
transformLink,
|
|
137
|
+
}: {
|
|
138
|
+
path?: string;
|
|
139
|
+
root?: string;
|
|
140
|
+
rootPublicPath?: string;
|
|
141
|
+
transformLink?: (href: string) => string;
|
|
142
|
+
},
|
|
143
|
+
input?: string | null,
|
|
144
|
+
) {
|
|
145
|
+
const currentPath = input || path || '';
|
|
146
|
+
const filePath = relative(resolve(root || '', rootPublicPath || ''), currentPath);
|
|
147
|
+
const transformer = transformLink || defaultTransformLink;
|
|
148
|
+
const href = transformer(filePath);
|
|
149
|
+
return href;
|
|
150
|
+
}
|