@astrojs/markdoc 0.7.1 → 0.8.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/LICENSE +0 -2
- package/components/TreeNode.ts +7 -10
- package/dist/extensions/shiki.d.ts +1 -1
- package/dist/extensions/shiki.js +5 -74
- package/package.json +13 -14
package/LICENSE
CHANGED
|
@@ -20,7 +20,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
"""
|
|
25
24
|
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
|
26
25
|
|
|
@@ -33,7 +32,6 @@ The above copyright notice and this permission notice shall be included in all c
|
|
|
33
32
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
34
33
|
"""
|
|
35
34
|
|
|
36
|
-
|
|
37
35
|
"""
|
|
38
36
|
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
|
|
39
37
|
|
package/components/TreeNode.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { AstroInstance } from 'astro';
|
|
2
1
|
import type { RenderableTreeNode } from '@markdoc/markdoc';
|
|
3
2
|
import Markdoc from '@markdoc/markdoc';
|
|
3
|
+
import type { AstroInstance } from 'astro';
|
|
4
|
+
import type { HTMLString } from 'astro/runtime/server/index.js';
|
|
4
5
|
import {
|
|
5
6
|
createComponent,
|
|
6
|
-
|
|
7
|
+
createHeadAndContent,
|
|
8
|
+
isHTMLString,
|
|
7
9
|
render,
|
|
10
|
+
renderComponent,
|
|
8
11
|
renderScriptElement,
|
|
12
|
+
renderTemplate,
|
|
9
13
|
renderUniqueStylesheet,
|
|
10
|
-
createHeadAndContent,
|
|
11
14
|
unescapeHTML,
|
|
12
|
-
renderTemplate,
|
|
13
|
-
HTMLString,
|
|
14
|
-
isHTMLString,
|
|
15
15
|
} from 'astro/runtime/server/index.js';
|
|
16
16
|
|
|
17
17
|
export type TreeNode =
|
|
@@ -89,10 +89,7 @@ export const ComponentNode = createComponent({
|
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
// Let the runtime know that this component is being used.
|
|
92
|
-
|
|
93
|
-
// TODO: remove this fallback in the next markdoc integration major
|
|
94
|
-
const propagators = result._metadata.propagators || result.propagators;
|
|
95
|
-
propagators.add({
|
|
92
|
+
result._metadata.propagators.add({
|
|
96
93
|
init() {
|
|
97
94
|
return headAndContent;
|
|
98
95
|
},
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ShikiConfig } from 'astro';
|
|
2
2
|
import type { AstroMarkdocConfig } from '../config.js';
|
|
3
|
-
export default function shiki(
|
|
3
|
+
export default function shiki(config?: ShikiConfig): Promise<AstroMarkdocConfig>;
|
package/dist/extensions/shiki.js
CHANGED
|
@@ -1,90 +1,21 @@
|
|
|
1
|
+
import { createShikiHighlighter } from "@astrojs/markdown-remark";
|
|
1
2
|
import Markdoc from "@markdoc/markdoc";
|
|
2
3
|
import { unescapeHTML } from "astro/runtime/server/index.js";
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
"#000001": "var(--astro-code-color-text)",
|
|
6
|
-
"#000002": "var(--astro-code-color-background)",
|
|
7
|
-
"#000004": "var(--astro-code-token-constant)",
|
|
8
|
-
"#000005": "var(--astro-code-token-string)",
|
|
9
|
-
"#000006": "var(--astro-code-token-comment)",
|
|
10
|
-
"#000007": "var(--astro-code-token-keyword)",
|
|
11
|
-
"#000008": "var(--astro-code-token-parameter)",
|
|
12
|
-
"#000009": "var(--astro-code-token-function)",
|
|
13
|
-
"#000010": "var(--astro-code-token-string-expression)",
|
|
14
|
-
"#000011": "var(--astro-code-token-punctuation)",
|
|
15
|
-
"#000012": "var(--astro-code-token-link)"
|
|
16
|
-
};
|
|
17
|
-
const COLOR_REPLACEMENT_REGEX = new RegExp(
|
|
18
|
-
`(${Object.keys(ASTRO_COLOR_REPLACEMENTS).join("|")})`,
|
|
19
|
-
"g"
|
|
20
|
-
);
|
|
21
|
-
const PRE_SELECTOR = /<pre class="(.*?)shiki(.*?)"/;
|
|
22
|
-
const LINE_SELECTOR = /<span class="line"><span style="(.*?)">([\+|\-])/g;
|
|
23
|
-
const INLINE_STYLE_SELECTOR = /style="(.*?)"/;
|
|
24
|
-
const INLINE_STYLE_SELECTOR_GLOBAL = /style="(.*?)"/g;
|
|
25
|
-
const highlighterCache = /* @__PURE__ */ new Map();
|
|
26
|
-
async function shiki({
|
|
27
|
-
langs = [],
|
|
28
|
-
theme = "github-dark",
|
|
29
|
-
wrap = false
|
|
30
|
-
} = {}) {
|
|
31
|
-
const cacheId = typeof theme === "string" ? theme : theme.name || "";
|
|
32
|
-
let highlighter = highlighterCache.get(cacheId);
|
|
33
|
-
if (!highlighter) {
|
|
34
|
-
highlighter = await getHighlighter({
|
|
35
|
-
langs: langs.length ? langs : Object.keys(bundledLanguages),
|
|
36
|
-
themes: [theme]
|
|
37
|
-
});
|
|
38
|
-
highlighterCache.set(cacheId, highlighter);
|
|
39
|
-
}
|
|
4
|
+
async function shiki(config) {
|
|
5
|
+
const highlighter = await createShikiHighlighter(config);
|
|
40
6
|
return {
|
|
41
7
|
nodes: {
|
|
42
8
|
fence: {
|
|
43
9
|
attributes: Markdoc.nodes.fence.attributes,
|
|
44
10
|
transform({ attributes }) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const langExists = highlighter.getLoadedLanguages().includes(attributes.language);
|
|
48
|
-
if (langExists) {
|
|
49
|
-
lang = attributes.language;
|
|
50
|
-
} else {
|
|
51
|
-
console.warn(
|
|
52
|
-
`[Shiki highlighter] The language "${attributes.language}" doesn't exist, falling back to plaintext.`
|
|
53
|
-
);
|
|
54
|
-
lang = "plaintext";
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
lang = "plaintext";
|
|
58
|
-
}
|
|
59
|
-
let html = highlighter.codeToHtml(attributes.content, { lang, theme });
|
|
60
|
-
html = html.replace(PRE_SELECTOR, `<pre class="$1astro-code$2"`);
|
|
61
|
-
if (attributes.language === "diff") {
|
|
62
|
-
html = html.replace(
|
|
63
|
-
LINE_SELECTOR,
|
|
64
|
-
'<span class="line"><span style="$1"><span style="user-select: none;">$2</span>'
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
if (wrap === false) {
|
|
68
|
-
html = html.replace(INLINE_STYLE_SELECTOR, 'style="$1; overflow-x: auto;"');
|
|
69
|
-
} else if (wrap === true) {
|
|
70
|
-
html = html.replace(
|
|
71
|
-
INLINE_STYLE_SELECTOR,
|
|
72
|
-
'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
76
|
-
if (themeName === "css-variables") {
|
|
77
|
-
html = html.replace(INLINE_STYLE_SELECTOR_GLOBAL, (m) => replaceCssVariables(m));
|
|
78
|
-
}
|
|
11
|
+
const lang = typeof attributes.language === "string" ? attributes.language : "plaintext";
|
|
12
|
+
const html = highlighter.highlight(attributes.content, lang);
|
|
79
13
|
return unescapeHTML(html);
|
|
80
14
|
}
|
|
81
15
|
}
|
|
82
16
|
}
|
|
83
17
|
};
|
|
84
18
|
}
|
|
85
|
-
function replaceCssVariables(str) {
|
|
86
|
-
return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
|
|
87
|
-
}
|
|
88
19
|
export {
|
|
89
20
|
shiki as default
|
|
90
21
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdoc",
|
|
3
3
|
"description": "Add support for Markdoc in your Astro site",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -56,33 +56,32 @@
|
|
|
56
56
|
"template"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@markdoc/markdoc": "^0.3.
|
|
60
|
-
"esbuild": "^0.19.
|
|
59
|
+
"@markdoc/markdoc": "^0.3.5",
|
|
60
|
+
"esbuild": "^0.19.6",
|
|
61
61
|
"github-slugger": "^2.0.0",
|
|
62
62
|
"gray-matter": "^4.0.3",
|
|
63
63
|
"htmlparser2": "^9.0.0",
|
|
64
64
|
"kleur": "^4.1.5",
|
|
65
|
-
"shikiji": "^0.6.
|
|
65
|
+
"shikiji": "^0.6.13",
|
|
66
66
|
"zod": "^3.22.4",
|
|
67
67
|
"@astrojs/internal-helpers": "0.2.1",
|
|
68
68
|
"@astrojs/prism": "3.0.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"astro": "^3.0.0"
|
|
71
|
+
"astro": "^3.0.0 || ^4.0.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@types/chai": "^4.3.
|
|
75
|
-
"@types/html-escaper": "^3.0.
|
|
76
|
-
"@types/markdown-it": "^13.0.
|
|
77
|
-
"@types/mocha": "^10.0.
|
|
74
|
+
"@types/chai": "^4.3.10",
|
|
75
|
+
"@types/html-escaper": "^3.0.2",
|
|
76
|
+
"@types/markdown-it": "^13.0.6",
|
|
77
|
+
"@types/mocha": "^10.0.4",
|
|
78
78
|
"chai": "^4.3.7",
|
|
79
79
|
"devalue": "^4.3.2",
|
|
80
|
-
"linkedom": "^0.
|
|
80
|
+
"linkedom": "^0.16.4",
|
|
81
81
|
"mocha": "^10.2.0",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"astro": "3.4.1",
|
|
82
|
+
"vite": "^5.0.0",
|
|
83
|
+
"@astrojs/markdown-remark": "4.0.0",
|
|
84
|
+
"astro": "4.0.0",
|
|
86
85
|
"astro-scripts": "0.0.14"
|
|
87
86
|
},
|
|
88
87
|
"engines": {
|