Skip to content

Commit 78f41be

Browse files
authored
Beheer: gebruik ADR plugin voor highlighting (#363)
De functies zijn nu onderdeel van de ADR respec plugin omdat ook andere modules die kunnen gebruiken. Daarom kunnen we ze hier weglaten.
1 parent 8e22b1b commit 78f41be

1 file changed

Lines changed: 2 additions & 54 deletions

File tree

‎js/config.mjs‎

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,7 @@
1-
import { processRuleBlocks } from "https://logius-standaarden.github.io/publicatie/respec/plugins/adr.mjs";
1+
import { processRuleBlocks, initializeHighlightJSYaml, fetchLinterConfiguration, highlightLinterCode } from "https://logius-standaarden.github.io/publicatie/respec/plugins/adr.mjs";
22
import { loadRespecWithConfiguration } from "https://logius-standaarden.github.io/publicatie/respec/organisation-config.mjs";
33
import { generateMermaidFigures } from "https://logius-standaarden.github.io/publicatie/respec/plugins/mermaid.mjs";
44

5-
async function initializeHighlightJSYaml() {
6-
//this is the function you call in 'preProcess', to load the highlighter
7-
const worker = await document.respec.worker;
8-
9-
const action = "highlight-load-lang-self-registration";
10-
const langURL = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/yaml.min.js";
11-
const lang = "yaml";
12-
worker.postMessage({ action, langURL, lang });
13-
return new Promise(resolve => {
14-
worker.addEventListener("message", function listener({ data }) {
15-
const { action: responseAction, lang: responseLang } = data;
16-
if (responseAction === action && responseLang === lang) {
17-
worker.removeEventListener("message", listener);
18-
resolve();
19-
}
20-
});
21-
});
22-
}
23-
24-
const LINTER_CONFIGURATION_PATH = 'media/linter.yaml';
25-
let linterConfiguration;
26-
async function fetchLinterConfiguration() {
27-
const linterResponse = await fetch(LINTER_CONFIGURATION_PATH);
28-
linterConfiguration = await linterResponse.text();
29-
}
30-
31-
async function highlightLinterCode(config, document) {
32-
//this is the function you call in 'postProcess', to load the highlighter
33-
const worker = await document.respec.worker;
34-
35-
const action = "highlight";
36-
const code = linterConfiguration;
37-
const lang = "yaml";
38-
worker.postMessage({ action, code, languages: [lang] });
39-
return new Promise(resolve => {
40-
worker.addEventListener("message", function listener({ data }) {
41-
const { action: responseAction, language: responseLang } = data;
42-
if (responseAction === action && responseLang === lang) {
43-
worker.removeEventListener("message", listener);
44-
45-
const codeElement = document.querySelector('.linter-yaml code');
46-
codeElement.innerHTML = data.value;
47-
const linkToConfiguration = document.createElement('div');
48-
linkToConfiguration.innerHTML = `Open the above details to inspect the linter configuration. You can also <a href="${LINTER_CONFIGURATION_PATH}">open the configuration file in separate tab</a>`
49-
linkToConfiguration.style.marginTop = '1em';
50-
document.querySelector('.linter-yaml').after(linkToConfiguration);
51-
resolve();
52-
}
53-
});
54-
});
55-
}
56-
575
loadRespecWithConfiguration({
586
authors: [
597
{
@@ -113,7 +61,7 @@ loadRespecWithConfiguration({
11361
postProcess: [
11462
generateMermaidFigures,
11563
highlightLinterCode,
116-
(config, document, utils) => processRuleBlocks(config, document, utils, linterConfiguration),
64+
processRuleBlocks,
11765
],
11866

11967
localBiblio: {

0 commit comments

Comments
 (0)