Skip to content

Commit

Permalink
Fix missing hljs object (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoituron authored Sep 9, 2024
1 parent dea12bb commit 0c8cfa1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/Demo/Shared/Components/CodeSnippet.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender)
{

await JSRuntime.InvokeVoidAsync("hljs.highlightElement", codeElement);
_jsModule = await JSRuntime.InvokeAsync<IJSObjectReference>("import",
"./_content/FluentUI.Demo.Shared/Components/CodeSnippet.razor.js");
await _jsModule.InvokeVoidAsync("highlightElement", codeElement);
await _jsModule.InvokeVoidAsync("addCopyButton");
}
}
Expand Down
8 changes: 7 additions & 1 deletion examples/Demo/Shared/Components/CodeSnippet.razor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function addCopyButton() {
export function addCopyButton() {
var snippets = document.querySelectorAll('.snippet');
var numberOfSnippets = snippets.length;
for (var i = 0; i < numberOfSnippets; i++) {
Expand All @@ -19,3 +19,9 @@
}
}
}

export function highlightElement(id) {
if (hljs) {
hljs.highlightElement(id);
}
}
4 changes: 3 additions & 1 deletion examples/Demo/Shared/Components/MarkdownSection.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export function highlight() {
var numberOfPreTags = preTagList.length;
for (var i = 0; i < numberOfPreTags; i++) {
var codeTag = preTagList[i].getElementsByTagName('code');
hljs.highlightElement(codeTag[0]);
if (hljs) {
hljs.highlightElement(codeTag[0]);
}
}
}

Expand Down

0 comments on commit 0c8cfa1

Please sign in to comment.