@lwrjs/markdown-view-provider 0.6.0-alpha.1 → 0.6.0-alpha.13
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/build/cjs/markdown-parser/plugins/highlighter.cjs +10 -1
- package/build/cjs/markdown-parser/plugins/md-metadata-collector.cjs +9 -3
- package/build/es/markdown-parser/plugins/highlighter.js +12 -3
- package/build/es/markdown-parser/plugins/md-metadata-collector.js +9 -3
- package/package.json +6 -6
|
@@ -32,12 +32,21 @@ var import_hast_util_to_string = __toModule(require("hast-util-to-string"));
|
|
|
32
32
|
var Shiki = __toModule(require("shiki"));
|
|
33
33
|
var import_rehype_parse = __toModule(require("rehype-parse"));
|
|
34
34
|
var hastParser = (0, import_unified.default)().use(import_rehype_parse.default, {fragment: true});
|
|
35
|
+
function isPreNode(node) {
|
|
36
|
+
return node.tagName === "pre";
|
|
37
|
+
}
|
|
38
|
+
function isParentNode(node) {
|
|
39
|
+
return Array.isArray(node.children);
|
|
40
|
+
}
|
|
41
|
+
function isCodeNode(node) {
|
|
42
|
+
return node.tagName === "code";
|
|
43
|
+
}
|
|
35
44
|
async function getHtmlHighlighter(options) {
|
|
36
45
|
const highlighter = await Shiki.getHighlighter({theme: options.theme});
|
|
37
46
|
return function htmlHighlighter() {
|
|
38
47
|
return function(tree) {
|
|
39
48
|
(0, import_unist_util_modify_children.default)((node, index, parent) => {
|
|
40
|
-
if (node
|
|
49
|
+
if (isPreNode(node) && isParentNode(node) && node.children.length === 1 && isCodeNode(node.children[0]) && typeof node.children[0].properties === "object" && Array.isArray(node.children[0].properties.className) && typeof node.children[0].properties.className[0] === "string" && node.children[0].properties.className[0].startsWith("language-")) {
|
|
41
50
|
const code = (0, import_hast_util_to_string.default)(node);
|
|
42
51
|
const language = node.children[0].properties.className[0].slice("language-".length);
|
|
43
52
|
let highlightedCodeHTML;
|
|
@@ -28,6 +28,12 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_unist_util_visit = __toModule(require("unist-util-visit"));
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
|
+
function isLiteralNode(node) {
|
|
32
|
+
return node && typeof node.value === "string";
|
|
33
|
+
}
|
|
34
|
+
function isParentNode(node) {
|
|
35
|
+
return node && Array.isArray(node.children);
|
|
36
|
+
}
|
|
31
37
|
function headingVisitor(collector, {depth, children}) {
|
|
32
38
|
const text = toStringAll(children);
|
|
33
39
|
const slug = (0, import_shared_utils.slugify)(text);
|
|
@@ -48,7 +54,7 @@ function toStringAll(values) {
|
|
|
48
54
|
const result = [];
|
|
49
55
|
let index = -1;
|
|
50
56
|
while (++index < values.length) {
|
|
51
|
-
if (values[index]
|
|
57
|
+
if (isLiteralNode(values[index])) {
|
|
52
58
|
result[index] = toString(values[index]);
|
|
53
59
|
}
|
|
54
60
|
}
|
|
@@ -56,9 +62,9 @@ function toStringAll(values) {
|
|
|
56
62
|
}
|
|
57
63
|
function toString(node) {
|
|
58
64
|
let ret = "";
|
|
59
|
-
if (node
|
|
65
|
+
if (isLiteralNode(node)) {
|
|
60
66
|
ret = String(node.value);
|
|
61
|
-
} else if (node
|
|
67
|
+
} else if (isParentNode(node)) {
|
|
62
68
|
ret = toStringAll(node.children);
|
|
63
69
|
}
|
|
64
70
|
return ret;
|
|
@@ -4,6 +4,15 @@ import hastUtilToString from 'hast-util-to-string';
|
|
|
4
4
|
import * as Shiki from 'shiki';
|
|
5
5
|
import rehypeParse from 'rehype-parse';
|
|
6
6
|
const hastParser = unified().use(rehypeParse, { fragment: true });
|
|
7
|
+
function isPreNode(node) {
|
|
8
|
+
return node.tagName === 'pre';
|
|
9
|
+
}
|
|
10
|
+
function isParentNode(node) {
|
|
11
|
+
return Array.isArray(node.children);
|
|
12
|
+
}
|
|
13
|
+
function isCodeNode(node) {
|
|
14
|
+
return node.tagName === 'code';
|
|
15
|
+
}
|
|
7
16
|
/**
|
|
8
17
|
* Generates an configured unified.Plugin for highlighting `code` snippets.
|
|
9
18
|
* @param options Allow the configuration of the HTML Highlighter (e.g. the `theme` used).
|
|
@@ -14,10 +23,10 @@ export async function getHtmlHighlighter(options) {
|
|
|
14
23
|
return function htmlHighlighter() {
|
|
15
24
|
return function (tree) {
|
|
16
25
|
unistUtilModifyChildren((node, index, parent) => {
|
|
17
|
-
if (node
|
|
18
|
-
|
|
26
|
+
if (isPreNode(node) &&
|
|
27
|
+
isParentNode(node) &&
|
|
19
28
|
node.children.length === 1 &&
|
|
20
|
-
node.children[0]
|
|
29
|
+
isCodeNode(node.children[0]) &&
|
|
21
30
|
typeof node.children[0].properties === 'object' &&
|
|
22
31
|
Array.isArray(node.children[0].properties.className) &&
|
|
23
32
|
typeof node.children[0].properties.className[0] === 'string' &&
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import visit from 'unist-util-visit';
|
|
2
2
|
import { slugify } from '@lwrjs/shared-utils';
|
|
3
|
+
function isLiteralNode(node) {
|
|
4
|
+
return node && typeof node.value === 'string';
|
|
5
|
+
}
|
|
6
|
+
function isParentNode(node) {
|
|
7
|
+
return node && Array.isArray(node.children);
|
|
8
|
+
}
|
|
3
9
|
function headingVisitor(collector, { depth, children }) {
|
|
4
10
|
const text = toStringAll(children);
|
|
5
11
|
const slug = slugify(text);
|
|
@@ -21,7 +27,7 @@ function toStringAll(values) {
|
|
|
21
27
|
const result = [];
|
|
22
28
|
let index = -1;
|
|
23
29
|
while (++index < values.length) {
|
|
24
|
-
if (values[index]
|
|
30
|
+
if (isLiteralNode(values[index])) {
|
|
25
31
|
result[index] = toString(values[index]);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
@@ -29,10 +35,10 @@ function toStringAll(values) {
|
|
|
29
35
|
}
|
|
30
36
|
function toString(node) {
|
|
31
37
|
let ret = '';
|
|
32
|
-
if (node
|
|
38
|
+
if (isLiteralNode(node)) {
|
|
33
39
|
ret = String(node.value);
|
|
34
40
|
}
|
|
35
|
-
else if (node
|
|
41
|
+
else if (isParentNode(node)) {
|
|
36
42
|
ret = toStringAll(node.children);
|
|
37
43
|
}
|
|
38
44
|
return ret;
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.0-alpha.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.13",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/base-template-engine": "0.6.0-alpha.
|
|
34
|
-
"@lwrjs/shared-utils": "0.6.0-alpha.
|
|
33
|
+
"@lwrjs/base-template-engine": "0.6.0-alpha.13",
|
|
34
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.13",
|
|
35
35
|
"gray-matter": "^4.0.2",
|
|
36
36
|
"hast-util-has-property": "^1.0.4",
|
|
37
37
|
"hast-util-heading-rank": "^1.0.1",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"vfile": "^4.2.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
53
|
+
"@lwrjs/types": "0.6.0-alpha.13"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=14.15.4 <17"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "056d10307fe29540d1586f8fd75e357b82ce2acc"
|
|
59
59
|
}
|