Skip to content

Commit

Permalink
highlight can load unsupported languages (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailsKuzmins committed Jun 5, 2024
1 parent 61c9b0c commit 05b894f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
13 changes: 12 additions & 1 deletion samples/MudBlazor.Markdown.Core/sample-issues.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# [Nested text](https://github.com/MyNihongo/MudBlazor.Markdown/issues/233)
# [Unknown language - Razor](https://github.com/MyNihongo/MudBlazor.Markdown/issues/260)
```razor
@page
@model IndexModel
@{
ViewData["Title"] = "Home Page";
}
<h2>@ViewData["Title"]</h2>
```

# [Nested text](https://github.com/MyNihongo/MudBlazor.Markdown/issues/233)
> To prevent the warning message regarding the deprecation of the `mysql_native_password` plugin from being logged, you have a couple of options:
>
> Option 1: Update User Authentication Method:
Expand Down
2 changes: 1 addition & 1 deletion src/MudBlazor.Markdown/MudBlazor.Markdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="MudBlazor" Version="6.20.0" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 14 additions & 1 deletion src/MudBlazor.Markdown/Resources/MudBlazor.Markdown.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import hljs from "highlight.js";
import hljsRazor from "highlightjs-cshtml-razor";

hljs.registerLanguage("cshtml", hljsRazor);
hljs.registerLanguage("razor", hljsRazor);
hljs.registerLanguage("razor-cshtml", hljsRazor);

const codeStylesDir = "code-styles";
const codeStylesSegment = `/MudBlazor.Markdown/${codeStylesDir}/`;

window.highlightCodeElement = function (element, text, language) {
const result = language ? hljs.highlight(text, { language }) : hljs.highlightAuto(text);
let result;

try {
result = language ? hljs.highlight(text, { language }) : hljs.highlightAuto(text);
} catch (e) {
console.error(e);
result = hljs.highlightAuto(text);
}

element.innerHTML = result.value;
}

Expand Down
32 changes: 31 additions & 1 deletion src/MudBlazor.Markdown/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/MudBlazor.Markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"webpack-stream": "^7.0.0"
},
"dependencies": {
"highlight.js": "^11.9.0"
"highlight.js": "^11.9.0",
"highlightjs-cshtml-razor": "^2.1.1"
}
}

0 comments on commit 05b894f

Please sign in to comment.