@hyperbook/markdown 0.45.0 → 0.46.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.
package/dist/index.js CHANGED
@@ -61513,7 +61513,27 @@ var en_default = {
61513
61513
  "webide-reset": "Reset",
61514
61514
  "webide-reset-prompt": "Are you sure you want to reset the code?",
61515
61515
  "webide-copy": "Copy",
61516
- "webide-download": "Download"
61516
+ "webide-download": "Download",
61517
+ "typst-code": "Typst",
61518
+ "typst-reset": "Reset",
61519
+ "typst-reset-prompt": "Are you sure you want to reset the code?",
61520
+ "typst-download-pdf": "Download PDF",
61521
+ "typst-pdf-error": "Error exporting PDF",
61522
+ "typst-download-project": "Download Project",
61523
+ "typst-loading": "Loading Typst...",
61524
+ "typst-add-source-file": "Add source file",
61525
+ "typst-add-binary-file": "Add binary file",
61526
+ "typst-source": "Source",
61527
+ "typst-binary": "Binary",
61528
+ "typst-add": "Add",
61529
+ "typst-delete-file": "Delete file",
61530
+ "typst-delete-confirm": "Delete",
61531
+ "typst-filename-prompt": "Enter filename (e.g., helper.typ):",
61532
+ "typst-filename-error": "Filename must end with .typ or .typst",
61533
+ "typst-filename-exists": "File already exists",
61534
+ "typst-file-replace": "Replace existing file?",
61535
+ "typst-binary-files": "Binary Files",
61536
+ "typst-no-binary-files": "No binary files"
61517
61537
  };
61518
61538
 
61519
61539
  // locales/de.json
@@ -61572,7 +61592,27 @@ var de_default = {
61572
61592
  "webide-reset": "Zur\xFCcksetzen",
61573
61593
  "webide-reset-prompt": "Sind Sie sicher, dass Sie den Code zur\xFCcksetzen m\xF6chten?",
61574
61594
  "webide-copy": "Kopieren",
61575
- "webide-download": "Herunterladen"
61595
+ "webide-download": "Herunterladen",
61596
+ "typst-code": "Typst",
61597
+ "typst-reset": "Zur\xFCcksetzen",
61598
+ "typst-reset-prompt": "Sind Sie sicher, dass Sie den Code zur\xFCcksetzen m\xF6chten?",
61599
+ "typst-download-pdf": "PDF herunterladen",
61600
+ "typst-pdf-error": "Fehler beim PDF-Export",
61601
+ "typst-download-project": "Projekt herunterladen",
61602
+ "typst-loading": "Typst wird geladen...",
61603
+ "typst-add-source-file": "Quelldatei hinzuf\xFCgen",
61604
+ "typst-add-binary-file": "Bin\xE4rdatei hinzuf\xFCgen",
61605
+ "typst-source": "Quelle",
61606
+ "typst-binary": "Bin\xE4r",
61607
+ "typst-add": "Hinzuf\xFCgen",
61608
+ "typst-delete-file": "Datei l\xF6schen",
61609
+ "typst-delete-confirm": "L\xF6schen",
61610
+ "typst-filename-prompt": "Dateiname eingeben (z.B. helper.typ):",
61611
+ "typst-filename-error": "Dateiname muss auf .typ oder .typst enden",
61612
+ "typst-filename-exists": "Datei existiert bereits",
61613
+ "typst-file-replace": "Existierende Datei ersetzen?",
61614
+ "typst-binary-files": "Bin\xE4rdateien",
61615
+ "typst-no-binary-files": "Keine Bin\xE4rdateien"
61576
61616
  };
61577
61617
 
61578
61618
  // src/i18n.ts
@@ -62766,6 +62806,15 @@ window.Prism.manual = true;`
62766
62806
  },
62767
62807
  children: []
62768
62808
  },
62809
+ {
62810
+ type: "element",
62811
+ tagName: "script",
62812
+ properties: {
62813
+ src: makeUrl(["prism", "prism-typst.js"], "assets"),
62814
+ defer: true
62815
+ },
62816
+ children: []
62817
+ },
62769
62818
  {
62770
62819
  type: "element",
62771
62820
  tagName: "link",
@@ -78955,6 +79004,378 @@ var remarkDirectiveTextinput_default = (ctx) => () => {
78955
79004
  };
78956
79005
  };
78957
79006
 
79007
+ // src/remarkDirectiveTypst.ts
79008
+ function htmlEntities4(str) {
79009
+ return String(str).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
79010
+ }
79011
+ var remarkDirectiveTypst_default = (ctx) => () => {
79012
+ const name = "typst";
79013
+ return (tree, file) => {
79014
+ visit(tree, function(node3) {
79015
+ if (isDirective(node3) && node3.name === name) {
79016
+ const {
79017
+ height = "auto",
79018
+ id = hash(node3),
79019
+ mode = "preview"
79020
+ } = node3.attributes || {};
79021
+ const data = node3.data || (node3.data = {});
79022
+ expectContainerDirective(node3, file, name);
79023
+ registerDirective(file, name, ["client.js"], ["style.css"], []);
79024
+ requestJS(file, ["code-input", "code-input.min.js"]);
79025
+ requestCSS(file, ["code-input", "code-input.min.css"]);
79026
+ requestJS(file, ["code-input", "auto-close-brackets.min.js"]);
79027
+ requestJS(file, ["code-input", "indent.min.js"]);
79028
+ requestJS(file, ["uzip", "uzip.js"]);
79029
+ const sourceFiles = [];
79030
+ const binaryFiles = [];
79031
+ for (const child of node3.children) {
79032
+ if (child.type === "text") {
79033
+ const text9 = child.value;
79034
+ const fileMatches = text9.matchAll(
79035
+ /@file\s+dest="([^"]+)"\s+src="([^"]+)"/g
79036
+ );
79037
+ for (const match of fileMatches) {
79038
+ const dest = match[1];
79039
+ const src = match[2];
79040
+ const url = ctx.makeUrl(
79041
+ src,
79042
+ "public",
79043
+ ctx.navigation.current || void 0
79044
+ );
79045
+ binaryFiles.push({ dest, url });
79046
+ }
79047
+ const sourceMatches = text9.matchAll(
79048
+ /@source\s+dest="([^"]+)"\s+src="([^"]+)"/g
79049
+ );
79050
+ for (const match of sourceMatches) {
79051
+ const dest = match[1];
79052
+ const src = match[2];
79053
+ const content5 = readFile(src, ctx) || "";
79054
+ sourceFiles.push({ filename: dest, content: content5 });
79055
+ }
79056
+ } else if (child.type === "paragraph") {
79057
+ for (const textNode of child.children) {
79058
+ if (textNode.type === "text") {
79059
+ const text9 = textNode.value;
79060
+ const fileMatches = text9.matchAll(
79061
+ /@file\s+dest="([^"]+)"\s+src="([^"]+)"/g
79062
+ );
79063
+ for (const match of fileMatches) {
79064
+ const dest = match[1];
79065
+ const src = match[2];
79066
+ const url = ctx.makeUrl(
79067
+ src,
79068
+ "public",
79069
+ ctx.navigation.current || void 0
79070
+ );
79071
+ binaryFiles.push({ dest, url });
79072
+ }
79073
+ const sourceMatches = text9.matchAll(
79074
+ /@source\s+dest="([^"]+)"\s+src="([^"]+)"/g
79075
+ );
79076
+ for (const match of sourceMatches) {
79077
+ const dest = match[1];
79078
+ const src = match[2];
79079
+ const content5 = readFile(src, ctx) || "";
79080
+ sourceFiles.push({ filename: dest, content: content5 });
79081
+ }
79082
+ }
79083
+ }
79084
+ }
79085
+ }
79086
+ const codeBlocks = node3.children.filter(
79087
+ (n) => n.type === "code" && (n.lang === "typ" || n.lang === "typst")
79088
+ );
79089
+ if (codeBlocks.length > 0) {
79090
+ for (const codeBlock of codeBlocks) {
79091
+ const filename = codeBlock.meta?.trim() || "main.typ";
79092
+ sourceFiles.push({
79093
+ filename,
79094
+ content: codeBlock.value
79095
+ });
79096
+ }
79097
+ }
79098
+ let mainSource = sourceFiles.find(
79099
+ (f) => f.filename == "main.typ" || f.filename == "main.typst"
79100
+ );
79101
+ if (!mainSource && sourceFiles.length > 0) {
79102
+ mainSource = sourceFiles[0];
79103
+ } else if (!mainSource) {
79104
+ mainSource = { filename: "main.typ", content: "" };
79105
+ }
79106
+ const isEditMode = mode === "edit";
79107
+ const isPreviewMode = mode === "preview" || !isEditMode;
79108
+ data.hName = "div";
79109
+ data.hProperties = {
79110
+ class: ["directive-typst", isPreviewMode ? "preview-only" : ""].join(" ").trim(),
79111
+ "data-id": id,
79112
+ "data-source-files": Buffer.from(
79113
+ JSON.stringify(sourceFiles)
79114
+ ).toString("base64"),
79115
+ "data-binary-files": Buffer.from(
79116
+ JSON.stringify(binaryFiles)
79117
+ ).toString("base64")
79118
+ };
79119
+ const previewContainer = {
79120
+ type: "element",
79121
+ tagName: "div",
79122
+ properties: {
79123
+ class: "preview-container",
79124
+ style: `height: ${height};`
79125
+ },
79126
+ children: [
79127
+ {
79128
+ type: "element",
79129
+ tagName: "div",
79130
+ properties: {
79131
+ class: "typst-loading"
79132
+ },
79133
+ children: [
79134
+ {
79135
+ type: "element",
79136
+ tagName: "div",
79137
+ properties: {
79138
+ class: "typst-spinner"
79139
+ },
79140
+ children: []
79141
+ },
79142
+ {
79143
+ type: "element",
79144
+ tagName: "span",
79145
+ properties: {},
79146
+ children: [
79147
+ {
79148
+ type: "text",
79149
+ value: i18n.get("typst-loading")
79150
+ }
79151
+ ]
79152
+ }
79153
+ ]
79154
+ },
79155
+ {
79156
+ type: "element",
79157
+ tagName: "div",
79158
+ properties: {
79159
+ class: "typst-preview"
79160
+ },
79161
+ children: []
79162
+ }
79163
+ ]
79164
+ };
79165
+ const downloadButton = {
79166
+ type: "element",
79167
+ tagName: "button",
79168
+ properties: {
79169
+ class: "download-pdf"
79170
+ },
79171
+ children: [
79172
+ {
79173
+ type: "text",
79174
+ value: i18n.get("typst-download-pdf")
79175
+ }
79176
+ ]
79177
+ };
79178
+ const downloadProjectButton = {
79179
+ type: "element",
79180
+ tagName: "button",
79181
+ properties: {
79182
+ class: "download-project"
79183
+ },
79184
+ children: [
79185
+ {
79186
+ type: "text",
79187
+ value: i18n.get("typst-download-project")
79188
+ }
79189
+ ]
79190
+ };
79191
+ if (isEditMode) {
79192
+ data.hChildren = [
79193
+ previewContainer,
79194
+ {
79195
+ type: "element",
79196
+ tagName: "div",
79197
+ properties: {
79198
+ class: "editor-container"
79199
+ },
79200
+ children: [
79201
+ {
79202
+ type: "element",
79203
+ tagName: "div",
79204
+ properties: {
79205
+ class: "file-tabs"
79206
+ },
79207
+ children: [
79208
+ {
79209
+ type: "element",
79210
+ tagName: "div",
79211
+ properties: {
79212
+ class: "tabs-list"
79213
+ },
79214
+ children: []
79215
+ },
79216
+ {
79217
+ type: "element",
79218
+ tagName: "button",
79219
+ properties: {
79220
+ class: "add-source-file",
79221
+ title: i18n.get("typst-add-source-file")
79222
+ },
79223
+ children: [
79224
+ {
79225
+ type: "text",
79226
+ value: "+"
79227
+ }
79228
+ ]
79229
+ }
79230
+ ]
79231
+ },
79232
+ {
79233
+ type: "element",
79234
+ tagName: "details",
79235
+ properties: {
79236
+ class: "binary-files-section"
79237
+ },
79238
+ children: [
79239
+ {
79240
+ type: "element",
79241
+ tagName: "summary",
79242
+ properties: {},
79243
+ children: [
79244
+ {
79245
+ type: "element",
79246
+ tagName: "span",
79247
+ properties: {
79248
+ class: "summary-text"
79249
+ },
79250
+ children: [
79251
+ {
79252
+ type: "element",
79253
+ tagName: "span",
79254
+ properties: {
79255
+ class: "summary-indicator"
79256
+ },
79257
+ children: [
79258
+ {
79259
+ type: "text",
79260
+ value: "\u25B6"
79261
+ }
79262
+ ]
79263
+ },
79264
+ {
79265
+ type: "text",
79266
+ value: i18n.get("typst-binary-files")
79267
+ }
79268
+ ]
79269
+ }
79270
+ ]
79271
+ },
79272
+ {
79273
+ type: "element",
79274
+ tagName: "div",
79275
+ properties: {
79276
+ class: "binary-files-list"
79277
+ },
79278
+ children: []
79279
+ },
79280
+ {
79281
+ type: "element",
79282
+ tagName: "div",
79283
+ properties: {
79284
+ class: "binary-files-actions"
79285
+ },
79286
+ children: [
79287
+ {
79288
+ type: "element",
79289
+ tagName: "button",
79290
+ properties: {
79291
+ class: "add-binary-file",
79292
+ title: i18n.get("typst-add-binary-file")
79293
+ },
79294
+ children: [
79295
+ {
79296
+ type: "text",
79297
+ value: "+ " + i18n.get("typst-add")
79298
+ }
79299
+ ]
79300
+ }
79301
+ ]
79302
+ }
79303
+ ]
79304
+ },
79305
+ {
79306
+ type: "element",
79307
+ tagName: "code-input",
79308
+ properties: {
79309
+ class: "editor typst active line-numbers",
79310
+ language: "typst",
79311
+ template: "typst-highlighted"
79312
+ },
79313
+ children: [
79314
+ {
79315
+ type: "raw",
79316
+ value: htmlEntities4(mainSource.content)
79317
+ }
79318
+ ]
79319
+ },
79320
+ {
79321
+ type: "element",
79322
+ tagName: "div",
79323
+ properties: {
79324
+ class: "buttons bottom"
79325
+ },
79326
+ children: [
79327
+ {
79328
+ type: "element",
79329
+ tagName: "button",
79330
+ properties: {
79331
+ class: "reset"
79332
+ },
79333
+ children: [
79334
+ {
79335
+ type: "text",
79336
+ value: i18n.get("typst-reset")
79337
+ }
79338
+ ]
79339
+ },
79340
+ downloadProjectButton,
79341
+ downloadButton
79342
+ ]
79343
+ }
79344
+ ]
79345
+ }
79346
+ ];
79347
+ } else {
79348
+ data.hChildren = [
79349
+ previewContainer,
79350
+ {
79351
+ type: "element",
79352
+ tagName: "div",
79353
+ properties: {
79354
+ class: "buttons bottom"
79355
+ },
79356
+ children: [downloadProjectButton, downloadButton]
79357
+ },
79358
+ {
79359
+ type: "element",
79360
+ tagName: "textarea",
79361
+ properties: {
79362
+ class: "typst-source hidden",
79363
+ style: "display: none;"
79364
+ },
79365
+ children: [
79366
+ {
79367
+ type: "text",
79368
+ value: mainSource.content
79369
+ }
79370
+ ]
79371
+ }
79372
+ ];
79373
+ }
79374
+ }
79375
+ });
79376
+ };
79377
+ };
79378
+
78958
79379
  // src/process.ts
78959
79380
  var remark = (ctx) => {
78960
79381
  i18n.init(ctx.config.language || "en");
@@ -78999,6 +79420,7 @@ var remark = (ctx) => {
78999
79420
  remarkDirectiveMultievent_default(ctx),
79000
79421
  remarkDirectiveLearningmap_default(ctx),
79001
79422
  remarkDirectiveTextinput_default(ctx),
79423
+ remarkDirectiveTypst_default(ctx),
79002
79424
  remarkCode_default(ctx),
79003
79425
  remarkMath,
79004
79426
  /* needs to be last directive */