Skip to content

Commit

Permalink
funnelweave
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Nov 15, 2024
1 parent 2e9e89c commit e8dbd6e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 172 deletions.
84 changes: 0 additions & 84 deletions lib/fw.js

This file was deleted.

50 changes: 0 additions & 50 deletions lib/fwprettier.js

This file was deleted.

64 changes: 26 additions & 38 deletions lib/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Number {
this.meta = meta;
this.meta["pandoc-version"] = pandoc;
if (meta.name) builders[meta.name] = this;
if (this.meta.funnelweb)
this.funnelweb = new (require(this.meta.funnelweb))(this.meta.name);
}

secno(type) {
Expand All @@ -41,9 +43,12 @@ class Number {
}

skip(line) {
if (!this.meta.funnelweb && !(this.fence && this.skipping === true)) {
if (/^@(\$|o|!\{)/.test(line)) return (this.skipping = "fw");
if (/^@(\}|!\})/.test(line)) {
if (
(!this.funnelweb || this.funnelweb.skipcode()) &&
this.skipping !== true
) {
if (/^@[o$]/.test(line)) return (this.skipping = "fw");
if (/^@\}/.test(line)) {
this.skipping = false;
return true;
}
Expand All @@ -57,12 +62,14 @@ class Number {
}
return this.skipping;
}
var m = line.match(/^(:+)\s+(?:\{\.)?var(\S+)/);
var m = line.match(/^(:+)\s+(?:\{\.)?(var(\S+)|funnelweb)/);
if (m) {
this.fence = m[1];
if (this.variant !== m[2]) {
if (
(m[3] && m[3] !== this.variant) ||
(m[2] === "funnelweb" && !this.funnelweb)
)
return (this.skipping = true);
}
return this.fence.length < 3;
}
return this.skipping;
Expand All @@ -83,10 +90,7 @@ class Number {
function (line) {
lineno++;
if (this.skip(line)) return;
if (this.meta.funnelweb)
line = line
.replace(/@!.*$/, "")
.replace(/^@[$o]@\<(.*?)@\>.*?@\{/, " ##fwisec $1");
if (this.funnelweb) line = this.funnelweb.phase1(line);
try {
for (
var m, regex = /\[.*?\]\{id=(.*?)\}/g;
Expand Down Expand Up @@ -169,6 +173,10 @@ class Number {
"line",
function (line) {
lineno++;
if (this.funnelweb) {
const code = this.funnelweb.code(line);
if (code) out.write(code);
}
if (this.skip(line)) return;
try {
var extraline;
Expand All @@ -193,22 +201,11 @@ class Number {
if (m1)
this.tableofcontents(this.toc[m1[1]]?.sub || [], out, "");
else {
if (this.meta.funnelweb)
line = line
.replace(/^@!\{/, "::: funnelweb")
.replace(/^@!\}/, ":::")
.replace(/@!.*$/, "")
.replace(
/^@[$o]@\<(.*?)@\>.*?@\{/,
function (m, p) {
extraline = "::::\n```" + this.meta.funnelweb;
return "::: funnelweb\n:::: caption\n ##fwisec " + p;
}.bind(this),
)
.replace(/^@\}/, function (m) {
extraline = ":::";
return "```";
});
if (this.funnelweb) {
const l = this.funnelweb.phase2(line);
line = l.line;
extraline = l.extraline;
}
line = line.replace(
/\$\$\$(.*?)\$\$\$/g,
function (m, p) {
Expand Down Expand Up @@ -292,21 +289,12 @@ class Number {
this.toc = { "": { sub: [] } };
this.match = 0;
for (var c of this.chapters) await this.phase1(c);
if (this.meta.funnelweb && this.toc.fwisec) {
this.toc.fwisec.sub.sort(function (a, b) {
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
});
for (var i = 1; i < this.toc.fwisec.sub.length; )
if (this.toc.fwisec.sub[i].name === this.toc.fwisec.sub[i - 1].name) {
this.toc.fwisec.sub[i - 1].sub.push(this.toc.fwisec.sub[i]);
this.toc.fwisec.sub.splice(i, 1);
} else i++;
}
if (this.funnelweb && this.toc.fwisec)
this.funnelweb.sortindex(this.toc.fwisec);
}

async write(out) {
if (this.funnelweb) await this.funnelweb.weave();
this.match = 0;
for (var c of this.chapters) {
await this.phase2(c, out);
Expand Down
1 change: 1 addition & 0 deletions styles/odata.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ td > code {

.example pre,
.funnelweb pre,
.funnelweb p,
.rep {
margin-left: var(--indent);
}
Expand Down

0 comments on commit e8dbd6e

Please sign in to comment.