spec-up-t 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +13 -0
- package/assets/compiled/body.js +17 -11
- package/assets/compiled/head.css +6 -4
- package/assets/css/collapse-definitions.css +0 -1
- package/assets/css/create-pdf.css +4 -2
- package/assets/css/create-term-filter.css +4 -4
- package/assets/css/definition-buttons-container.css +60 -0
- package/assets/css/insert-trefs.css +7 -0
- package/assets/css/sidebar-toc.css +2 -1
- package/assets/css/terms-and-definitions.css +73 -22
- package/assets/js/add-href-to-snapshot-link.js +16 -9
- package/assets/js/addAnchorsToTerms.js +1 -1
- package/assets/js/charts.js +10 -0
- package/assets/js/collapse-definitions.js +13 -2
- package/assets/js/collapse-meta-info.js +11 -9
- package/assets/js/definition-button-container-utils.js +82 -0
- package/assets/js/edit-term-buttons.js +77 -20
- package/assets/js/github-issues.js +35 -0
- package/assets/js/github-repo-info.js +144 -0
- package/assets/js/highlight-heading-plus-sibling-nodes.test.js +18 -0
- package/assets/js/insert-trefs.js +62 -13
- package/assets/js/mermaid-diagrams.js +11 -0
- package/assets/js/terminology-section-utility-container/README.md +107 -0
- package/assets/js/terminology-section-utility-container/create-alphabet-index.js +17 -0
- package/assets/js/{create-term-filter.js → terminology-section-utility-container/create-term-filter.js} +11 -44
- package/assets/js/terminology-section-utility-container/hide-show-utility-container.js +21 -0
- package/assets/js/terminology-section-utility-container/search.js +203 -0
- package/assets/js/terminology-section-utility-container.js +203 -0
- package/assets/js/tooltips.js +283 -0
- package/config/asset-map.json +24 -16
- package/index.js +57 -390
- package/package.json +5 -2
- package/src/add-remove-xref-source.js +20 -21
- package/src/collect-external-references.js +8 -337
- package/src/collect-external-references.test.js +440 -33
- package/src/configure.js +8 -109
- package/src/create-docx.js +7 -6
- package/src/create-pdf.js +15 -14
- package/src/freeze-spec-data.js +46 -0
- package/src/git-info.test.js +76 -0
- package/src/health-check/destination-gitignore-checker.js +5 -3
- package/src/health-check/external-specs-checker.js +5 -4
- package/src/health-check/specs-configuration-checker.js +2 -1
- package/src/health-check/term-references-checker.js +5 -3
- package/src/health-check/terms-intro-checker.js +2 -1
- package/src/health-check/tref-term-checker.js +8 -7
- package/src/health-check.js +8 -7
- package/src/init.js +3 -2
- package/src/install-from-boilerplate/add-gitignore-entries.js +3 -2
- package/src/install-from-boilerplate/add-scripts-keys.js +5 -4
- package/src/install-from-boilerplate/boilerplate/README.md +1 -1
- package/src/install-from-boilerplate/boilerplate/spec/example-markup-in-markdown.md +1 -1
- package/src/install-from-boilerplate/boilerplate/spec/spec-head.md +1 -1
- package/src/install-from-boilerplate/boilerplate/specs.json +2 -1
- package/src/install-from-boilerplate/config-scripts-keys.js +3 -3
- package/src/install-from-boilerplate/copy-boilerplate.js +2 -1
- package/src/install-from-boilerplate/copy-system-files.js +4 -3
- package/src/install-from-boilerplate/custom-update.js +12 -1
- package/src/install-from-boilerplate/help.txt +1 -1
- package/src/install-from-boilerplate/menu.sh +6 -6
- package/src/json-key-validator.js +17 -11
- package/src/markdown-it/README.md +207 -0
- package/src/markdown-it/definition-lists.js +397 -0
- package/src/markdown-it/index.js +83 -0
- package/src/markdown-it/link-enhancement.js +98 -0
- package/src/markdown-it/plugins.js +118 -0
- package/src/markdown-it/table-enhancement.js +97 -0
- package/src/markdown-it/template-tag-syntax.js +152 -0
- package/src/parsers/index.js +16 -0
- package/src/parsers/spec-parser.js +152 -0
- package/src/parsers/spec-parser.test.js +109 -0
- package/src/parsers/template-tag-parser.js +277 -0
- package/src/parsers/template-tag-parser.test.js +107 -0
- package/src/pipeline/configuration/configure-starterpack.js +200 -0
- package/src/{create-external-specs-list.js → pipeline/configuration/create-external-specs-list.js} +13 -12
- package/src/{create-term-index.js → pipeline/configuration/create-term-index.js} +19 -18
- package/src/{create-versions-index.js → pipeline/configuration/create-versions-index.js} +4 -3
- package/src/{insert-term-index.js → pipeline/configuration/insert-term-index.js} +2 -2
- package/src/pipeline/configuration/prepare-spec-configuration.js +70 -0
- package/src/pipeline/parsing/apply-markdown-it-extensions.js +35 -0
- package/src/pipeline/parsing/create-markdown-parser.js +94 -0
- package/src/pipeline/parsing/create-markdown-parser.test.js +49 -0
- package/src/{html-dom-processor.js → pipeline/postprocessing/definition-list-postprocessor.js} +69 -10
- package/src/{escape-handler.js → pipeline/preprocessing/escape-processor.js} +3 -1
- package/src/{fix-markdown-files.js → pipeline/preprocessing/normalize-terminology-markdown.js} +41 -31
- package/src/pipeline/references/collect-external-references.js +307 -0
- package/src/pipeline/references/external-references-service.js +231 -0
- package/src/pipeline/references/fetch-terms-from-index.js +198 -0
- package/src/pipeline/references/match-term.js +34 -0
- package/src/{collectExternalReferences/matchTerm.test.js → pipeline/references/match-term.test.js} +8 -2
- package/src/pipeline/references/process-xtrefs-data.js +94 -0
- package/src/pipeline/references/xtref-utils.js +166 -0
- package/src/pipeline/rendering/render-spec-document.js +146 -0
- package/src/pipeline/rendering/render-utils.js +154 -0
- package/src/utils/LOGGER.md +81 -0
- package/src/utils/{doesUrlExist.js → does-url-exist.js} +4 -3
- package/src/utils/fetch.js +5 -4
- package/src/utils/file-opener.js +3 -2
- package/src/utils/git-info.js +77 -0
- package/src/utils/logger.js +74 -0
- package/src/utils/regex-patterns.js +471 -0
- package/src/utils/regex-patterns.test.js +281 -0
- package/templates/template.html +56 -21
- package/assets/js/create-alphabet-index.js +0 -60
- package/assets/js/hide-show-utility-container.js +0 -16
- package/assets/js/index.js +0 -87
- package/assets/js/search.js +0 -365
- package/src/collectExternalReferences/fetchTermsFromIndex.js +0 -284
- package/src/collectExternalReferences/matchTerm.js +0 -32
- package/src/collectExternalReferences/processXTrefsData.js +0 -108
- package/src/freeze.js +0 -90
- package/src/markdown-it-extensions.js +0 -395
- package/src/references.js +0 -114
- /package/assets/css/{bootstrap.min.css → embedded-libraries/bootstrap.min.css} +0 -0
- /package/assets/css/{prism.css → embedded-libraries/prism.css} +0 -0
- /package/assets/css/{prism.dark.css → embedded-libraries/prism.dark.css} +0 -0
- /package/assets/css/{prism.default.css → embedded-libraries/prism.default.css} +0 -0
- /package/assets/js/{bootstrap.bundle.min.js → embedded-libraries/bootstrap.bundle.min.js} +0 -0
- /package/assets/js/{chart.js → embedded-libraries/chart.js} +0 -0
- /package/assets/js/{diff.min.js → embedded-libraries/diff.min.js} +0 -0
- /package/assets/js/{font-awesome.js → embedded-libraries/font-awesome.js} +0 -0
- /package/assets/js/{mermaid.js → embedded-libraries/mermaid.js} +0 -0
- /package/assets/js/{notyf.js → embedded-libraries/notyf.js} +0 -0
- /package/assets/js/{popper.js → embedded-libraries/popper.js} +0 -0
- /package/assets/js/{prism.dark.js → embedded-libraries/prism.dark.js} +0 -0
- /package/assets/js/{prism.default.js → embedded-libraries/prism.default.js} +0 -0
- /package/assets/js/{prism.js → embedded-libraries/prism.js} +0 -0
- /package/assets/js/{tippy.js → embedded-libraries/tippy.js} +0 -0
- /package/src/{escape-mechanism.js → pipeline/preprocessing/escape-placeholder-utils.js} +0 -0
- /package/src/utils/{isLineWithDefinition.js → is-line-with-definition.js} +0 -0
package/src/init.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const Logger = require('./utils/logger');
|
|
3
4
|
const outputDir = path.join(process.cwd(), '.cache');
|
|
4
5
|
const initFlagPath = path.join(outputDir, 'init.flag');
|
|
5
6
|
|
|
@@ -20,9 +21,9 @@ async function initialize() {
|
|
|
20
21
|
// Create the init flag file
|
|
21
22
|
await fs.writeFile(initFlagPath, 'Initialization completed.');
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
Logger.success('Initialization complete.');
|
|
24
25
|
} catch (error) {
|
|
25
|
-
|
|
26
|
+
Logger.error(`Initialization failed: ${error.message}`);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs').promises;
|
|
2
|
+
const Logger = require('../utils/logger');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Reads the content of a file or returns an empty string if the file does not exist.
|
|
@@ -42,9 +43,9 @@ async function updateGitignore(gitignorePath, filesToAdd) {
|
|
|
42
43
|
// Write the updated content back to the .gitignore file
|
|
43
44
|
await fs.writeFile(gitignorePath, updatedGitignoreContent, 'utf8');
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
Logger.success('Updated .gitignore file');
|
|
46
47
|
} catch (error) {
|
|
47
|
-
|
|
48
|
+
Logger.error('Error updating .gitignore:', error.message);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const Logger = require('../utils/logger');
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Adds scripts to the package.json file.
|
|
@@ -15,7 +16,7 @@ function addScriptsKeys(scriptKeys, overwriteKeys = {}) {
|
|
|
15
16
|
// Read the package.json file
|
|
16
17
|
fs.readFile(packageJsonPath, 'utf8', (err, data) => {
|
|
17
18
|
if (err) {
|
|
18
|
-
|
|
19
|
+
Logger.error('Error reading package.json:', err);
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -38,13 +39,13 @@ function addScriptsKeys(scriptKeys, overwriteKeys = {}) {
|
|
|
38
39
|
// Write the updated package.json back to disk
|
|
39
40
|
fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8', (err) => {
|
|
40
41
|
if (err) {
|
|
41
|
-
|
|
42
|
+
Logger.error('Error writing package.json:', err);
|
|
42
43
|
} else {
|
|
43
|
-
|
|
44
|
+
Logger.success('Scripts added to package.json successfully!');
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
} catch (parseError) {
|
|
47
|
-
|
|
48
|
+
Logger.error('Error parsing package.json:', parseError);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
## Intro
|
|
4
4
|
|
|
5
|
-
This is a default Spec-Up-T installation. Find information on the [Spec-Up-T documentation website](https://
|
|
5
|
+
This is a default Spec-Up-T installation. Find information on the [Spec-Up-T documentation website](https://trustoverip.github.io/spec-up-t-website/).
|
|
6
6
|
|
|
7
7
|
This is a demo site for Spec-Up-T. The subject matter – gardening and related terms – is used purely as an example to demonstrate how the system works. You can replace these demo terms and definitions with your own content to suit your documentation needs.
|
|
@@ -2,11 +2,11 @@ const configScriptsKeys = {
|
|
|
2
2
|
"edit": "node -e \"require('spec-up-t')()\"",
|
|
3
3
|
"render": "node --no-warnings -e \"require('spec-up-t/index.js')({ nowatch: true })\"",
|
|
4
4
|
"dev": "node -e \"require('spec-up-t')({ dev: true })\"",
|
|
5
|
-
"collectExternalReferences": "node --no-warnings -e \"require('spec-up-t/src/collect-external-references.js').collectExternalReferences()\"",
|
|
5
|
+
"collectExternalReferences": "node --no-warnings -e \"require('spec-up-t/src/pipeline/references/collect-external-references.js').collectExternalReferences()\"",
|
|
6
6
|
"topdf": "node -e \"require('spec-up-t/src/create-pdf.js')\"",
|
|
7
7
|
"todocx": "node -e \"require('spec-up-t/src/create-docx.js')\"",
|
|
8
|
-
"freeze": "node -e \"require('spec-up-t/src/freeze.js')\"",
|
|
9
|
-
"references": "node -e \"require('spec-up-t/src/references.js')\"",
|
|
8
|
+
"freeze": "node -e \"require('spec-up-t/src/freeze-spec-data.js')\"",
|
|
9
|
+
"references": "node -e \"require('spec-up-t/src/pipeline/references/external-references-service.js')\"",
|
|
10
10
|
"help": "cat ./node_modules/spec-up-t/src/install-from-boilerplate/help.txt",
|
|
11
11
|
"menu": "bash ./node_modules/spec-up-t/src/install-from-boilerplate/menu.sh",
|
|
12
12
|
"addremovexrefsource": "node --no-warnings -e \"require('spec-up-t/src/add-remove-xref-source.js')\"",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const Logger = require('../utils/logger');
|
|
3
4
|
|
|
4
5
|
function copyBoilerplate() {
|
|
5
6
|
const sourceDir = path.join(__dirname, './', 'boilerplate');
|
|
@@ -16,7 +17,7 @@ function copyBoilerplate() {
|
|
|
16
17
|
const gitignoreDestPath = path.join(__dirname, '../../../../', '.gitignore');
|
|
17
18
|
fs.renameSync(gitignorePath, gitignoreDestPath);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Logger.success('Copied spec-up-t-boilerplate to current directory');
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
module.exports = copyBoilerplate;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { systemFiles } = require('./config-system-files.js');
|
|
4
|
+
const Logger = require('../utils/logger');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Copies system files from the boilerplate directory to the root of the project.
|
|
@@ -18,13 +19,13 @@ function copySystemFiles() {
|
|
|
18
19
|
|
|
19
20
|
try {
|
|
20
21
|
fs.cpSync(srcPath, destPath, { recursive: true });
|
|
21
|
-
|
|
22
|
+
Logger.success(`Copied ${item} to ${destPath}`);
|
|
22
23
|
} catch (error) {
|
|
23
|
-
|
|
24
|
+
Logger.error(`Failed to copy ${item} to ${destPath}:`, error);
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
Logger.success('Copied system files to current directory');
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
module.exports = copySystemFiles;
|
|
@@ -10,4 +10,15 @@ addScriptsKeys(configScriptsKeys, configOverwriteScriptsKeys);
|
|
|
10
10
|
copySystemFiles();
|
|
11
11
|
updateGitignore(gitIgnoreEntries.gitignorePath, gitIgnoreEntries.filesToAdd);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const Logger = require('../utils/logger');
|
|
14
|
+
|
|
15
|
+
// We can use this file to do any custom updates during post-install.
|
|
16
|
+
const customUpdate = () => {
|
|
17
|
+
// Custom logic here
|
|
18
|
+
// ...
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Call custom update
|
|
22
|
+
customUpdate();
|
|
23
|
+
|
|
24
|
+
Logger.success("Custom update done");
|
|
@@ -21,7 +21,7 @@ function handle_choice() {
|
|
|
21
21
|
echo " ${options[index]}"
|
|
22
22
|
echo -e " ************************************\n\n"
|
|
23
23
|
show_progress
|
|
24
|
-
${options[index + 1]}
|
|
24
|
+
"${options[index + 1]}"
|
|
25
25
|
else
|
|
26
26
|
clear
|
|
27
27
|
echo -e "\n\n ************************************"
|
|
@@ -69,7 +69,7 @@ function prompt_input() {
|
|
|
69
69
|
|
|
70
70
|
function do_add_content() {
|
|
71
71
|
clear
|
|
72
|
-
echo -e "\n\n\n ********************\n\n\n You can start adding your content to the markdown files in the "spec" directory.\n\n You can do this by editing local files in an editor or by going to your repository on GitHub.\n\n More info: https://
|
|
72
|
+
echo -e "\n\n\n ********************\n\n\n You can start adding your content to the markdown files in the "spec" directory.\n\n You can do this by editing local files in an editor or by going to your repository on GitHub.\n\n More info: https://trustoverip.github.io/spec-up-t-website/docs/various-roles/content-authors-guide/introduction\n\n\n ********************"
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function do_render() { clear; npm run render; }
|
|
@@ -83,14 +83,14 @@ function do_freeze() { clear; npm run freeze; }
|
|
|
83
83
|
|
|
84
84
|
function do_help() {
|
|
85
85
|
clear
|
|
86
|
-
echo -e "\n\n\n You will be redirected to the documentation website\n\n (https://
|
|
86
|
+
echo -e "\n\n\n You will be redirected to the documentation website\n\n (https://trustoverip.github.io/spec-up-t-website/)."
|
|
87
87
|
sleep 2
|
|
88
88
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
89
|
-
open "https://
|
|
89
|
+
open "https://trustoverip.github.io/spec-up-t-website/"
|
|
90
90
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
91
|
-
xdg-open "https://
|
|
91
|
+
xdg-open "https://trustoverip.github.io/spec-up-t-website/"
|
|
92
92
|
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
|
|
93
|
-
start "https://
|
|
93
|
+
start "https://trustoverip.github.io/spec-up-t-website/"
|
|
94
94
|
else
|
|
95
95
|
echo "Unsupported OS."
|
|
96
96
|
fi
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
const fs = require('fs');
|
|
12
12
|
const readlineSync = require('readline-sync');
|
|
13
|
+
const Logger = require('./utils/logger');
|
|
13
14
|
|
|
14
15
|
let errorFound = false;
|
|
15
16
|
|
|
@@ -25,6 +26,11 @@ function loadData() {
|
|
|
25
26
|
|
|
26
27
|
// This function recursively checks if the required keys are present in the object
|
|
27
28
|
function checkKeysSync(object, expectedKeys, parentKey = '') {
|
|
29
|
+
// Guard against undefined or non-iterable expected key definitions so the validator fails gracefully instead of throwing.
|
|
30
|
+
if (!Array.isArray(expectedKeys)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
for (let key of expectedKeys) {
|
|
29
35
|
if (Array.isArray(object)) {
|
|
30
36
|
// If the object is an array, check each item within the array
|
|
@@ -34,7 +40,7 @@ function checkKeysSync(object, expectedKeys, parentKey = '') {
|
|
|
34
40
|
} else if (typeof object === 'object') {
|
|
35
41
|
// If the key is missing from the object, log an error
|
|
36
42
|
if (!(key in object)) {
|
|
37
|
-
|
|
43
|
+
Logger.error(`Error: Missing key '${key}'\n We cannot guarantee that Spec-Up-T will work properly.\n Here is an example specs.json file:\n https://github.com/trustoverip/spec-up-t-starter-pack/blob/main/spec-up-t-boilerplate/specs.json`);
|
|
38
44
|
errorFound = true;
|
|
39
45
|
pauseForEnterSync(); // Pause synchronously to allow user to acknowledge the error
|
|
40
46
|
}
|
|
@@ -61,7 +67,7 @@ function runJsonKeyValidatorSync() {
|
|
|
61
67
|
"logo",
|
|
62
68
|
"logo_link",
|
|
63
69
|
"source",
|
|
64
|
-
"external_specs"
|
|
70
|
+
// "external_specs"
|
|
65
71
|
// "assets" // Commented out: We no longer check for 'assets' in the specs object
|
|
66
72
|
],
|
|
67
73
|
source: [
|
|
@@ -69,12 +75,12 @@ function runJsonKeyValidatorSync() {
|
|
|
69
75
|
"account",
|
|
70
76
|
"repo"
|
|
71
77
|
],
|
|
72
|
-
external_specs: [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
],
|
|
78
|
+
// external_specs: [
|
|
79
|
+
// "gh_page",
|
|
80
|
+
// "external_spec",
|
|
81
|
+
// "url",
|
|
82
|
+
// "terms_dir"
|
|
83
|
+
// ],
|
|
78
84
|
// Removed the 'assets' block entirely, as it's no longer part of the required keys:
|
|
79
85
|
// assets: [
|
|
80
86
|
// "path",
|
|
@@ -85,7 +91,7 @@ function runJsonKeyValidatorSync() {
|
|
|
85
91
|
|
|
86
92
|
// Iterate over each spec entry in the specs array from the JSON file
|
|
87
93
|
for (let [index, spec] of data.specs.entries()) {
|
|
88
|
-
|
|
94
|
+
Logger.info(`Checking spec #${index + 1}`);
|
|
89
95
|
|
|
90
96
|
// Check for keys defined in expectedKeys.specs
|
|
91
97
|
checkKeysSync(spec, expectedKeys.specs, `specs[${index}]`);
|
|
@@ -96,7 +102,7 @@ function runJsonKeyValidatorSync() {
|
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
// Check for keys inside the 'external_specs' array, if present
|
|
99
|
-
if (spec.external_specs) {
|
|
105
|
+
if (spec.external_specs && Array.isArray(expectedKeys.external_specs)) {
|
|
100
106
|
checkKeysSync(spec.external_specs, expectedKeys.external_specs, `specs[${index}].external_specs`);
|
|
101
107
|
}
|
|
102
108
|
|
|
@@ -108,7 +114,7 @@ function runJsonKeyValidatorSync() {
|
|
|
108
114
|
|
|
109
115
|
// If no errors were found, print a success message
|
|
110
116
|
if (!errorFound) {
|
|
111
|
-
|
|
117
|
+
Logger.success('All keys are present. No errors found. Continuing…');
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
120
|
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Markdown-it Extensions
|
|
2
|
+
|
|
3
|
+
This directory contains the refactored markdown-it extensions used by the spec-up-t system. The extensions have been broken down into focused, well-documented modules to improve maintainability and understanding.
|
|
4
|
+
|
|
5
|
+
## Module Overview
|
|
6
|
+
|
|
7
|
+
### Core Philosophy
|
|
8
|
+
|
|
9
|
+
The markdown-it library uses a token-based rendering system where:
|
|
10
|
+
|
|
11
|
+
- **Tokens** represent different parts of the markdown (paragraphs, headers, tables, etc.)
|
|
12
|
+
- **Renderer rules** are functions that convert tokens to HTML
|
|
13
|
+
- **Inline rules** process inline elements during parsing
|
|
14
|
+
- **Plugins** extend the parser with custom functionality
|
|
15
|
+
|
|
16
|
+
Our extensions override default renderer rules and add custom inline parsing rules to implement spec-up-specific functionality.
|
|
17
|
+
|
|
18
|
+
## Modules
|
|
19
|
+
|
|
20
|
+
### 1. `table-enhancement.js`
|
|
21
|
+
|
|
22
|
+
**Purpose**: Enhances table rendering with Bootstrap styling and responsive wrappers.
|
|
23
|
+
|
|
24
|
+
**Features**:
|
|
25
|
+
|
|
26
|
+
- Adds Bootstrap CSS classes (`table`, `table-striped`, `table-bordered`, `table-hover`)
|
|
27
|
+
- Wraps tables in responsive containers (`table-responsive-md`)
|
|
28
|
+
- Preserves existing classes while adding new ones
|
|
29
|
+
|
|
30
|
+
**How it works**: Overrides `table_open` and `table_close` renderer rules.
|
|
31
|
+
|
|
32
|
+
### 2. `template-tag-syntax.js`
|
|
33
|
+
|
|
34
|
+
**Purpose**: Processes custom template-tag syntax like `[[def:term]]`, `[[tref:spec,term]]`, etc.
|
|
35
|
+
|
|
36
|
+
**Features**:
|
|
37
|
+
|
|
38
|
+
- Parses `[[type:arg1,arg2]]` syntax during markdown processing
|
|
39
|
+
- Creates template tokens for later rendering
|
|
40
|
+
- Supports extensible template-tag handlers
|
|
41
|
+
- Integrates with the escape mechanism
|
|
42
|
+
|
|
43
|
+
**How it works**:
|
|
44
|
+
|
|
45
|
+
- Adds an inline ruler (`templates_ruler`) to detect and parse template-tag syntax
|
|
46
|
+
- Creates template tokens with parsed information
|
|
47
|
+
- Provides a renderer rule to convert template tokens to HTML
|
|
48
|
+
|
|
49
|
+
### 3. `link-enhancement.js`
|
|
50
|
+
|
|
51
|
+
**Purpose**: Adds path-based attributes to links for CSS styling and JavaScript targeting.
|
|
52
|
+
|
|
53
|
+
**Features**:
|
|
54
|
+
|
|
55
|
+
- Extracts domain and path segments from URLs
|
|
56
|
+
- Adds `path-0`, `path-1`, etc. attributes to anchor tags
|
|
57
|
+
- Special handling for auto-detected links (linkify)
|
|
58
|
+
|
|
59
|
+
**How it works**: Overrides `link_open` and `link_close` renderer rules.
|
|
60
|
+
|
|
61
|
+
### 4. `definition-lists.js`
|
|
62
|
+
|
|
63
|
+
**Purpose**: Advanced processing of definition lists for terminology and reference management.
|
|
64
|
+
|
|
65
|
+
**Features**:
|
|
66
|
+
|
|
67
|
+
- **Smart Classification**: Distinguishes between terminology lists and reference lists
|
|
68
|
+
- **Term Type Detection**: Identifies local terms (`[[def:term]]`) vs external terms (`[[tref:spec,term]]`)
|
|
69
|
+
- **Quality Control**: Removes empty `<dt>` elements that cause rendering issues
|
|
70
|
+
- **Section-Aware**: Only applies terminology styling after the terminology section marker
|
|
71
|
+
|
|
72
|
+
**How it works**:
|
|
73
|
+
|
|
74
|
+
- Overrides `dl_open`, `dt_open`, and `dt_close` renderer rules
|
|
75
|
+
- Uses helper functions to analyze token structure and content
|
|
76
|
+
- Applies CSS classes based on term types and context
|
|
77
|
+
|
|
78
|
+
### 5. `index.js`
|
|
79
|
+
|
|
80
|
+
**Purpose**: Main orchestrator that applies all enhancements in the correct order.
|
|
81
|
+
|
|
82
|
+
**Features**:
|
|
83
|
+
|
|
84
|
+
- Single entry point for all markdown-it extensions
|
|
85
|
+
- Maintains dependency order between modules
|
|
86
|
+
- Provides both unified and individual module access
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
### Basic Usage
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
const MarkdownIt = require('markdown-it');
|
|
94
|
+
const applyMarkdownItExtensions = require('./markdown-it');
|
|
95
|
+
|
|
96
|
+
const md = new MarkdownIt();
|
|
97
|
+
const templates = [
|
|
98
|
+
{
|
|
99
|
+
filter: type => type === 'def',
|
|
100
|
+
render: (token, type, term) => `<span id="term:${term}">${term}</span>`
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
applyMarkdownItExtensions(md, templates);
|
|
105
|
+
const html = md.render('[[def:example-term]]');
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Individual Module Usage
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
const applyTableEnhancements = require('./markdown-it/table-enhancement');
|
|
112
|
+
const applyTemplateTagSyntax = require('./markdown-it/template-tag-syntax');
|
|
113
|
+
|
|
114
|
+
// Apply only table enhancements
|
|
115
|
+
applyTableEnhancements(md);
|
|
116
|
+
|
|
117
|
+
// Apply only template-tag syntax with custom handlers
|
|
118
|
+
applyTemplateTagSyntax(md, templates);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Template System
|
|
122
|
+
|
|
123
|
+
The template-tag system processes custom syntax like `[[type:args]]` in markdown. Template-tags are defined as objects with:
|
|
124
|
+
|
|
125
|
+
- `filter(type)`: Function that returns true if this handler processes the given type
|
|
126
|
+
- `parse(token, type, ...args)`: Optional preprocessing function called during parsing
|
|
127
|
+
- `render(token, type, ...args)`: Function that returns HTML string for rendering
|
|
128
|
+
|
|
129
|
+
### Example Template-Tag Handler
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
{
|
|
133
|
+
filter: type => type.match(/^def$/),
|
|
134
|
+
parse: (token, type, term, alias) => {
|
|
135
|
+
// Preprocessing during markdown parsing
|
|
136
|
+
definitions.push([term, alias]);
|
|
137
|
+
return `<span id="term:${term.replace(/\s+/g, '-').toLowerCase()}">${term}</span>`;
|
|
138
|
+
},
|
|
139
|
+
render: (token, type, ...args) => {
|
|
140
|
+
// Final rendering (if parse didn't handle it)
|
|
141
|
+
return token.content;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Definition List Processing
|
|
147
|
+
|
|
148
|
+
The definition list module implements sophisticated logic for handling terminology:
|
|
149
|
+
|
|
150
|
+
### List Classification
|
|
151
|
+
|
|
152
|
+
- **Terminology Lists**: Get `terms-and-definitions-list` class
|
|
153
|
+
- **Reference Lists**: Keep existing classes (e.g., `reference-list`)
|
|
154
|
+
- **Section-Aware**: Only processes lists after `terminology-section-start` marker
|
|
155
|
+
|
|
156
|
+
### Term Classification
|
|
157
|
+
|
|
158
|
+
- **Local Terms** (`[[def:term]]`): Get `term-local` class
|
|
159
|
+
- **External Terms** (`[[tref:spec,term]]`): Get `term-external` class
|
|
160
|
+
- **Regular Terms**: No special class
|
|
161
|
+
|
|
162
|
+
### Quality Control
|
|
163
|
+
|
|
164
|
+
- **Empty Elements**: Removes `<dt>` elements with no content
|
|
165
|
+
- **Spec References**: Avoids styling bibliographic references as terminology
|
|
166
|
+
|
|
167
|
+
## Development Guidelines
|
|
168
|
+
|
|
169
|
+
### Adding New Modules
|
|
170
|
+
|
|
171
|
+
1. Create a focused module in this directory
|
|
172
|
+
2. Follow the existing naming pattern (`feature-name.js`)
|
|
173
|
+
3. Export a single function that takes a markdown-it instance
|
|
174
|
+
4. Add comprehensive documentation with examples
|
|
175
|
+
5. Update `index.js` to include the new module
|
|
176
|
+
|
|
177
|
+
### Code Quality
|
|
178
|
+
|
|
179
|
+
- Keep cognitive complexity below 15
|
|
180
|
+
- Add extensive comments for markdown-it concepts
|
|
181
|
+
- Use descriptive function and variable names
|
|
182
|
+
- Extract helper functions for complex logic
|
|
183
|
+
- Write tests for new functionality
|
|
184
|
+
|
|
185
|
+
### SonarQube Compliance
|
|
186
|
+
|
|
187
|
+
All modules must pass SonarQube analysis without issues. The refactoring specifically addresses:
|
|
188
|
+
|
|
189
|
+
- Reduced cognitive complexity through modularization
|
|
190
|
+
- Better code organization and separation of concerns
|
|
191
|
+
- Comprehensive documentation for maintainability
|
|
192
|
+
|
|
193
|
+
## Backward Compatibility
|
|
194
|
+
|
|
195
|
+
The main `markdown-it-extensions.js` file maintains complete backward compatibility by delegating to the new modular system. Existing code can continue to use the original interface without changes.
|
|
196
|
+
|
|
197
|
+
## Testing
|
|
198
|
+
|
|
199
|
+
Run the full test suite to ensure all functionality works correctly:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npm test
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Individual modules can be tested by importing and using them directly in test files.
|
|
206
|
+
|
|
207
|
+
Please remember to run `gulp compile` after making changes to client-side assets, and test on a separate test machine before deployment.
|