@diplodoc/transform 4.37.0 → 4.38.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.map +1 -1
- package/dist/css/_yfm-only.min.css.map +1 -1
- 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.map +1 -1
- package/dist/css/yfm.min.css.map +1 -1
- package/lib/plugins/anchors/index.js +3 -3
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/includes/index.js +6 -5
- package/lib/plugins/includes/index.js.map +1 -1
- package/lib/sanitize.js +4 -1
- package/lib/sanitize.js.map +1 -1
- package/lib/utilsFS.d.ts +1 -0
- package/lib/utilsFS.js +10 -1
- package/lib/utilsFS.js.map +1 -1
- package/package.json +2 -2
- package/src/transform/plugins/anchors/index.ts +2 -3
- package/src/transform/plugins/includes/index.ts +16 -8
- package/src/transform/sanitize.ts +5 -1
- package/src/transform/utilsFS.ts +9 -1
|
@@ -2,7 +2,13 @@ import {bold} from 'chalk';
|
|
|
2
2
|
import Token from 'markdown-it/lib/token';
|
|
3
3
|
|
|
4
4
|
import {StateCore} from '../../typings';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
GetFileTokensOpts,
|
|
7
|
+
getFileTokens,
|
|
8
|
+
getFullIncludePath,
|
|
9
|
+
getRealPath,
|
|
10
|
+
isFileExists,
|
|
11
|
+
} from '../../utilsFS';
|
|
6
12
|
import {findBlockTokens} from '../../utils';
|
|
7
13
|
import {MarkdownItPluginCb, MarkdownItPluginOpts} from '../typings';
|
|
8
14
|
|
|
@@ -44,13 +50,8 @@ function unfoldIncludes(md: MarkdownItIncluded, state: StateCore, path: string,
|
|
|
44
50
|
|
|
45
51
|
const fullIncludePath = getFullIncludePath(includePath, root, path);
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
let
|
|
49
|
-
const hashIndex = fullIncludePath.lastIndexOf('#');
|
|
50
|
-
if (hashIndex > -1 && !isFileExists(pathname)) {
|
|
51
|
-
pathname = fullIncludePath.slice(0, hashIndex);
|
|
52
|
-
hash = fullIncludePath.slice(hashIndex + 1);
|
|
53
|
-
}
|
|
53
|
+
// Check the real path of the file in case of a symlink
|
|
54
|
+
let pathname = getRealPath(fullIncludePath);
|
|
54
55
|
|
|
55
56
|
if (!pathname.startsWith(root)) {
|
|
56
57
|
i++;
|
|
@@ -58,6 +59,13 @@ function unfoldIncludes(md: MarkdownItIncluded, state: StateCore, path: string,
|
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
let hash = '';
|
|
63
|
+
const hashIndex = fullIncludePath.lastIndexOf('#');
|
|
64
|
+
if (hashIndex > -1 && !isFileExists(pathname)) {
|
|
65
|
+
pathname = fullIncludePath.slice(0, hashIndex);
|
|
66
|
+
hash = fullIncludePath.slice(hashIndex + 1);
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
// Check the existed included store and extract it
|
|
62
70
|
const included = md.included?.[pathname];
|
|
63
71
|
|
|
@@ -5,6 +5,7 @@ import * as cheerio from 'cheerio';
|
|
|
5
5
|
import css from 'css';
|
|
6
6
|
|
|
7
7
|
import {CssWhiteList} from './typings';
|
|
8
|
+
import log from './log';
|
|
8
9
|
|
|
9
10
|
const htmlTags = [
|
|
10
11
|
'a',
|
|
@@ -560,8 +561,11 @@ function sanitizeStyleTags(dom: cheerio.CheerioAPI, cssWhiteList: CssWhiteList)
|
|
|
560
561
|
});
|
|
561
562
|
|
|
562
563
|
dom(element).text(css.stringify(parsedCSS));
|
|
563
|
-
} catch {
|
|
564
|
+
} catch (error) {
|
|
564
565
|
dom(element).remove();
|
|
566
|
+
|
|
567
|
+
const errorMessage = error instanceof Error ? error.message : `${error}`;
|
|
568
|
+
log.info(errorMessage);
|
|
565
569
|
}
|
|
566
570
|
});
|
|
567
571
|
}
|
package/src/transform/utilsFS.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {Dictionary} from 'lodash';
|
|
2
2
|
|
|
3
|
-
import {readFileSync, statSync} from 'fs';
|
|
3
|
+
import {readFileSync, realpathSync, statSync} from 'fs';
|
|
4
4
|
import escapeRegExp from 'lodash/escapeRegExp';
|
|
5
5
|
import {join, parse, relative, resolve, sep} from 'path';
|
|
6
6
|
|
|
@@ -168,3 +168,11 @@ export function getRelativePath(path: string, toPath: string) {
|
|
|
168
168
|
const parentPath = pathDirs.join(sep);
|
|
169
169
|
return relative(parentPath, toPath);
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
export function getRealPath(symlinkPath: string): string {
|
|
173
|
+
try {
|
|
174
|
+
return realpathSync(symlinkPath);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
return symlinkPath;
|
|
177
|
+
}
|
|
178
|
+
}
|