spec-up-t 0.11.21 → 0.11.23
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/assets/compiled/body.js +1 -1
- package/index.js +4 -0
- package/package.json +1 -1
- package/src/create-term-relations.js +116 -0
package/assets/compiled/body.js
CHANGED
|
@@ -63,6 +63,6 @@ function backToTop(){const n=document.createElement("a");n.id="back-to-top-a1znc
|
|
|
63
63
|
*/
|
|
64
64
|
function fetchCommitHashes(){document.querySelectorAll("[data-local-href]").forEach(e=>{const t=e.getAttribute("data-local-href").split(":");allXrefs.xrefs.forEach(r=>{if(r.externalSpec===t[1]&&r.term.toLowerCase()===t[2].toLowerCase()){const t=r.commitHash&&r.commitHash[0]?r.commitHash[0].substring(0,7):"No hash",o=document.createElement("a");o.href="https://github.com/"+r.owner+"/"+r.repo+"/compare/"+r.commitHash+"..main/"+r.terms_dir+"/"+r.term.replace(/ /g," - ").toLowerCase()+".md",o.target="_blank",o.classList.add("diff","xref-info-links","btn"),o.innerHTML="Diff",e.parentNode.insertBefore(o,e.nextSibling);const n=document.createElement("a");n.href="https://github.com/"+r.owner+"/"+r.repo+"/blob/main/"+r.terms_dir+"/"+r.term.replace(/ /g,"-").toLowerCase()+".md",n.target="_blank",n.classList.add("latest-version","xref-info-links","btn"),n.innerHTML="Latest",o.parentNode.insertBefore(n,e.nextSibling);const a=document.createElement("a");a.href="https://github.com/"+r.owner+"/"+r.repo+"/blob/"+r.commitHash+"/"+r.terms_dir+"/"+r.term.replace(/ /g,"-").toLowerCase()+".md",a.target="_blank",a.classList.add("exact-commit-hash","xref-info-links","btn"),a.innerHTML=t,n.parentNode.insertBefore(a,e.nextSibling)}})})}document.addEventListener("DOMContentLoaded",(function(){fetchCommitHashes()}));
|
|
65
65
|
function addAnchorsToTerms(){document.querySelectorAll('dt:has(> span[id^="term:"])').forEach(e=>{const t=function(e){let t=e;for(;t.querySelector('span[id^="term:"]');)t=t.querySelector('span[id^="term:"]');return t}(e),r=t.getAttribute("id"),n=document.createElement("a");n.setAttribute("href","#"+r),n.setAttribute("class","toc-anchor"),n.innerHTML="§ ",t.parentNode.insertBefore(n,t)})}document.addEventListener("DOMContentLoaded",(function(){addAnchorsToTerms()}));
|
|
66
|
-
function copyAnchorToCliboard(){document.addEventListener("click",(function(o){if(o.target.classList.contains("toc-anchor")){
|
|
66
|
+
function copyAnchorToCliboard(){document.addEventListener("click",(function(o){if(o.target.classList.contains("toc-anchor")){const c=o.target.href;navigator.clipboard.writeText(c).then(()=>{console.log("Anchor copied to clipboard"),notyf.success("Anchor copied to clipboard: "+c)}).catch(o=>{console.error("Failed to copy anchor to clipboard",o)})}}))}document.addEventListener("DOMContentLoaded",(function(){copyAnchorToCliboard()}));
|
|
67
67
|
var Notyf=function(){"use strict";var t,i=function(){return(i=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++)for(var o in i=arguments[e])Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o]);return t}).apply(this,arguments)},e=(n.prototype.on=function(t,i){var e=this.listeners[t]||[];this.listeners[t]=e.concat([i])},n.prototype.triggerEvent=function(t,i){var e=this;(this.listeners[t]||[]).forEach((function(t){return t({target:e,event:i})}))},n);function n(t){this.options=t,this.listeners={}}(s=t=t||{})[s.Add=0]="Add",s[s.Remove=1]="Remove";var o,s,a=(r.prototype.push=function(i){this.notifications.push(i),this.updateFn(i,t.Add,this.notifications)},r.prototype.splice=function(i,e){return e=this.notifications.splice(i,e)[0],this.updateFn(e,t.Remove,this.notifications),e},r.prototype.indexOf=function(t){return this.notifications.indexOf(t)},r.prototype.onUpdate=function(t){this.updateFn=t},r);function r(){this.notifications=[]}(s=o=o||{}).Dismiss="dismiss";var c={types:[{type:"success",className:"notyf__toast--success",backgroundColor:"#3dc763",icon:{className:"notyf__icon--success",tagName:"i"}},{type:"error",className:"notyf__toast--error",backgroundColor:"#ed3d3d",icon:{className:"notyf__icon--error",tagName:"i"}}],duration:2e3,ripple:!0,position:{x:"right",y:"bottom"},dismissible:!(s.Click="click")},p=(d.prototype.on=function(t,e){var n;this.events=i(i({},this.events),((n={})[t]=e,n))},d.prototype.update=function(i,e){e===t.Add?this.addNotification(i):e===t.Remove&&this.removeNotification(i)},d.prototype.removeNotification=function(t){var i,e,n=this;(t=this._popRenderedNotification(t))&&((e=t.node).classList.add("notyf__toast--disappear"),e.addEventListener(this.animationEndEventName,i=function(t){t.target===e&&(e.removeEventListener(n.animationEndEventName,i),n.container.removeChild(e))}))},d.prototype.addNotification=function(t){var i=this._renderNotification(t);this.notifications.push({notification:t,node:i}),this._announce(t.options.message||"Notification")},d.prototype._renderNotification=function(t){var i=this._buildNotificationCard(t),e=t.options.className;return e&&(t=i.classList).add.apply(t,e.split(" ")),this.container.appendChild(i),i},d.prototype._popRenderedNotification=function(t){for(var i=-1,e=0;e<this.notifications.length&&i<0;e++)this.notifications[e].notification===t&&(i=e);if(-1!==i)return this.notifications.splice(i,1)[0]},d.prototype.getXPosition=function(t){return(null===(t=null==t?void 0:t.position)||void 0===t?void 0:t.x)||"right"},d.prototype.getYPosition=function(t){return(null===(t=null==t?void 0:t.position)||void 0===t?void 0:t.y)||"bottom"},d.prototype.adjustContainerAlignment=function(t){var i=this.X_POSITION_FLEX_MAP[this.getXPosition(t)],e=this.Y_POSITION_FLEX_MAP[this.getYPosition(t)];(t=this.container.style).setProperty("justify-content",e),t.setProperty("align-items",i)},d.prototype._buildNotificationCard=function(t){var i=this,e=t.options,n=e.icon;this.adjustContainerAlignment(e);var s=this._createHTMLElement({tagName:"div",className:"notyf__toast"}),a=this._createHTMLElement({tagName:"div",className:"notyf__ripple"}),r=this._createHTMLElement({tagName:"div",className:"notyf__wrapper"}),c=this._createHTMLElement({tagName:"div",className:"notyf__message"});c.innerHTML=e.message||"";var p,d,l,u,f=e.background||e.backgroundColor;return n&&(p=this._createHTMLElement({tagName:"div",className:"notyf__icon"}),("string"==typeof n||n instanceof String)&&(p.innerHTML=new String(n).valueOf()),"object"==typeof n&&(d=n.tagName,l=n.className,u=n.text,n=void 0===(n=n.color)?f:n,u=this._createHTMLElement({tagName:void 0===d?"i":d,className:l,text:u}),n&&(u.style.color=n),p.appendChild(u)),r.appendChild(p)),r.appendChild(c),s.appendChild(r),f&&(e.ripple?(a.style.background=f,s.appendChild(a)):s.style.background=f),e.dismissible&&(a=this._createHTMLElement({tagName:"div",className:"notyf__dismiss"}),f=this._createHTMLElement({tagName:"button",className:"notyf__dismiss-btn"}),a.appendChild(f),r.appendChild(a),s.classList.add("notyf__toast--dismissible"),f.addEventListener("click",(function(e){var n,s;null!==(s=(n=i.events)[o.Dismiss])&&void 0!==s&&s.call(n,{target:t,event:e}),e.stopPropagation()}))),s.addEventListener("click",(function(e){var n,s;return null===(s=(n=i.events)[o.Click])||void 0===s?void 0:s.call(n,{target:t,event:e})})),e="top"===this.getYPosition(e)?"upper":"lower",s.classList.add("notyf__toast--"+e),s},d.prototype._createHTMLElement=function(t){var i=t.tagName,e=t.className;t=t.text,i=document.createElement(i);return e&&(i.className=e),i.textContent=t||null,i},d.prototype._createA11yContainer=function(){var t=this._createHTMLElement({tagName:"div",className:"notyf-announcer"});t.setAttribute("aria-atomic","true"),t.setAttribute("aria-live","polite"),t.style.border="0",t.style.clip="rect(0 0 0 0)",t.style.height="1px",t.style.margin="-1px",t.style.overflow="hidden",t.style.padding="0",t.style.position="absolute",t.style.width="1px",t.style.outline="0",document.body.appendChild(t),this.a11yContainer=t},d.prototype._announce=function(t){var i=this;this.a11yContainer.textContent="",setTimeout((function(){i.a11yContainer.textContent=t}),100)},d.prototype._getAnimationEndEventName=function(){var t,i=document.createElement("_fake"),e={MozTransition:"animationend",OTransition:"oAnimationEnd",WebkitTransition:"webkitAnimationEnd",transition:"animationend"};for(t in e)if(void 0!==i.style[t])return e[t];return"animationend"},d);function d(){this.notifications=[],this.events={},this.X_POSITION_FLEX_MAP={left:"flex-start",center:"center",right:"flex-end"},this.Y_POSITION_FLEX_MAP={top:"flex-start",center:"center",bottom:"flex-end"};var t=document.createDocumentFragment(),i=this._createHTMLElement({tagName:"div",className:"notyf"});t.appendChild(i),document.body.appendChild(t),this.container=i,this.animationEndEventName=this._getAnimationEndEventName(),this._createA11yContainer()}function l(t){var e=this;this.dismiss=this._removeNotification,this.notifications=new a,this.view=new p;var n=this.registerTypes(t);this.options=i(i({},c),t),this.options.types=n,this.notifications.onUpdate((function(t,i){return e.view.update(t,i)})),this.view.on(o.Dismiss,(function(t){var i=t.target;t=t.event;e._removeNotification(i),i.triggerEvent(o.Dismiss,t)})),this.view.on(o.Click,(function(t){var i=t.target;t=t.event;return i.triggerEvent(o.Click,t)}))}return l.prototype.error=function(t){return t=this.normalizeOptions("error",t),this.open(t)},l.prototype.success=function(t){return t=this.normalizeOptions("success",t),this.open(t)},l.prototype.open=function(t){var n=this.options.types.find((function(i){return i.type===t.type}))||{};n=i(i({},n),t);return this.assignProps(["ripple","position","dismissible"],n),n=new e(n),this._pushNotification(n),n},l.prototype.dismissAll=function(){for(;this.notifications.splice(0,1););},l.prototype.assignProps=function(t,i){var e=this;t.forEach((function(t){i[t]=(null==i[t]?e.options:i)[t]}))},l.prototype._pushNotification=function(t){var i=this;this.notifications.push(t);var e=(void 0!==t.options.duration?t:this).options.duration;e&&setTimeout((function(){return i._removeNotification(t)}),e)},l.prototype._removeNotification=function(t){-1!==(t=this.notifications.indexOf(t))&&this.notifications.splice(t,1)},l.prototype.normalizeOptions=function(t,e){return t={type:t},"string"==typeof e?t.message=e:"object"==typeof e&&(t=i(i({},t),e)),t},l.prototype.registerTypes=function(t){var e=(t&&t.types||[]).slice();return c.types.map((function(t){var n=-1;e.forEach((function(i,e){i.type===t.type&&(n=e)}));var o=-1!==n?e.splice(n,1)[0]:{};return i(i({},t),o)})).concat(e)},l}(),notyf=new Notyf({types:[{type:"success",background:"#1D6DAE"}]});
|
|
68
68
|
!function(){var e=window.markdownit();delegateEvent("pointerup","[panel-toggle]",(e,t)=>{slidepanels.toggle(t.getAttribute("panel-toggle"))},{passive:!0}),window.addEventListener("hashchange",e=>slidepanels.close());let t=specConfig.source;t&&"github"===t.host&&fetch(`https://api.github.com/repos/${t.account+"/"+t.repo}/issues`).then(e=>e.json()).then(t=>{let n=t.length;document.querySelectorAll("[issue-count]").forEach(e=>{e.setAttribute("issue-count",n)}),repo_issue_list.innerHTML=t.map(t=>`<li class="repo-issue">\n <detail-box>\n <section>${e.render(t.body||"")}</section>\n <header class="repo-issue-title">\n <span class="repo-issue-number">${t.number}</span>\n <span class="repo-issue-link">\n <a href="${t.html_url}" target="_blank">${t.title}</a>\n </span>\n <span detail-box-toggle></span>\n </header>\n </detail-box>\n </li>`).join(""),Prism.highlightAllUnder(repo_issue_list)}),mermaid.initialize({startOnLoad:!0,theme:"neutral"}),document.querySelectorAll(".chartjs").forEach(e=>{new Chart(e,JSON.parse(e.textContent))});let n=new WeakMap;delegateEvent("pointerover",".term-reference, .spec-reference",(e,t)=>{const s=t.getAttribute("data-local-href")||t.getAttribute("href")||"";let l=document.getElementById(s.replace("#",""));if(!l||n.has(t))return;let r=l.closest("dt, td:first-child");if(!r)return;let i={allowHTML:!0,inlinePositioning:!0};switch(r.tagName){case"DT":i.content=r.nextElementSibling.textContent;break;case"TD":let e=r.closest("table"),t=Array.from(r.closest("tr").children);if(t.shift(),e){let n=Array.from(e.querySelectorAll("thead th"));n.shift(),n.length&&(i.content=`\n <header>${r.textContent}</header>\n <table>\n ${n.map((e,n)=>`<tr><td>${e.textContent}:</td><td>${t[n]?t[n].textContent:""}</td></tr>`).join("")}\n </table>`)}}i.content&&n.set(t,tippy(t,i))},{passive:!0})}();
|
package/index.js
CHANGED
|
@@ -6,6 +6,10 @@ module.exports = function(options = {}) {
|
|
|
6
6
|
validateReferences,
|
|
7
7
|
findExternalSpecByKey
|
|
8
8
|
} = require('./references.js');
|
|
9
|
+
|
|
10
|
+
const { createTermRelations } = require('./src/create-term-relations.js');
|
|
11
|
+
createTermRelations();
|
|
12
|
+
|
|
9
13
|
const gulp = require('gulp');
|
|
10
14
|
const fs = require('fs-extra');
|
|
11
15
|
const path = require('path');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.23",
|
|
4
4
|
"description": "Technical specification drafting tool that generates rich specification documents from markdown. Forked from https://github.com/decentralized-identity/spec-up by Daniel Buchner (https://github.com/csuwildcat)",
|
|
5
5
|
"main": "./index",
|
|
6
6
|
"repository": {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file This file creates a json and a js file with an an object that contains the relations between terms
|
|
3
|
+
* @author Kor Dwarshuis
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @since 2024-06-22
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs-extra');
|
|
9
|
+
const config = fs.readJsonSync('specs.json');
|
|
10
|
+
const specDirectories = config.specs.map(spec => spec.spec_directory + '/' + spec.spec_terms_directory);
|
|
11
|
+
|
|
12
|
+
// Create directory named “output” in the project root if it does not yet exist
|
|
13
|
+
if (!fs.existsSync('output')) {
|
|
14
|
+
fs.mkdirSync('output');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Create a path for the output file in the project root
|
|
18
|
+
const outputPathJSON = 'output/term-relations-data.json';
|
|
19
|
+
const outputPathJS = 'output/term-relations-data.js';
|
|
20
|
+
|
|
21
|
+
function createTermRelations() {
|
|
22
|
+
let allDefs = {};
|
|
23
|
+
allDefs.defs = new Set();
|
|
24
|
+
|
|
25
|
+
// Go through all directories that contain files with a term and definition
|
|
26
|
+
console.log('All “spec_directory” found in specs.json: ', specDirectories);
|
|
27
|
+
specDirectories.forEach(specDirectory => {
|
|
28
|
+
// read directory
|
|
29
|
+
fs.readdirSync(specDirectory).forEach(file => {
|
|
30
|
+
// read file
|
|
31
|
+
if (file.endsWith('.md')) {
|
|
32
|
+
const markdown = fs.readFileSync(`${specDirectory}/${file}`, 'utf8');
|
|
33
|
+
|
|
34
|
+
let regexDef = /\[\[def:.*?\]\]/g;
|
|
35
|
+
let regexRef = /\[\[ref:.*?\]\]/g;
|
|
36
|
+
let regexXref = /\[\[xref:.*?\]\]/g;
|
|
37
|
+
|
|
38
|
+
let entry = {};
|
|
39
|
+
|
|
40
|
+
if (regexDef.test(markdown)) {
|
|
41
|
+
const defs = markdown.match(regexDef);
|
|
42
|
+
let refs = markdown.match(regexRef);
|
|
43
|
+
let xrefs = markdown.match(regexXref);
|
|
44
|
+
|
|
45
|
+
defs.forEach(def => {
|
|
46
|
+
// remove “[[def:” from the beginning of every value in allMatches
|
|
47
|
+
def = def.replace(/\[\[def:/, '');
|
|
48
|
+
|
|
49
|
+
// remove “]]” from the end of every value in allMatches
|
|
50
|
+
def = def.replace(/\]\]/, '');
|
|
51
|
+
|
|
52
|
+
// trim every entry of allMatches
|
|
53
|
+
def = def.trim();
|
|
54
|
+
|
|
55
|
+
// Split the input on the first comma
|
|
56
|
+
let [term, rest] = def.split(/,(.+)/);
|
|
57
|
+
|
|
58
|
+
// Trim the term
|
|
59
|
+
term = term.trim();
|
|
60
|
+
|
|
61
|
+
entry.term = term;
|
|
62
|
+
// Split the rest into an array of synonyms if it exists, otherwise use a placeholder
|
|
63
|
+
let synonyms = rest ? rest.split(',').map(s => s.trim()) : [];
|
|
64
|
+
entry.synonyms = synonyms;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (refs !== null) {
|
|
68
|
+
entry.refs = [];
|
|
69
|
+
refs.forEach(ref => {
|
|
70
|
+
// remove “[[ref:” from the beginning of every value in allMatches
|
|
71
|
+
ref = ref.replace(/\[\[ref:/, '');
|
|
72
|
+
// remove “]]” from the end of every value in allMatches
|
|
73
|
+
ref = ref.replace(/\]\]/, '');
|
|
74
|
+
// trim every entry of allMatches
|
|
75
|
+
ref = ref.trim();
|
|
76
|
+
entry.refs.push(ref);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (xrefs !== null) {
|
|
81
|
+
entry.xrefs = [];
|
|
82
|
+
xrefs.forEach(xref => {
|
|
83
|
+
// remove “[[xref:” from the beginning of every value in allMatches
|
|
84
|
+
xref = xref.replace(/\[\[xref:/, '');
|
|
85
|
+
// remove “]]” from the end of every value in allMatches
|
|
86
|
+
xref = xref.replace(/\]\]/, '');
|
|
87
|
+
// trim every entry of allMatches
|
|
88
|
+
xref = xref.trim();
|
|
89
|
+
entry.xrefs.push(xref);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
allDefs.defs.add(entry);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
})
|
|
97
|
+
// Convert the Set back to an Array if needed
|
|
98
|
+
allDefs.defs = Array.from(allDefs.defs);
|
|
99
|
+
|
|
100
|
+
// Convert allXrefsStr to a JSON string with indentation
|
|
101
|
+
const allDefsStr = JSON.stringify(allDefs, null, 2);
|
|
102
|
+
|
|
103
|
+
// Write the JSON code to a .json file
|
|
104
|
+
fs.writeFileSync(outputPathJSON, allDefsStr, 'utf8');
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
// Create the JS code for the assignment
|
|
108
|
+
const stringReadyForFileWrite = `const allTermRelations = ${allDefsStr};`;
|
|
109
|
+
|
|
110
|
+
// Write the JS code to a .js file
|
|
111
|
+
fs.writeFileSync(outputPathJS, stringReadyForFileWrite, 'utf8');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = {
|
|
115
|
+
createTermRelations
|
|
116
|
+
}
|