|
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"; |
2 | 2 | import { loadRespecWithConfiguration } from "https://logius-standaarden.github.io/publicatie/respec/organisation-config.mjs"; |
3 | 3 | import { generateMermaidFigures } from "https://logius-standaarden.github.io/publicatie/respec/plugins/mermaid.mjs"; |
4 | 4 |
|
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 | | - |
57 | 5 | loadRespecWithConfiguration({ |
58 | 6 | authors: [ |
59 | 7 | { |
@@ -113,7 +61,7 @@ loadRespecWithConfiguration({ |
113 | 61 | postProcess: [ |
114 | 62 | generateMermaidFigures, |
115 | 63 | highlightLinterCode, |
116 | | - (config, document, utils) => processRuleBlocks(config, document, utils, linterConfiguration), |
| 64 | + processRuleBlocks, |
117 | 65 | ], |
118 | 66 |
|
119 | 67 | localBiblio: { |
|
0 commit comments