@salesforcedevs/sfdocs-remark-include-plugin 0.0.3-alpha → 0.0.4-alpha
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/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ import { Transformer } from 'unified';
|
|
|
6
6
|
* with the included content. Must be used after remark-directive.
|
|
7
7
|
* When the included file path contains /shared/, image URLs in that content are rewritten to absolute paths using the content directory.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns Remark transformer
|
|
9
|
+
* @param customRenderFunctions - Optional { renderInclude } for custom HTML rendering (same as genericDirective)
|
|
10
|
+
* @returns Function that returns a Remark transformer
|
|
11
11
|
*/
|
|
12
|
-
declare function includePlugin(
|
|
12
|
+
declare function includePlugin(customRenderFunctions?: {
|
|
13
13
|
renderInclude?: (metadata: Map<string, unknown>) => Map<string, string>;
|
|
14
|
-
}): Transformer;
|
|
14
|
+
}): () => Transformer;
|
|
15
15
|
export default includePlugin;
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAwCtC;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAwCtC;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAC,qBAAqB,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,SACjF,WAAW,CAuCnD;AAED,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -46,48 +46,50 @@ function transformImageLinksInTree(root, contentDir) {
|
|
|
46
46
|
* with the included content. Must be used after remark-directive.
|
|
47
47
|
* When the included file path contains /shared/, image URLs in that content are rewritten to absolute paths using the content directory.
|
|
48
48
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @returns Remark transformer
|
|
49
|
+
* @param customRenderFunctions - Optional { renderInclude } for custom HTML rendering (same as genericDirective)
|
|
50
|
+
* @returns Function that returns a Remark transformer
|
|
51
51
|
*/
|
|
52
|
-
function includePlugin(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const filename = path_1.default.resolve(file.dirname || '', src);
|
|
65
|
-
if (!fs_1.default.existsSync(filename)) {
|
|
66
|
-
file.fail(`File not found ${filename}`, node);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
const content = fs_1.default.readFileSync(filename);
|
|
71
|
-
const includeFile = (0, vfile_1.default)({ path: filename, contents: content });
|
|
72
|
-
if (options === null || options === void 0 ? void 0 : options.renderInclude) {
|
|
73
|
-
const root = processor.processSync(includeFile);
|
|
74
|
-
const metadata = new Map([['root', root], ['node', node]]);
|
|
75
|
-
const out = options.renderInclude(metadata).get('outputDom');
|
|
76
|
-
parent.children.splice(i, 1, { type: 'html', value: out });
|
|
52
|
+
function includePlugin(customRenderFunctions) {
|
|
53
|
+
return function includePluginImpl() {
|
|
54
|
+
const processor = this;
|
|
55
|
+
return function transformer(tree, file) {
|
|
56
|
+
(0, unist_util_visit_1.default)(tree, (node, i, parent) => {
|
|
57
|
+
var _a;
|
|
58
|
+
if (node.type !== LEAF_DIRECTIVE_TYPE || node.name !== INCLUDE_DIRECTIVE || !parent)
|
|
59
|
+
return;
|
|
60
|
+
const src = (_a = node.attributes) === null || _a === void 0 ? void 0 : _a.src;
|
|
61
|
+
if (!src) {
|
|
62
|
+
file.fail('Include directive requires a src attribute', node);
|
|
63
|
+
return;
|
|
77
64
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
const filename = path_1.default.resolve(file.dirname || '', src);
|
|
66
|
+
if (!fs_1.default.existsSync(filename)) {
|
|
67
|
+
file.fail(`File not found ${filename}`, node);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const content = fs_1.default.readFileSync(filename);
|
|
72
|
+
const includeFile = (0, vfile_1.default)({ path: filename, contents: content });
|
|
73
|
+
if (customRenderFunctions === null || customRenderFunctions === void 0 ? void 0 : customRenderFunctions.renderInclude) {
|
|
74
|
+
const root = processor.processSync(includeFile);
|
|
75
|
+
const metadata = new Map([['root', root], ['node', node]]);
|
|
76
|
+
const out = customRenderFunctions.renderInclude(metadata).get('outputDom');
|
|
77
|
+
parent.children.splice(i, 1, { type: 'html', value: out !== null && out !== void 0 ? out : '' });
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
let root = processor.parse(includeFile);
|
|
81
|
+
if (filename.includes(SHARED_PATH_SEGMENT)) {
|
|
82
|
+
transformImageLinksInTree(root, getContentDirPath(filename));
|
|
83
|
+
}
|
|
84
|
+
const { children } = root;
|
|
85
|
+
parent.children.splice(i + 1, 0, ...(Array.isArray(children) ? children : []));
|
|
82
86
|
}
|
|
83
|
-
const { children } = root;
|
|
84
|
-
parent.children.splice(i + 1, 0, ...(Array.isArray(children) ? children : []));
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
file.fail((err === null || err === void 0 ? void 0 : err.message) || `Failed to read file ${filename}`, node);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
exports.default = includePlugin;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,wEAAqC;AAErC,gDAAwB;AACxB,4CAAoB;AACpB,kDAAqC;AAErC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAC5C,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAEvC,SAAS,iBAAiB,CAAC,WAAmB;IAC1C,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACrD,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE;QACjB,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;KACjE;IACD,OAAO,EAAE,CAAC;AACd,CAAC;AAED,SAAS,sBAAsB,CAAC,UAAkB;IAC9C,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,UAAU,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC,IAAI,IAAI,KAAK,CAAC,CAAC;QAAE,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAS,EAAE,UAAkB;IAC5D,IAAI,CAAC,UAAU;QAAE,OAAO;IACxB,IAAA,0BAAK,EAAC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