@hyperbook/markdown 0.23.1 → 0.24.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/dist/index.js CHANGED
@@ -63702,11 +63702,19 @@ function hash(object) {
63702
63702
  }
63703
63703
 
63704
63704
  // src/remarkDirectiveTabs.ts
63705
- var remarkDirectiveTabs_default = (ctx) => () => {
63706
- return (tree, file) => {
63707
- visit(tree, function(node3) {
63708
- if (isDirective(node3)) {
63709
- if (node3.name !== "tabs") return;
63705
+ function remarkDirectiveTabs_default(ctx) {
63706
+ return function() {
63707
+ const self2 = this;
63708
+ return async (tree, file) => {
63709
+ const tabsNodes = [];
63710
+ visit(tree, function(node3) {
63711
+ if (isDirective(node3)) {
63712
+ if (node3.name !== "tabs") return;
63713
+ tabsNodes.push(node3);
63714
+ return;
63715
+ }
63716
+ });
63717
+ for (const node3 of tabsNodes) {
63710
63718
  const data = node3.data || (node3.data = {});
63711
63719
  if (node3.name === "tabs") {
63712
63720
  expectContainerDirective(node3, file, "tabs");
@@ -63722,9 +63730,9 @@ var remarkDirectiveTabs_default = (ctx) => () => {
63722
63730
  const tabContentElements = [];
63723
63731
  const tabTitleElements = [];
63724
63732
  let first = true;
63725
- node3.children.filter(isDirective).forEach((node4) => {
63726
- expectContainerDirective(node4, file, "tab");
63727
- let { title = "", id: tabId = hash(node4) } = node4.attributes || {};
63733
+ for (const tabNode of node3.children.filter(isDirective)) {
63734
+ expectContainerDirective(tabNode, file, "tab");
63735
+ let { title = "", id: tabId = hash(tabNode) } = tabNode.attributes || {};
63728
63736
  let tree2 = remark(ctx).parse(title);
63729
63737
  remarkGemoji()(tree2);
63730
63738
  let hastTree = toHast(tree2);
@@ -63742,6 +63750,7 @@ var remarkDirectiveTabs_default = (ctx) => () => {
63742
63750
  },
63743
63751
  children: hastTree.children || []
63744
63752
  });
63753
+ const tabContent = await remark(ctx).run(tabNode);
63745
63754
  tabContentElements.push({
63746
63755
  type: "element",
63747
63756
  tagName: "div",
@@ -63750,10 +63759,10 @@ var remarkDirectiveTabs_default = (ctx) => () => {
63750
63759
  "data-tab-id": tabId,
63751
63760
  "data-tabs-id": tabsId
63752
63761
  },
63753
- children: toHast(node4)?.children
63762
+ children: [tabContent]
63754
63763
  });
63755
63764
  first = false;
63756
- });
63765
+ }
63757
63766
  data.hChildren = [
63758
63767
  {
63759
63768
  type: "element",
@@ -63768,9 +63777,9 @@ var remarkDirectiveTabs_default = (ctx) => () => {
63768
63777
  ];
63769
63778
  }
63770
63779
  }
63771
- });
63780
+ };
63772
63781
  };
63773
- };
63782
+ }
63774
63783
 
63775
63784
  // src/remarkDirectiveSqlIde.ts
63776
63785
  var remarkDirectiveSqlIde_default = (ctx) => () => {
@@ -63913,7 +63922,15 @@ var en_default = {
63913
63922
  "slideshow-previous": "Previous",
63914
63923
  "slideshow-next": "Next",
63915
63924
  "slideshow-jump-to": "Jump to {{index}}",
63916
- "toggle-bookmark": "Toggle Bookmark"
63925
+ "toggle-bookmark": "Toggle Bookmark",
63926
+ "webide-code-preview": "Code Preview",
63927
+ "webide-html": "HTML",
63928
+ "webide-css": "CSS",
63929
+ "webide-js": "JS",
63930
+ "webide-reset": "Reset",
63931
+ "webide-reset-prompt": "Are you sure you want to reset the code?",
63932
+ "webide-copy": "Copy",
63933
+ "webide-download": "Download"
63917
63934
  };
63918
63935
 
63919
63936
  // locales/de.json
@@ -63955,7 +63972,15 @@ var de_default = {
63955
63972
  "slideshow-previous": "Zur\xFCck",
63956
63973
  "slideshow-next": "Weiter",
63957
63974
  "slideshow-jump-to": "Springe zu {{index}}",
63958
- "toggle-bookmark": "Lesezeichen umschalten"
63975
+ "toggle-bookmark": "Lesezeichen umschalten",
63976
+ "webide-code-preview": "Code-Vorschau",
63977
+ "webide-html": "HTML",
63978
+ "webide-css": "CSS",
63979
+ "webide-js": "JS",
63980
+ "webide-reset": "Zur\xFCcksetzen",
63981
+ "webide-reset-prompt": "Sind Sie sicher, dass Sie den Code zur\xFCcksetzen m\xF6chten?",
63982
+ "webide-copy": "Kopieren",
63983
+ "webide-download": "Herunterladen"
63959
63984
  };
63960
63985
 
63961
63986
  // src/i18n.ts
@@ -66656,48 +66681,55 @@ var remarkDirectiveCollapsible_default = (ctx) => () => {
66656
66681
  }
66657
66682
  return [element5];
66658
66683
  };
66659
- return (tree, file) => {
66684
+ const collapsibleNodes = [];
66685
+ return async (tree, file) => {
66660
66686
  visit(tree, function(node3) {
66661
66687
  if (isDirective(node3)) {
66662
66688
  if (node3.name !== name) return;
66663
- const data = node3.data || (node3.data = {});
66664
- const { title = "", id } = node3.data.hProperties || {};
66665
- expectContainerDirective(node3, file, name);
66666
- registerDirective(file, name, [], ["style.css"]);
66667
- node3.attributes = {};
66668
- data.hName = "div";
66669
- data.hProperties = {
66670
- class: "directive-collapsible",
66671
- "data-id": id
66672
- };
66673
- const children = toHast(node3)?.children.flatMap(
66674
- transformCollapsible
66675
- );
66676
- data.hChildren = [
66677
- {
66678
- type: "element",
66679
- tagName: "button",
66680
- properties: {
66681
- class: "collapsible"
66682
- },
66683
- children: [
66684
- {
66685
- type: "text",
66686
- value: title
66687
- }
66688
- ]
66689
- },
66690
- {
66691
- type: "element",
66692
- tagName: "div",
66693
- properties: {
66694
- class: "collapsible-content"
66695
- },
66696
- children
66697
- }
66698
- ];
66689
+ collapsibleNodes.push(node3);
66690
+ return;
66699
66691
  }
66700
66692
  });
66693
+ for (const node3 of collapsibleNodes) {
66694
+ const data = node3.data || (node3.data = {});
66695
+ const { title = "", id } = node3.data.hProperties || {};
66696
+ expectContainerDirective(node3, file, name);
66697
+ registerDirective(file, name, [], ["style.css"]);
66698
+ node3.attributes = {};
66699
+ data.hName = "div";
66700
+ data.hProperties = {
66701
+ class: "directive-collapsible",
66702
+ "data-id": id
66703
+ };
66704
+ const collapsibleContent = [];
66705
+ for (const child of node3.children) {
66706
+ collapsibleContent.push(await remark(ctx).run(child));
66707
+ }
66708
+ console.log(collapsibleContent);
66709
+ data.hChildren = [
66710
+ {
66711
+ type: "element",
66712
+ tagName: "button",
66713
+ properties: {
66714
+ class: "collapsible"
66715
+ },
66716
+ children: [
66717
+ {
66718
+ type: "text",
66719
+ value: title
66720
+ }
66721
+ ]
66722
+ },
66723
+ {
66724
+ type: "element",
66725
+ tagName: "div",
66726
+ properties: {
66727
+ class: "collapsible-content"
66728
+ },
66729
+ children: collapsibleContent
66730
+ }
66731
+ ];
66732
+ }
66701
66733
  };
66702
66734
  };
66703
66735
 
@@ -73243,9 +73275,6 @@ var rehypeDirectiveP5_default = (ctx) => () => {
73243
73275
  path4.posix.join("directive-p5", "p5.min.js"),
73244
73276
  "assets"
73245
73277
  );
73246
- const escape2 = (s3) => {
73247
- return s3.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
73248
- };
73249
73278
  const wrapSketch = (sketchCode) => {
73250
73279
  if (sketchCode !== "" && !sketchCode?.includes("setup")) {
73251
73280
  return `
@@ -73872,6 +73901,256 @@ var remarkDirectivePyide_default = (ctx) => () => {
73872
73901
  };
73873
73902
  };
73874
73903
 
73904
+ // src/remarkDirectiveWebide.ts
73905
+ var remarkDirectiveWebide_default = (ctx) => () => {
73906
+ const name = "webide";
73907
+ const makeWrapInMarkupTemplate = () => `<!DOCTYPE html>
73908
+ <head>
73909
+ <title>WebIDE</title>
73910
+ <meta charset="utf8" />
73911
+ <style type='text/css'>
73912
+ html, body {
73913
+ margin: 0;
73914
+ padding: 0;
73915
+ background: white;
73916
+ }
73917
+ ###CSS###
73918
+ </style>
73919
+ </head>
73920
+ <body>###HTML###</body>
73921
+ <script type="text/javascript">###JS###</script>
73922
+ `;
73923
+ return (tree, file) => {
73924
+ visit(tree, function(node3) {
73925
+ if (isDirective(node3) && node3.name === name) {
73926
+ const { height = 400, id = hash(node3) } = node3.attributes || {};
73927
+ const data = node3.data || (node3.data = {});
73928
+ expectContainerDirective(node3, file, name);
73929
+ registerDirective(file, name, ["client.js"], ["style.css"]);
73930
+ requestJS(file, ["code-input", "code-input.min.js"]);
73931
+ requestCSS(file, ["code-input", "code-input.min.css"]);
73932
+ requestJS(file, ["code-input", "auto-close-brackets.min.js"]);
73933
+ requestJS(file, ["code-input", "indent.min.js"]);
73934
+ let js = "";
73935
+ let css = "";
73936
+ let html11 = "";
73937
+ let template = makeWrapInMarkupTemplate();
73938
+ let jsNode = node3.children.find(
73939
+ (n) => n.type === "code" && n.lang === "js"
73940
+ );
73941
+ let cssNode = node3.children.find(
73942
+ (n) => n.type === "code" && n.lang === "css"
73943
+ );
73944
+ let htmlNode = node3.children.find(
73945
+ (n) => n.type === "code" && n.lang === "html" && n.meta === null
73946
+ );
73947
+ let templateNode = node3.children.find(
73948
+ (n) => n.type === "code" && n.lang === "html" && n.meta === "template"
73949
+ );
73950
+ const buttons = [];
73951
+ const editors = [];
73952
+ if (htmlNode) {
73953
+ html11 = htmlNode.value;
73954
+ buttons.push({
73955
+ type: "element",
73956
+ tagName: "button",
73957
+ properties: {
73958
+ class: "html"
73959
+ },
73960
+ children: [
73961
+ {
73962
+ type: "text",
73963
+ value: i18n.get("webide-html")
73964
+ }
73965
+ ]
73966
+ });
73967
+ editors.push({
73968
+ type: "element",
73969
+ tagName: "code-input",
73970
+ properties: {
73971
+ class: "editor html line-numbers",
73972
+ language: "html",
73973
+ template: "webide-highlighted"
73974
+ },
73975
+ children: [
73976
+ {
73977
+ type: "raw",
73978
+ value: html11
73979
+ }
73980
+ ]
73981
+ });
73982
+ }
73983
+ if (cssNode) {
73984
+ css = cssNode.value;
73985
+ buttons.push({
73986
+ type: "element",
73987
+ tagName: "button",
73988
+ properties: {
73989
+ class: "css"
73990
+ },
73991
+ children: [
73992
+ {
73993
+ type: "text",
73994
+ value: i18n.get("webide-css")
73995
+ }
73996
+ ]
73997
+ });
73998
+ editors.push({
73999
+ type: "element",
74000
+ tagName: "code-input",
74001
+ properties: {
74002
+ class: "editor css line-numbers",
74003
+ language: "css",
74004
+ template: "webide-highlighted"
74005
+ },
74006
+ children: [
74007
+ {
74008
+ type: "raw",
74009
+ value: css
74010
+ }
74011
+ ]
74012
+ });
74013
+ }
74014
+ if (jsNode) {
74015
+ js = jsNode.value;
74016
+ buttons.push({
74017
+ type: "element",
74018
+ tagName: "button",
74019
+ properties: {
74020
+ class: "js"
74021
+ },
74022
+ children: [
74023
+ {
74024
+ type: "text",
74025
+ value: i18n.get("webide-js")
74026
+ }
74027
+ ]
74028
+ });
74029
+ editors.push({
74030
+ type: "element",
74031
+ tagName: "code-input",
74032
+ properties: {
74033
+ class: "editor js line-numbers",
74034
+ language: "javascript",
74035
+ template: "webide-highlighted"
74036
+ },
74037
+ children: [
74038
+ {
74039
+ type: "raw",
74040
+ value: js
74041
+ }
74042
+ ]
74043
+ });
74044
+ }
74045
+ if (buttons.length > 0) {
74046
+ buttons[0].properties.class += " active";
74047
+ }
74048
+ if (editors.length > 0) {
74049
+ editors[0].properties.class += " active";
74050
+ }
74051
+ if (templateNode) template = templateNode.value;
74052
+ const srcdoc = template.replace("###JS###", js).replace("###HTML###", html11).replace("###CSS###", css).replace(/\u00A0/g, " ");
74053
+ data.hName = "div";
74054
+ data.hProperties = {
74055
+ class: "directive-webide",
74056
+ "data-template": template.replace(/\u00A0/g, " "),
74057
+ "data-id": id
74058
+ };
74059
+ data.hChildren = [
74060
+ {
74061
+ type: "element",
74062
+ tagName: "div",
74063
+ properties: {
74064
+ class: "container",
74065
+ style: `height: ${height}px;`
74066
+ },
74067
+ children: [
74068
+ {
74069
+ type: "element",
74070
+ tagName: "div",
74071
+ properties: {
74072
+ class: "container-title"
74073
+ },
74074
+ children: [
74075
+ {
74076
+ type: "text",
74077
+ value: ""
74078
+ }
74079
+ ]
74080
+ },
74081
+ {
74082
+ type: "element",
74083
+ tagName: "iframe",
74084
+ properties: {
74085
+ srcdoc,
74086
+ loading: "eager",
74087
+ sandbox: "allow-scripts allow-popups allow-modals allow-forms allow-same-origin",
74088
+ "aria-label": i18n.get("webide-code-preview"),
74089
+ title: i18n.get("webide-code-preview")
74090
+ },
74091
+ children: []
74092
+ }
74093
+ ]
74094
+ },
74095
+ {
74096
+ type: "element",
74097
+ tagName: "div",
74098
+ properties: {
74099
+ class: "editor-container"
74100
+ },
74101
+ children: [
74102
+ {
74103
+ type: "element",
74104
+ tagName: "div",
74105
+ properties: {
74106
+ class: "buttons"
74107
+ },
74108
+ children: buttons
74109
+ },
74110
+ ...editors,
74111
+ {
74112
+ type: "element",
74113
+ tagName: "div",
74114
+ properties: {
74115
+ class: "buttons bottom"
74116
+ },
74117
+ children: [
74118
+ {
74119
+ type: "element",
74120
+ tagName: "button",
74121
+ properties: {
74122
+ class: "reset"
74123
+ },
74124
+ children: [
74125
+ {
74126
+ type: "text",
74127
+ value: i18n.get("webide-reset")
74128
+ }
74129
+ ]
74130
+ },
74131
+ {
74132
+ type: "element",
74133
+ tagName: "button",
74134
+ properties: {
74135
+ class: "download"
74136
+ },
74137
+ children: [
74138
+ {
74139
+ type: "text",
74140
+ value: i18n.get("webide-download")
74141
+ }
74142
+ ]
74143
+ }
74144
+ ]
74145
+ }
74146
+ ]
74147
+ }
74148
+ ];
74149
+ }
74150
+ });
74151
+ };
74152
+ };
74153
+
73875
74154
  // src/process.ts
73876
74155
  var remark = (ctx) => {
73877
74156
  const remarkPlugins = [
@@ -73908,6 +74187,7 @@ var remark = (ctx) => {
73908
74187
  remarkDirectiveExcalidraw_default(ctx),
73909
74188
  remarkDirectiveStruktog_default(ctx),
73910
74189
  remarkDirectiveGeogebra_default(ctx),
74190
+ remarkDirectiveWebide_default(ctx),
73911
74191
  remarkCode_default(ctx),
73912
74192
  remarkMath,
73913
74193
  remarkUnwrapImages,
@@ -73916,6 +74196,12 @@ var remark = (ctx) => {
73916
74196
  remarkCollectHeadings_default(ctx),
73917
74197
  remarkCollectSearchDocuments_default(ctx)
73918
74198
  ];
74199
+ return unified().use(remarkParse).use(remarkPlugins).use(remarkRehype, {
74200
+ allowDangerousHtml: ctx.config.allowDangerousHtml || false
74201
+ });
74202
+ };
74203
+ var process2 = (md, ctx) => {
74204
+ i18n.init(ctx.config.language || "en");
73919
74205
  const rehypePlugins = [
73920
74206
  rehypeTableOfContents_default(ctx),
73921
74207
  rehypeQrCode_default(ctx),
@@ -73939,13 +74225,7 @@ var remark = (ctx) => {
73939
74225
  ],
73940
74226
  rehypeFormat
73941
74227
  ];
73942
- return unified().use(remarkParse).use(remarkPlugins).use(remarkRehype, {
73943
- allowDangerousHtml: ctx.config.allowDangerousHtml || false
73944
- }).use(rehypePlugins);
73945
- };
73946
- var process2 = (md, ctx) => {
73947
- i18n.init(ctx.config.language || "en");
73948
- return remark(ctx).use(rehypeShell_default(ctx)).use(rehypeHtmlStructure_default(ctx)).use(rehypeStringify, {
74228
+ return remark(ctx).use(rehypePlugins).use(rehypeShell_default(ctx)).use(rehypeHtmlStructure_default(ctx)).use(rehypeStringify, {
73949
74229
  allowDangerousCharacters: true,
73950
74230
  allowDangerousHtml: ctx.config.allowDangerousHtml || false
73951
74231
  }).process(md);