gutterpress 0.11.22 → 0.11.23-alpha.1

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.
Files changed (57) hide show
  1. package/README.md +5 -5
  2. package/dist/{README-3nj919rm.md → README-8ef336pp.md} +1 -1
  3. package/dist/api/index.js +4 -4
  4. package/dist/{build-53bw14h7.js → build-09cd1n7s.js} +8 -8
  5. package/dist/{chapter-01-rkpyvjna.md → chapter-01-gsbjt584.md} +1 -1
  6. package/dist/chapter-01-s71xrf5q.md +69 -0
  7. package/dist/{chapter-01-7jwqg1ct.md → chapter-01-wgjfz4w6.md} +1 -1
  8. package/dist/checks/source/character-table.d.ts +12 -6
  9. package/dist/{cli-ke86zsz6.js → cli-5hkmp2wy.js} +70 -40
  10. package/dist/{cli-kx4hbnx2.js → cli-b0vyjvmt.js} +1 -1
  11. package/dist/{cli-1hxxwbaq.js → cli-ccp7sxz3.js} +1 -1
  12. package/dist/{cli-zj5xaepv.js → cli-dd115fa8.js} +22 -6
  13. package/dist/{cli-8kg0wjdt.js → cli-dtckwda1.js} +1 -1
  14. package/dist/{cli-1ngqzg8s.js → cli-fe43evmf.js} +21 -5
  15. package/dist/{cli-ntwqmdnw.js → cli-h17e3mtz.js} +462 -4
  16. package/dist/{cli-cjftezxr.js → cli-nr6j6300.js} +2 -1
  17. package/dist/cli.js +12 -12
  18. package/dist/{doctor-xka1frnx.js → doctor-nddspx4n.js} +3 -3
  19. package/dist/{engine-p93f06gj.js → engine-892swzzc.js} +2 -2
  20. package/dist/{engine-0ndvy8vj.js → engine-yjzknt0g.js} +2 -2
  21. package/dist/{ext-dwfqyy1j.js → ext-zjpen4yx.js} +9 -9
  22. package/dist/{extension-restore-7vp3vh77.js → extension-restore-jvs60x9b.js} +3 -3
  23. package/dist/{extension-restore-ct1wk344.js → extension-restore-w8xt4kbq.js} +5 -5
  24. package/dist/{index-53nrm5j1.js → index-0w2azsk1.js} +1 -1
  25. package/dist/{index-4v7e621e.js → index-2jpk25en.js} +464 -5
  26. package/dist/{index-vay3ff1f.js → index-dsvk7q6s.js} +21 -5
  27. package/dist/{index-6cmn2wpd.js → index-m4hhzg3c.js} +21 -5
  28. package/dist/{index-kh7fayjv.js → index-zrhyb967.js} +328 -311
  29. package/dist/index.js +5 -5
  30. package/dist/lib/build-runner.d.ts +1 -1
  31. package/dist/lib/extension-manager.d.ts +1 -1
  32. package/dist/lib/extension-specifier.d.ts +1 -1
  33. package/dist/lib/markdown/assemble.d.ts +7 -1
  34. package/dist/lib/markdown/gutterpress-css.d.ts +1 -1
  35. package/dist/lib/markdown/index.d.ts +4 -0
  36. package/dist/lib/markdown/math.d.ts +43 -0
  37. package/dist/lib/markdown/renderer.d.ts +11 -8
  38. package/dist/lib/markdown/table.d.ts +46 -0
  39. package/dist/lib/markdown/typography.d.ts +12 -0
  40. package/dist/lib/presets.d.ts +1 -1
  41. package/dist/lib/project-scaffold.d.ts +1 -1
  42. package/dist/lib/project-templates.d.ts +9 -1
  43. package/dist/manifest-8f10dr4f.yaml +17 -0
  44. package/dist/{manifest.schema-399bx3vc.json → manifest.schema-9aeaered.json} +8 -1
  45. package/dist/{new-1pawj2qf.js → new-xhq8wczn.js} +8 -8
  46. package/dist/package-zttkgydq.json +10 -0
  47. package/dist/{plugins-fr4fnzhb.js → plugins-9en8m9y0.js} +3 -3
  48. package/dist/{plugins-g4dgw7mn.js → plugins-gf0gkjmv.js} +1 -1
  49. package/dist/{preflight-ept9q57t.js → preflight-negnxg7b.js} +8 -8
  50. package/dist/preview/file-watcher.d.ts +1 -0
  51. package/dist/{preview-fxpnjv7k.js → preview-cep2s9cg.js} +8 -8
  52. package/dist/{publish-zhqqsgmr.js → publish-xery6qc6.js} +8 -8
  53. package/dist/render.js +470 -11
  54. package/dist/schema/manifest.types.d.ts +8 -0
  55. package/dist/theme-9c58td2d.css +76 -0
  56. package/dist/{validate-t68gvckq.js → validate-3d0sgf4g.js} +8 -8
  57. package/package.json +2 -1
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  build
3
- } from "./cli-8kg0wjdt.js";
3
+ } from "./cli-dtckwda1.js";
4
4
  import"./cli-eyyggect.js";
5
5
  import"./cli-asap4t1z.js";
6
- import"./cli-1ngqzg8s.js";
6
+ import"./cli-fe43evmf.js";
7
7
  import {
8
8
  BuildError
9
9
  } from "./cli-46ycxe6r.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  build
3
- } from "./index-53nrm5j1.js";
3
+ } from "./index-0w2azsk1.js";
4
4
  import"./index-apc8w9w8.js";
5
5
  import {
6
6
  BuildError
7
- } from "./index-vay3ff1f.js";
7
+ } from "./index-dsvk7q6s.js";
8
8
  import"./index-bt0qws5c.js";
9
9
  import"./index-37x76zdn.js";
10
10
 
@@ -2,10 +2,10 @@ import {
2
2
  importExtensionFromFile,
3
3
  importExtensionFromUrl,
4
4
  searchNpmExtensions
5
- } from "./cli-ke86zsz6.js";
6
- import"./cli-1hxxwbaq.js";
5
+ } from "./cli-5hkmp2wy.js";
6
+ import"./cli-ccp7sxz3.js";
7
7
  import"./cli-ht1bcqdd.js";
8
- import"./cli-8kg0wjdt.js";
8
+ import"./cli-dtckwda1.js";
9
9
  import"./cli-2ppw6q9v.js";
10
10
  import"./cli-eyyggect.js";
11
11
  import"./cli-asap4t1z.js";
@@ -22,9 +22,9 @@ import {
22
22
  removeExtension,
23
23
  setExtensionEnabled,
24
24
  updateExtensions
25
- } from "./cli-zj5xaepv.js";
26
- import"./cli-ntwqmdnw.js";
27
- import"./cli-kx4hbnx2.js";
25
+ } from "./cli-dd115fa8.js";
26
+ import"./cli-h17e3mtz.js";
27
+ import"./cli-b0vyjvmt.js";
28
28
  import {
29
29
  UsageError,
30
30
  exitForUsage,
@@ -32,8 +32,8 @@ import {
32
32
  rejectUnknownFlags,
33
33
  resolveProjectDir
34
34
  } from "./cli-d8xjns66.js";
35
- import"./cli-cjftezxr.js";
36
- import"./cli-1ngqzg8s.js";
35
+ import"./cli-nr6j6300.js";
36
+ import"./cli-fe43evmf.js";
37
37
  import {
38
38
  EXIT_CODES
39
39
  } from "./cli-46ycxe6r.js";
@@ -69,7 +69,7 @@ var extAddArgs = {
69
69
  },
70
70
  look: {
71
71
  type: "boolean",
72
- description: "Treat SOURCE as a built-in look id (clean-book, zine, technical-doc): copy it into extensions/ and add it",
72
+ description: "Treat SOURCE as a built-in look id (clean-book, zine, technical-doc, academic): copy it into extensions/ and add it",
73
73
  required: false
74
74
  }
75
75
  };
@@ -3,9 +3,9 @@ import {
3
3
  restoreForCommand,
4
4
  restoreOfflineMessage,
5
5
  restorePinnedExtensions
6
- } from "./index-6cmn2wpd.js";
7
- import"./index-4v7e621e.js";
8
- import"./index-vay3ff1f.js";
6
+ } from "./index-m4hhzg3c.js";
7
+ import"./index-2jpk25en.js";
8
+ import"./index-dsvk7q6s.js";
9
9
  import"./index-r7jcsk6h.js";
10
10
  import"./index-37x76zdn.js";
11
11
  export {
@@ -3,12 +3,12 @@ import {
3
3
  restoreForCommand,
4
4
  restoreOfflineMessage,
5
5
  restorePinnedExtensions
6
- } from "./cli-zj5xaepv.js";
7
- import"./cli-ntwqmdnw.js";
8
- import"./cli-kx4hbnx2.js";
6
+ } from "./cli-dd115fa8.js";
7
+ import"./cli-h17e3mtz.js";
8
+ import"./cli-b0vyjvmt.js";
9
9
  import"./cli-d8xjns66.js";
10
- import"./cli-cjftezxr.js";
11
- import"./cli-1ngqzg8s.js";
10
+ import"./cli-nr6j6300.js";
11
+ import"./cli-fe43evmf.js";
12
12
  import"./cli-46ycxe6r.js";
13
13
  import"./cli-h3phdstf.js";
14
14
  import"./cli-37x76zdn.js";
@@ -21,7 +21,7 @@ import {
21
21
  } from "./index-apc8w9w8.js";
22
22
  import {
23
23
  getAssetPath
24
- } from "./index-vay3ff1f.js";
24
+ } from "./index-dsvk7q6s.js";
25
25
  import {
26
26
  launchChromium
27
27
  } from "./index-bt0qws5c.js";
@@ -37,7 +37,7 @@ import { satisfies, validRange } from "semver";
37
37
  // package.json
38
38
  var package_default = {
39
39
  name: "gutterpress",
40
- version: "0.11.22",
40
+ version: "0.11.23-alpha.1",
41
41
  description: "Markdown-to-PDF converter for professional print layout using a native Chromium print engine and Ghostscript.",
42
42
  author: "itlackey",
43
43
  license: "MPL-2.0",
@@ -115,6 +115,7 @@ var package_default = {
115
115
  "markdown-it-sub": "^2.0.0",
116
116
  "markdown-it-sup": "^2.0.0",
117
117
  markdownlint: "^0.40.0",
118
+ "mathjax-full": "^3.2.2",
118
119
  "pdf-lib": "^1.17.1",
119
120
  postcss: "^8.5.18",
120
121
  "resolve.exports": "2.0.3",
@@ -1760,6 +1761,38 @@ img.gp-shape {
1760
1761
  :where(.gp-alert-important) { --gp-alert-color: var(--gp-alert-important-color); }
1761
1762
  :where(.gp-alert-warning) { --gp-alert-color: var(--gp-alert-warning-color); }
1762
1763
  :where(.gp-alert-caution) { --gp-alert-color: var(--gp-alert-caution-color); }
1764
+
1765
+ /* Math (the bundled gutterpress-math feature, math.ts): MathJax's own rules
1766
+ for the <mjx-container> SVG output it emits, from its SVG output jax's
1767
+ stylesheet, less the ones for its interactive menu and tooltips. Inert in
1768
+ a book without formulas. */
1769
+ mjx-container[jax="SVG"] { direction: ltr; }
1770
+ mjx-container[jax="SVG"] > svg { overflow: visible; min-height: 1px; min-width: 1px; }
1771
+ mjx-container[jax="SVG"] > svg a { fill: blue; stroke: blue; }
1772
+ mjx-container[jax="SVG"][display="true"] { display: block; text-align: center; margin: 1em 0; }
1773
+ mjx-container[jax="SVG"][display="true"][width="full"] { display: flex; }
1774
+ mjx-container[jax="SVG"][justify="left"] { text-align: left; }
1775
+ mjx-container[jax="SVG"][justify="right"] { text-align: right; }
1776
+ mjx-container[jax="SVG"] path[data-c], mjx-container[jax="SVG"] use[data-c] { stroke-width: 3; }
1777
+ mjx-assistive-mml {
1778
+ position: absolute !important;
1779
+ top: 0px; left: 0px;
1780
+ clip: rect(1px, 1px, 1px, 1px);
1781
+ padding: 1px 0px 0px 0px !important;
1782
+ border: 0px !important;
1783
+ display: block !important;
1784
+ width: auto !important;
1785
+ overflow: hidden !important;
1786
+ user-select: none;
1787
+ }
1788
+ mjx-assistive-mml[display="block"] { width: 100% !important; }
1789
+ g[data-mml-node="merror"] > g { fill: red; stroke: red; }
1790
+ g[data-mml-node="merror"] > rect[data-background] { fill: yellow; stroke: none; }
1791
+ g[data-mml-node="mtable"] > line[data-line], svg[data-table] > g > line[data-line] { stroke-width: 70px; fill: none; }
1792
+ g[data-mml-node="mtable"] > rect[data-frame], svg[data-table] > g > rect[data-frame] { stroke-width: 70px; fill: none; }
1793
+ g[data-mml-node="mtable"] > .mjx-dashed, svg[data-table] > g > .mjx-dashed { stroke-dasharray: 140; }
1794
+ g[data-mml-node="mtable"] > .mjx-dotted, svg[data-table] > g > .mjx-dotted { stroke-linecap: round; stroke-dasharray: 0,140; }
1795
+ g[data-mml-node="mtable"] > g > svg { overflow: visible; }
1763
1796
  `;
1764
1797
  var GP_CLASSES = new Set([
1765
1798
  "gp-left",
@@ -2074,6 +2107,224 @@ function gpBlockNames(md) {
2074
2107
  md.core.ruler.push("gp_block_names", (state) => nameBlocksAndHeadings(state.tokens));
2075
2108
  }
2076
2109
 
2110
+ // src/lib/markdown/table.ts
2111
+ import { isSpace } from "markdown-it/lib/common/utils.mjs";
2112
+ var scanCodeSpan = (src, start, max) => {
2113
+ let open = start;
2114
+ while (open < max && src.charCodeAt(open) === 96)
2115
+ open++;
2116
+ const length = open - start;
2117
+ let pos = open;
2118
+ while (pos < max) {
2119
+ if (src.charCodeAt(pos) !== 96) {
2120
+ pos++;
2121
+ continue;
2122
+ }
2123
+ let run = pos;
2124
+ while (run < max && src.charCodeAt(run) === 96)
2125
+ run++;
2126
+ if (run - pos === length)
2127
+ return run;
2128
+ pos = run;
2129
+ }
2130
+ return open;
2131
+ };
2132
+ var DEFAULT_SPANS = { 96: scanCodeSpan };
2133
+ function splitCells(str2, spans) {
2134
+ const result = [];
2135
+ const max = str2.length;
2136
+ let pos = 0;
2137
+ let lastPos = 0;
2138
+ let current = "";
2139
+ let isEscaped = false;
2140
+ while (pos < max) {
2141
+ const ch = str2.charCodeAt(pos);
2142
+ if (ch === 124) {
2143
+ if (!isEscaped) {
2144
+ result.push(current + str2.substring(lastPos, pos));
2145
+ current = "";
2146
+ lastPos = pos + 1;
2147
+ } else {
2148
+ current += str2.substring(lastPos, pos - 1);
2149
+ lastPos = pos;
2150
+ }
2151
+ } else if (!isEscaped && spans[ch]) {
2152
+ pos = spans[ch](str2, pos, max);
2153
+ continue;
2154
+ }
2155
+ isEscaped = ch === 92;
2156
+ pos++;
2157
+ }
2158
+ result.push(current + str2.substring(lastPos));
2159
+ return result;
2160
+ }
2161
+ function getLine(state, line) {
2162
+ const pos = state.bMarks[line] + state.tShift[line];
2163
+ const max = state.eMarks[line];
2164
+ return state.src.slice(pos, max);
2165
+ }
2166
+ var MAX_AUTOCOMPLETED_CELLS = 65536;
2167
+ function warnExtraCells(env, line, cells, columns) {
2168
+ if (!env.layoutWarnings)
2169
+ env.layoutWarnings = [];
2170
+ const extra = cells - columns;
2171
+ env.layoutWarnings.push({
2172
+ line: line + 1,
2173
+ type: "table_extra_cells",
2174
+ message: `This row has ${cells} cells but the table has ${columns} columns, so its last ` + `${extra === 1 ? "cell is" : `${extra} cells are`} left out. ` + "A | inside a cell splits it: write \\| for a literal one."
2175
+ });
2176
+ }
2177
+ function tableRule(spans) {
2178
+ return function table(state, startLine, endLine, silent) {
2179
+ if (startLine + 2 > endLine)
2180
+ return false;
2181
+ let nextLine = startLine + 1;
2182
+ if (state.sCount[nextLine] < state.blkIndent)
2183
+ return false;
2184
+ if (state.sCount[nextLine] - state.blkIndent >= 4)
2185
+ return false;
2186
+ let pos = state.bMarks[nextLine] + state.tShift[nextLine];
2187
+ if (pos >= state.eMarks[nextLine])
2188
+ return false;
2189
+ const firstCh = state.src.charCodeAt(pos++);
2190
+ if (firstCh !== 124 && firstCh !== 45 && firstCh !== 58)
2191
+ return false;
2192
+ if (pos >= state.eMarks[nextLine])
2193
+ return false;
2194
+ const secondCh = state.src.charCodeAt(pos++);
2195
+ if (secondCh !== 124 && secondCh !== 45 && secondCh !== 58 && !isSpace(secondCh)) {
2196
+ return false;
2197
+ }
2198
+ if (firstCh === 45 && isSpace(secondCh))
2199
+ return false;
2200
+ while (pos < state.eMarks[nextLine]) {
2201
+ const ch = state.src.charCodeAt(pos);
2202
+ if (ch !== 124 && ch !== 45 && ch !== 58 && !isSpace(ch))
2203
+ return false;
2204
+ pos++;
2205
+ }
2206
+ let lineText = getLine(state, startLine + 1);
2207
+ let columns = lineText.split("|");
2208
+ const aligns = [];
2209
+ for (let i = 0;i < columns.length; i++) {
2210
+ const t = columns[i].trim();
2211
+ if (!t) {
2212
+ if (i === 0 || i === columns.length - 1) {
2213
+ continue;
2214
+ } else {
2215
+ return false;
2216
+ }
2217
+ }
2218
+ if (!/^:?-+:?$/.test(t))
2219
+ return false;
2220
+ if (t.charCodeAt(t.length - 1) === 58) {
2221
+ aligns.push(t.charCodeAt(0) === 58 ? "center" : "right");
2222
+ } else if (t.charCodeAt(0) === 58) {
2223
+ aligns.push("left");
2224
+ } else {
2225
+ aligns.push("");
2226
+ }
2227
+ }
2228
+ lineText = getLine(state, startLine).trim();
2229
+ if (lineText.indexOf("|") === -1)
2230
+ return false;
2231
+ if (state.sCount[startLine] - state.blkIndent >= 4)
2232
+ return false;
2233
+ columns = splitCells(lineText, spans);
2234
+ if (columns.length && columns[0] === "")
2235
+ columns.shift();
2236
+ if (columns.length && columns[columns.length - 1] === "")
2237
+ columns.pop();
2238
+ const columnCount = columns.length;
2239
+ if (columnCount === 0 || columnCount !== aligns.length)
2240
+ return false;
2241
+ if (silent)
2242
+ return true;
2243
+ const oldParentType = state.parentType;
2244
+ state.parentType = "table";
2245
+ const terminatorRules = state.md.block.ruler.getRules("blockquote");
2246
+ const token_to = state.push("table_open", "table", 1);
2247
+ const tableLines = [startLine, 0];
2248
+ token_to.map = tableLines;
2249
+ const token_tho = state.push("thead_open", "thead", 1);
2250
+ token_tho.map = [startLine, startLine + 1];
2251
+ const token_htro = state.push("tr_open", "tr", 1);
2252
+ token_htro.map = [startLine, startLine + 1];
2253
+ for (let i = 0;i < columns.length; i++) {
2254
+ const token_ho = state.push("th_open", "th", 1);
2255
+ if (aligns[i]) {
2256
+ token_ho.attrs = [["style", "text-align:" + aligns[i]]];
2257
+ }
2258
+ const token_il = state.push("inline", "", 0);
2259
+ token_il.content = columns[i].trim();
2260
+ token_il.children = [];
2261
+ state.push("th_close", "th", -1);
2262
+ }
2263
+ state.push("tr_close", "tr", -1);
2264
+ state.push("thead_close", "thead", -1);
2265
+ let tbodyLines;
2266
+ let autocompletedCells = 0;
2267
+ for (nextLine = startLine + 2;nextLine < endLine; nextLine++) {
2268
+ if (state.sCount[nextLine] < state.blkIndent)
2269
+ break;
2270
+ let terminate = false;
2271
+ for (let i = 0, l = terminatorRules.length;i < l; i++) {
2272
+ if (terminatorRules[i](state, nextLine, endLine, true)) {
2273
+ terminate = true;
2274
+ break;
2275
+ }
2276
+ }
2277
+ if (terminate)
2278
+ break;
2279
+ lineText = getLine(state, nextLine).trim();
2280
+ if (!lineText)
2281
+ break;
2282
+ if (state.sCount[nextLine] - state.blkIndent >= 4)
2283
+ break;
2284
+ columns = splitCells(lineText, spans);
2285
+ if (columns.length && columns[0] === "")
2286
+ columns.shift();
2287
+ if (columns.length && columns[columns.length - 1] === "")
2288
+ columns.pop();
2289
+ if (columns.length > columnCount) {
2290
+ warnExtraCells(state.env, nextLine, columns.length, columnCount);
2291
+ }
2292
+ autocompletedCells += columnCount - columns.length;
2293
+ if (autocompletedCells > MAX_AUTOCOMPLETED_CELLS)
2294
+ break;
2295
+ if (nextLine === startLine + 2) {
2296
+ const token_tbo = state.push("tbody_open", "tbody", 1);
2297
+ token_tbo.map = tbodyLines = [startLine + 2, 0];
2298
+ }
2299
+ const token_tro = state.push("tr_open", "tr", 1);
2300
+ token_tro.map = [nextLine, nextLine + 1];
2301
+ for (let i = 0;i < columnCount; i++) {
2302
+ const token_tdo = state.push("td_open", "td", 1);
2303
+ if (aligns[i]) {
2304
+ token_tdo.attrs = [["style", "text-align:" + aligns[i]]];
2305
+ }
2306
+ const token_il = state.push("inline", "", 0);
2307
+ token_il.content = columns[i] ? columns[i].trim() : "";
2308
+ token_il.children = [];
2309
+ state.push("td_close", "td", -1);
2310
+ }
2311
+ state.push("tr_close", "tr", -1);
2312
+ }
2313
+ if (tbodyLines) {
2314
+ state.push("tbody_close", "tbody", -1);
2315
+ tbodyLines[1] = nextLine;
2316
+ }
2317
+ state.push("table_close", "table", -1);
2318
+ tableLines[1] = nextLine;
2319
+ state.parentType = oldParentType;
2320
+ state.line = nextLine;
2321
+ return true;
2322
+ };
2323
+ }
2324
+ function gpTable(md, options) {
2325
+ md.block.ruler.at("table", tableRule(options?.spans ?? DEFAULT_SPANS), { alt: ["paragraph", "reference"] });
2326
+ }
2327
+
2077
2328
  // src/lib/markdown/table-align.ts
2078
2329
  var ALIGN = /^text-align:(left|center|right)$/;
2079
2330
  function gpTableAlign(md) {
@@ -2095,6 +2346,57 @@ th[data-align="center"], td[data-align="center"] { text-align: center; }
2095
2346
  th[data-align="right"], td[data-align="right"] { text-align: right; }
2096
2347
  `;
2097
2348
 
2349
+ // src/lib/markdown/typography.ts
2350
+ var EM_DASH = /(^|[^-])---(?=[^-]|$)/gm;
2351
+ var EN_DASH_SPACED = /(^|\s)--(?=\s|$)/gm;
2352
+ var EN_DASH = /(^|[^-\s])--(?=[^-\s]|$)/gm;
2353
+ var ELLIPSIS = /\.\.\./g;
2354
+ var CANDIDATE = /--|\.\.\./;
2355
+ function replaceInText(children) {
2356
+ let insideAutolink = 0;
2357
+ for (let i = children.length - 1;i >= 0; i--) {
2358
+ const token = children[i];
2359
+ if (token.type === "text" && !insideAutolink && CANDIDATE.test(token.content)) {
2360
+ token.content = token.content.replace(ELLIPSIS, "…").replace(EM_DASH, "$1—").replace(EN_DASH_SPACED, "$1–").replace(EN_DASH, "$1–");
2361
+ }
2362
+ if (token.type === "link_close" && token.info === "auto")
2363
+ insideAutolink++;
2364
+ if (token.type === "link_open" && token.info === "auto")
2365
+ insideAutolink--;
2366
+ }
2367
+ }
2368
+ var QUOTES = {
2369
+ en: "“”‘’",
2370
+ de: "„“‚‘",
2371
+ "de-ch": "«»‹›",
2372
+ "de-li": "«»‹›",
2373
+ fr: ["« ", " »", "‹ ", " ›"],
2374
+ es: "«»“”",
2375
+ it: "«»“”",
2376
+ pt: "«»“”",
2377
+ "pt-br": "“”‘’",
2378
+ ru: "«»„“",
2379
+ pl: "„”«»",
2380
+ cs: "„“‚‘",
2381
+ sk: "„“‚‘",
2382
+ sv: "””’’",
2383
+ fi: "””’’"
2384
+ };
2385
+ function quotesFor(language) {
2386
+ const tag = (language ?? "en").toLowerCase();
2387
+ return QUOTES[tag] ?? QUOTES[tag.split("-")[0]] ?? QUOTES.en;
2388
+ }
2389
+ function gpTypography(md) {
2390
+ md.disable("replacements");
2391
+ md.core.ruler.after("linkify", "gp_typography", (state) => {
2392
+ for (const token of state.tokens) {
2393
+ if (token.type !== "inline" || !token.children || !CANDIDATE.test(token.content))
2394
+ continue;
2395
+ replaceInText(token.children);
2396
+ }
2397
+ });
2398
+ }
2399
+
2098
2400
  // src/lib/two-versions-markers.ts
2099
2401
  var YOUR_VERSION_LABEL = "your version";
2100
2402
  var ONLINE_VERSION_LABEL = "online version";
@@ -2316,6 +2618,159 @@ function gfmAlerts(md) {
2316
2618
  md.core.ruler.after("block", "gp_gfm_alerts", gfmAlertsRule);
2317
2619
  }
2318
2620
 
2621
+ // src/lib/markdown/math.ts
2622
+ import { mathjax } from "mathjax-full/js/mathjax.js";
2623
+ import { TeX } from "mathjax-full/js/input/tex.js";
2624
+ import { SVG } from "mathjax-full/js/output/svg.js";
2625
+ import { liteAdaptor } from "mathjax-full/js/adaptors/liteAdaptor.js";
2626
+ import { RegisterHTMLHandler } from "mathjax-full/js/handlers/html.js";
2627
+ import { AssistiveMmlHandler } from "mathjax-full/js/a11y/assistive-mml.js";
2628
+ import { AllPackages } from "mathjax-full/js/input/tex/AllPackages.js";
2629
+ function findInlineMathEnd(src, start, max) {
2630
+ const after = src.charCodeAt(start + 1);
2631
+ if (after === 32 || after === 9)
2632
+ return -1;
2633
+ let match = start + 1;
2634
+ while ((match = src.indexOf("$", match)) !== -1 && match < max) {
2635
+ let pos = match - 1;
2636
+ while (src.charCodeAt(pos) === 92)
2637
+ pos--;
2638
+ if ((match - pos) % 2 === 1)
2639
+ break;
2640
+ match++;
2641
+ }
2642
+ if (match === -1 || match >= max)
2643
+ return -1;
2644
+ if (match === start + 1)
2645
+ return -2;
2646
+ const before = src.charCodeAt(match - 1);
2647
+ const next = src.charCodeAt(match + 1);
2648
+ if (before === 32 || before === 9 || next >= 48 && next <= 57)
2649
+ return -1;
2650
+ return match;
2651
+ }
2652
+ var scanInlineMath = (src, start, max) => {
2653
+ const end = findInlineMathEnd(src, start, max);
2654
+ return end >= 0 ? end + 1 : end === -2 ? start + 2 : start + 1;
2655
+ };
2656
+ function mathInline(state, silent) {
2657
+ if (state.src.charCodeAt(state.pos) !== 36)
2658
+ return false;
2659
+ const end = findInlineMathEnd(state.src, state.pos, state.posMax);
2660
+ if (end < 0) {
2661
+ const literal = end === -2 ? "$$" : "$";
2662
+ if (!silent)
2663
+ state.pending += literal;
2664
+ state.pos += literal.length;
2665
+ return true;
2666
+ }
2667
+ if (!silent) {
2668
+ const token = state.push("math_inline", "math", 0);
2669
+ token.markup = "$";
2670
+ token.content = state.src.slice(state.pos + 1, end);
2671
+ }
2672
+ state.pos = end + 1;
2673
+ return true;
2674
+ }
2675
+ function mathBlock(state, start, end, silent) {
2676
+ let pos = state.bMarks[start] + state.tShift[start];
2677
+ let max = state.eMarks[start];
2678
+ if (pos + 2 > max)
2679
+ return false;
2680
+ if (state.src.slice(pos, pos + 2) !== "$$")
2681
+ return false;
2682
+ pos += 2;
2683
+ let firstLine = state.src.slice(pos, max);
2684
+ if (silent)
2685
+ return true;
2686
+ let found = false;
2687
+ let lastLine = "";
2688
+ if (firstLine.trim().slice(-2) === "$$") {
2689
+ firstLine = firstLine.trim().slice(0, -2);
2690
+ found = true;
2691
+ }
2692
+ let next = start;
2693
+ while (!found) {
2694
+ next++;
2695
+ if (next >= end)
2696
+ break;
2697
+ pos = state.bMarks[next] + state.tShift[next];
2698
+ max = state.eMarks[next];
2699
+ if (pos < max && state.tShift[next] < state.blkIndent) {
2700
+ break;
2701
+ }
2702
+ if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
2703
+ const lastPos = state.src.slice(0, max).lastIndexOf("$$");
2704
+ lastLine = state.src.slice(pos, lastPos);
2705
+ found = true;
2706
+ }
2707
+ }
2708
+ state.line = next + 1;
2709
+ const token = state.push("math_block", "math", 0);
2710
+ token.block = true;
2711
+ token.content = (firstLine && firstLine.trim() ? firstLine + `
2712
+ ` : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
2713
+ token.map = [start, state.line];
2714
+ token.markup = "$$";
2715
+ return true;
2716
+ }
2717
+ var adaptor = null;
2718
+ function getAdaptor() {
2719
+ if (!adaptor) {
2720
+ adaptor = liteAdaptor();
2721
+ AssistiveMmlHandler(RegisterHTMLHandler(adaptor));
2722
+ }
2723
+ return adaptor;
2724
+ }
2725
+ var PACKAGES = AllPackages.filter((name) => name !== "noerrors" && name !== "noundefined");
2726
+ function gpMath(md) {
2727
+ const html = getAdaptor();
2728
+ let errors = [];
2729
+ const tex = new TeX({
2730
+ packages: PACKAGES,
2731
+ formatError: (jax, err) => {
2732
+ errors.push(err.message);
2733
+ return jax.formatError(err);
2734
+ }
2735
+ });
2736
+ const document = mathjax.document("", { InputJax: tex, OutputJax: new SVG({ fontCache: "none" }) });
2737
+ const typeset = (token, display, env) => {
2738
+ errors = [];
2739
+ const out = html.outerHTML(document.convert(token.content, { display }));
2740
+ for (const message of errors) {
2741
+ if (!env.layoutWarnings)
2742
+ env.layoutWarnings = [];
2743
+ env.layoutWarnings.push({
2744
+ line: token.meta?.line ?? (token.map?.[0] ?? 0) + 1,
2745
+ type: "math_error",
2746
+ message: `This formula could not be typeset: ${message}. It prints in red until it is fixed.`
2747
+ });
2748
+ }
2749
+ return display ? out + `
2750
+ ` : out;
2751
+ };
2752
+ md.inline.ruler.after("escape", "math_inline", mathInline);
2753
+ md.block.ruler.after("blockquote", "math_block", mathBlock, {
2754
+ alt: ["paragraph", "reference", "blockquote", "list"]
2755
+ });
2756
+ md.core.ruler.after("inline", "math_lines", (state) => {
2757
+ let line = 1;
2758
+ for (const token of state.tokens) {
2759
+ if (token.map)
2760
+ line = token.map[0] + 1;
2761
+ if (token.type !== "inline" || !token.children)
2762
+ continue;
2763
+ for (const child of token.children) {
2764
+ if (child.type === "math_inline")
2765
+ child.meta = { line };
2766
+ }
2767
+ }
2768
+ });
2769
+ md.renderer.rules.math_inline = (tokens, idx, _options, env) => typeset(tokens[idx], false, env);
2770
+ md.renderer.rules.math_block = (tokens, idx, _options, env) => typeset(tokens[idx], true, env);
2771
+ md.use(gpTable, { spans: { ...DEFAULT_SPANS, 36: scanInlineMath } });
2772
+ }
2773
+
2319
2774
  // src/lib/markdown/images.ts
2320
2775
  var isSrcsetSpace = (char) => char === "\t" || char === `
2321
2776
  ` || char === "\f" || char === "\r" || char === " ";
@@ -2742,14 +3197,17 @@ var BUILTIN_OPTIONAL_PLUGINS = {
2742
3197
  "markdown-it-sub": unwrapPlugin(markdownItSub),
2743
3198
  "markdown-it-sup": unwrapPlugin(markdownItSup),
2744
3199
  "markdown-it-abbr": unwrapPlugin(markdownItAbbr),
2745
- "gutterpress-gfm-alerts": gfmAlerts
3200
+ "gutterpress-gfm-alerts": gfmAlerts,
3201
+ "gutterpress-math": gpMath
2746
3202
  };
2747
- function createMarkdownRenderer(customPlugins) {
3203
+ function createMarkdownRenderer(customPlugins, options) {
2748
3204
  const md = new MarkdownIt({
2749
3205
  html: true,
2750
3206
  linkify: true,
2751
- typographer: true
3207
+ typographer: true,
3208
+ quotes: quotesFor(options?.language)
2752
3209
  });
3210
+ md.use(gpTypography);
2753
3211
  md.use(unwrapPlugin(markdownItAttrs));
2754
3212
  md.use(unwrapPlugin(markdownItFootnote));
2755
3213
  md.use(unwrapPlugin(markdownItDeflist));
@@ -2759,6 +3217,7 @@ function createMarkdownRenderer(customPlugins) {
2759
3217
  md.use(plugin, { declaredMarkers });
2760
3218
  md.use(gpPinScope);
2761
3219
  md.use(gpBlockNames);
3220
+ md.use(gpTable);
2762
3221
  md.use(gpTableAlign);
2763
3222
  md.use(gpTwoVersions);
2764
3223
  registerImageRule(md);
@@ -3241,4 +3700,4 @@ async function loadPluginsWithCss(configs, baseDir, onError) {
3241
3700
  };
3242
3701
  }
3243
3702
 
3244
- export { YOUR_VERSION_LABEL, ONLINE_VERSION_LABEL, TWO_VERSIONS_OPEN, TWO_VERSIONS_CLOSE, buildDeclaredMarkerRegistry, MARKER_CSS, GUTTERPRESS_CSS, TWO_VERSIONS_CSS, TABLE_ALIGN_CSS, setLogLevel, debug, info, warn, error, log, slugify, prettify, parseSrcsetUrlCandidates, collectHtmlImageRefs, createMarkdownRenderer, applyPlugins, collectPluginCss, collectPluginStylePaths, collectPluginStyleGroups, resolveDeclaredStyles, package_default, PACKAGE_META, PACKAGE_VERSION, EXTENSION_MANIFEST_FILENAME, readExtensionMeta, extensionStyleList, extensionEntry, extensionCarries, pathEscapesFolder, assertExtensionContained, resolveExtension, __resetPathPluginCacheForTests, loadPlugin, loadPublishFunction, loadPlugins, loadPluginsWithCss };
3703
+ export { YOUR_VERSION_LABEL, ONLINE_VERSION_LABEL, TWO_VERSIONS_OPEN, TWO_VERSIONS_CLOSE, buildDeclaredMarkerRegistry, MARKER_CSS, GUTTERPRESS_CSS, TWO_VERSIONS_CSS, TABLE_ALIGN_CSS, slugify, prettify, setLogLevel, debug, info, warn, error, log, parseSrcsetUrlCandidates, collectHtmlImageRefs, createMarkdownRenderer, applyPlugins, collectPluginCss, collectPluginStylePaths, collectPluginStyleGroups, resolveDeclaredStyles, package_default, PACKAGE_META, PACKAGE_VERSION, EXTENSION_MANIFEST_FILENAME, readExtensionMeta, extensionStyleList, extensionEntry, extensionCarries, pathEscapesFolder, assertExtensionContained, resolveExtension, __resetPathPluginCacheForTests, loadPlugin, loadPublishFunction, loadPlugins, loadPluginsWithCss };