Skip to content

Commit 65c25c9

Browse files
committed
Update md compiler to use code custom element
1 parent 50dc20f commit 65c25c9

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

tools/transforms/content-package/services/renderer/code.renderer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ export function applyCodeRenderer(renderer: Renderer) {
1818
const filenameIndex = code.indexOf(filenameKey);
1919
if (filenameIndex >= 0) {
2020
return replaceFilename(
21-
(text, directiveRef) =>
22-
// @ts-ignore
23-
renderer.code(text, language, isEscaped, directiveRef),
21+
(text) =>
22+
renderer.code(text, language, isEscaped),
2423
code,
2524
filenameKey,
2625
filenameIndex

tools/transforms/shared/utils/markdown-utils.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,18 @@ export function appendEmptyLine(text: string) {
1717
}
1818

1919
export function replaceFilename(
20-
renderer: (code: string, directiveRef: string) => string,
20+
renderer: (code: string) => string,
2121
text: string,
2222
filenameKey: string,
2323
filenameIndex: number,
2424
) {
2525
const startIndex = filenameIndex + filenameKey.length;
2626
const endIndex = text.indexOf(')');
27-
const directiveRef = `app` + crypto.randomBytes(20).toString('hex');
2827
const filename = text.slice(startIndex + 1, endIndex);
29-
return (
30-
`
31-
<span class="filename">` +
32-
(filename.length > 0
33-
? `
34-
{{ '${filename}' | extension: ${directiveRef}.isJsActive }}`
35-
: '') +
36-
`
37-
<app-tabs #${directiveRef}></app-tabs>
38-
</span>` +
39-
renderer(text.slice(endIndex + 1), directiveRef).trim()
40-
);
28+
return `
29+
<code-element ${filename.length ? `filename="${filename}"` : ''}>
30+
${renderer(text.slice(endIndex + 1)).trim()}
31+
</code-element>`;
4132
}
4233

4334
export function parseSwitcher(
@@ -49,12 +40,14 @@ export function parseSwitcher(
4940
) {
5041
const tsCode = text.slice(0, switchIndex).trim();
5142
const jsCode = text.slice(switchIndex + switchKey.length, text.length).trim();
52-
const wrapCondition = (snippet: string, lang: 'ts' | 'js') =>
53-
elementKey
54-
? snippet.slice(0, 4) +
55-
` [class.hide]="${lang === 'js' ? '!' : ''}${elementKey}.isJsActive"` +
56-
snippet.slice(4, snippet.length)
57-
: snippet;
43+
44+
const wrapCondition = (htmlSnippet: string, lang: 'ts' | 'js'): string => {
45+
// The beginning of the pre-Tag (<pre)
46+
const beginPreTag = htmlSnippet.slice(0, 4);
47+
const endPreTag = htmlSnippet.slice(4, htmlSnippet.length);
48+
return `${beginPreTag} slot=${lang}${endPreTag}`;
49+
};
50+
5851
return (
5952
wrapCondition(renderer(tsCode, 'typescript'), 'ts') +
6053
wrapCondition(renderer(jsCode, 'typescript'), 'js')

0 commit comments

Comments
 (0)