Skip to content

Commit 5176a95

Browse files
committed
Remove most of angular highlighter as it's not needed
1 parent 33f898f commit 5176a95

3 files changed

Lines changed: 2 additions & 66 deletions

File tree

build/lib/angularHighlighter.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
export function mustUseAngularHighlighter(fileContent: string): boolean;
2-
3-
export function highlightAngularComponent(fileContent: string): Promise<string>;

build/lib/angularHighlighter.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,5 @@
1-
import { codeToHighlightCodeHtml } from "./highlighter.ts";
2-
31
export function mustUseAngularHighlighter(fileContent: string): boolean {
42
return (
53
fileContent.includes("@angular/core") && fileContent.includes("template")
64
);
75
}
8-
9-
export async function highlightAngularComponent(
10-
fileContent: string,
11-
): Promise<string> {
12-
const templateCode = getAngularTemplateCode(fileContent);
13-
14-
let codeHighlighted;
15-
if (templateCode) {
16-
const componentWithEmptyTemplate =
17-
removeAngularTemplateContent(fileContent);
18-
const templateCodeHighlighted = await codeToHighlightCodeHtml(
19-
templateCode,
20-
"angular-html",
21-
);
22-
23-
const componentWithoutTemplateHighlighted = await codeToHighlightCodeHtml(
24-
componentWithEmptyTemplate,
25-
"angular-ts",
26-
);
27-
28-
codeHighlighted = componentWithoutTemplateHighlighted.replace(
29-
"template",
30-
"template: `" + removeCodeWrapper(templateCodeHighlighted) + "`,",
31-
);
32-
} else {
33-
codeHighlighted = await codeToHighlightCodeHtml(fileContent, "angular-ts");
34-
}
35-
36-
return codeHighlighted;
37-
}
38-
39-
function getAngularTemplateCode(fileContent: string): string {
40-
// regex to grab what is inside angular component template inside backticks
41-
const regex = /template:\s*`([\s\S]*?)`/gm;
42-
43-
// grab the template string
44-
const template = regex.exec(fileContent);
45-
46-
if (template) return template[1];
47-
48-
return "";
49-
}
50-
51-
function removeAngularTemplateContent(fileContent: string): string {
52-
const componentWithoutContentInsideTemplate = fileContent.replace(
53-
/template:\s*`([\s\S]*?)([^*])`,?/gm,
54-
"template",
55-
);
56-
57-
return componentWithoutContentInsideTemplate;
58-
}
59-
60-
function removeCodeWrapper(html: string): string {
61-
const regexForWrapper = /<pre([\s\S]*?)><code>([\s\S]*?)<\/code><\/pre>/gm;
62-
const code = regexForWrapper.exec(html);
63-
return code ? code[2] : "";
64-
}

build/lib/generateContent.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import path from "node:path";
44
import { frameworks } from "../../frameworks.ts";
55
import playgroundUrlByFramework from "./playgroundUrlByFramework.ts";
66
import prettier from "prettier";
7-
import {
8-
highlightAngularComponent,
9-
mustUseAngularHighlighter,
10-
} from "./angularHighlighter.ts";
7+
import { mustUseAngularHighlighter } from "./angularHighlighter.ts";
118
import {
129
codeToHighlightCodeHtml,
1310
markdownToHighlightedHtml,
@@ -210,7 +207,7 @@ export default async function generateContent(
210207
frameworkSnippet.markdownFiles.push(file);
211208
} else {
212209
file.contentHtml = mustUseAngularHighlighter(content)
213-
? await highlightAngularComponent(content)
210+
? await codeToHighlightCodeHtml(content, "angular-ts")
214211
: await codeToHighlightCodeHtml(content, ext);
215212

216213
frameworkSnippet.files.push(file);

0 commit comments

Comments
 (0)