@noirmd/previewer 1.2.0 → 2.0.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.
Files changed (53) hide show
  1. package/dist/NReditor.cjs +851 -895
  2. package/dist/NReditor.cjs.map +1 -1
  3. package/dist/NReditor.d.cts +1 -1
  4. package/dist/NReditor.d.ts +1 -1
  5. package/dist/NReditor.js +852 -896
  6. package/dist/NReditor.js.map +1 -1
  7. package/dist/admonition.css +55 -0
  8. package/dist/{markdown.css → base.css} +96 -126
  9. package/dist/blockquote.css +16 -0
  10. package/dist/button.css +32 -0
  11. package/dist/card.css +143 -0
  12. package/dist/codeblock.css +59 -0
  13. package/dist/core.cjs +9 -1
  14. package/dist/core.cjs.map +1 -1
  15. package/dist/core.js +9 -1
  16. package/dist/core.js.map +1 -1
  17. package/dist/details.css +45 -0
  18. package/dist/editor.css +56 -9
  19. package/dist/fonts/material-icons-round.woff2 +0 -0
  20. package/dist/index.cjs +852 -883
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +41 -70
  23. package/dist/index.d.ts +41 -70
  24. package/dist/index.js +851 -877
  25. package/dist/index.js.map +1 -1
  26. package/dist/list.css +18 -0
  27. package/dist/modal.css +82 -0
  28. package/dist/react.cjs +852 -886
  29. package/dist/react.cjs.map +1 -1
  30. package/dist/react.d.cts +44 -73
  31. package/dist/react.d.ts +44 -73
  32. package/dist/react.js +851 -880
  33. package/dist/react.js.map +1 -1
  34. package/dist/slide.css +21 -0
  35. package/dist/table.css +36 -0
  36. package/dist/toc.css +45 -0
  37. package/dist/vanilla.cjs +42 -28
  38. package/dist/vanilla.cjs.map +1 -1
  39. package/dist/vanilla.css +32 -677
  40. package/dist/vanilla.d.cts +8 -2
  41. package/dist/vanilla.d.ts +8 -2
  42. package/dist/vanilla.js +41 -28
  43. package/dist/vanilla.js.map +1 -1
  44. package/dist/variables.css +53 -0
  45. package/dist/vue.cjs +931 -1121
  46. package/dist/vue.cjs.map +1 -1
  47. package/dist/vue.d.cts +63 -214
  48. package/dist/vue.d.ts +63 -214
  49. package/dist/vue.js +930 -1120
  50. package/dist/vue.js.map +1 -1
  51. package/editor.css +56 -9
  52. package/package.json +5 -10
  53. package/markdown.css +0 -344
@@ -80,6 +80,12 @@ declare function renderTokens(tokens: Token[]): HTMLElement;
80
80
  * Convenience: parse markdown string and render directly.
81
81
  */
82
82
  declare function renderMarkdownString(markdown: string): HTMLElement;
83
+ /**
84
+ * Render a raw HTML string into a wrapper element.
85
+ * Extracts <style> blocks (injected globally into <head>) and
86
+ * force-executes any <script> tags.
87
+ */
88
+ declare function renderHtmlString(html: string): HTMLElement;
83
89
 
84
90
  /**
85
91
  * Render inline markdown text into a DocumentFragment.
@@ -90,7 +96,7 @@ declare function renderMarkdownString(markdown: string): HTMLElement;
90
96
  declare function renderInline(text: string): DocumentFragment;
91
97
 
92
98
  /**
93
- * Create a Material Symbols icon element.
99
+ * Create a Material Icons Round icon element.
94
100
  */
95
101
  declare function createIcon(iconName: string, extraClasses?: string): HTMLElement;
96
102
  /**
@@ -170,4 +176,4 @@ interface DirectiveProps {
170
176
  type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
171
177
  declare const directiveRegistry: Record<string, DirectiveRendererFn>;
172
178
 
173
- export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderInline, renderMarkdownString, renderTokens };
179
+ export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderHtmlString, renderInline, renderMarkdownString, renderTokens };
package/dist/vanilla.d.ts CHANGED
@@ -80,6 +80,12 @@ declare function renderTokens(tokens: Token[]): HTMLElement;
80
80
  * Convenience: parse markdown string and render directly.
81
81
  */
82
82
  declare function renderMarkdownString(markdown: string): HTMLElement;
83
+ /**
84
+ * Render a raw HTML string into a wrapper element.
85
+ * Extracts <style> blocks (injected globally into <head>) and
86
+ * force-executes any <script> tags.
87
+ */
88
+ declare function renderHtmlString(html: string): HTMLElement;
83
89
 
84
90
  /**
85
91
  * Render inline markdown text into a DocumentFragment.
@@ -90,7 +96,7 @@ declare function renderMarkdownString(markdown: string): HTMLElement;
90
96
  declare function renderInline(text: string): DocumentFragment;
91
97
 
92
98
  /**
93
- * Create a Material Symbols icon element.
99
+ * Create a Material Icons Round icon element.
94
100
  */
95
101
  declare function createIcon(iconName: string, extraClasses?: string): HTMLElement;
96
102
  /**
@@ -170,4 +176,4 @@ interface DirectiveProps {
170
176
  type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
171
177
  declare const directiveRegistry: Record<string, DirectiveRendererFn>;
172
178
 
173
- export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderInline, renderMarkdownString, renderTokens };
179
+ export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderHtmlString, renderInline, renderMarkdownString, renderTokens };
package/dist/vanilla.js CHANGED
@@ -1647,6 +1647,7 @@ function parseMarkdown(markdown2) {
1647
1647
  if (!markdown2) return [];
1648
1648
  const lines = markdown2.replace(/\r\n/g, "\n").replace(/\r/g, "").split("\n");
1649
1649
  const result = [];
1650
+ const usedIds = /* @__PURE__ */ new Set();
1650
1651
  let i = 0;
1651
1652
  while (i < lines.length) {
1652
1653
  const line = lines[i];
@@ -1656,7 +1657,14 @@ function parseMarkdown(markdown2) {
1656
1657
  const level = match[1].length;
1657
1658
  const rawText = match[2];
1658
1659
  const { text: text2, classes: classes2, id: customId } = extractAttributes(rawText);
1659
- const id2 = customId || generateId(text2.replace(/->|<-/g, ""));
1660
+ const baseId = customId || generateId(text2.replace(/->|<-/g, ""));
1661
+ let id2 = baseId;
1662
+ let n = 1;
1663
+ while (usedIds.has(id2)) {
1664
+ n++;
1665
+ id2 = `${baseId}-${n}`;
1666
+ }
1667
+ usedIds.add(id2);
1660
1668
  result.push({ type: "header", level, text: text2, id: id2, classes: classes2 || void 0 });
1661
1669
  i++;
1662
1670
  continue;
@@ -10908,7 +10916,7 @@ var highlightSetup_default = core_default;
10908
10916
  // vanilla/components.ts
10909
10917
  function createIcon(iconName, extraClasses) {
10910
10918
  const span = document.createElement("span");
10911
- const cls = `nr-icon material-symbols-rounded${extraClasses ? ` ${extraClasses}` : ""}`;
10919
+ const cls = `nr-icon material-icons-round${extraClasses ? ` ${extraClasses}` : ""}`;
10912
10920
  span.className = cls;
10913
10921
  span.setAttribute("aria-hidden", "true");
10914
10922
  const isCodepoint = /^[eE][0-9a-fA-F]{3,4}$/.test(iconName);
@@ -10970,7 +10978,7 @@ var DEFAULT_ADMONITION_ICONS = {
10970
10978
  info: "lightbulb",
10971
10979
  warning: "warning",
10972
10980
  danger: "report",
10973
- greentext: "subdirectory_play_arrow"
10981
+ greentext: "subdirectory_arrow_right"
10974
10982
  };
10975
10983
  function createAdmonition(type, title, icon) {
10976
10984
  const el = document.createElement("div");
@@ -11289,7 +11297,8 @@ var modalDirective = ({ props, renderSlot }) => {
11289
11297
  const btn = document.createElement("button");
11290
11298
  btn.className = `nr-button nr-button--default`;
11291
11299
  if (customClass) btn.classList.add(...customClass.split(/\s+/).filter(Boolean));
11292
- if (props.icon) btn.appendChild(createIcon(props.icon));
11300
+ const icon = props.icon || "open_in_new";
11301
+ if (icon) btn.appendChild(createIcon(icon));
11293
11302
  btn.appendChild(document.createTextNode(label));
11294
11303
  const dialog = createModal(modalTitle);
11295
11304
  const body = dialog.querySelector(".nr-modal__body");
@@ -11609,6 +11618,32 @@ function renderMarkdownString(markdown2) {
11609
11618
  const tokens = parseMarkdown(markdown2);
11610
11619
  return renderTokens(tokens);
11611
11620
  }
11621
+ function renderHtmlString(html) {
11622
+ let processedContent = html;
11623
+ processedContent = processedContent.replace(
11624
+ /<style(?:\s+[^>]*)?>([\s\S]*?)<\/style>/gi,
11625
+ (_match, cssContent) => {
11626
+ const styleEl = document.createElement("style");
11627
+ styleEl.setAttribute("data-nr-global", "");
11628
+ styleEl.textContent = cssContent;
11629
+ document.head.appendChild(styleEl);
11630
+ return "";
11631
+ }
11632
+ );
11633
+ const wrapper = document.createElement("div");
11634
+ wrapper.className = "nr-raw-html";
11635
+ wrapper.innerHTML = processedContent;
11636
+ const scripts = wrapper.querySelectorAll("script");
11637
+ scripts.forEach((oldScript) => {
11638
+ const newScript = document.createElement("script");
11639
+ Array.from(oldScript.attributes).forEach(
11640
+ (attr) => newScript.setAttribute(attr.name, attr.value)
11641
+ );
11642
+ newScript.textContent = oldScript.textContent;
11643
+ oldScript.parentNode?.replaceChild(newScript, oldScript);
11644
+ });
11645
+ return wrapper;
11646
+ }
11612
11647
  function renderTokensInner(tokens, ctx) {
11613
11648
  const container = document.createElement("div");
11614
11649
  container.appendChild(processElements(tokens, ctx, tokens));
@@ -11695,30 +11730,7 @@ function renderElement(element, ctx, allElements) {
11695
11730
  return renderDirective(element, ctx, allElements);
11696
11731
  case "html": {
11697
11732
  const el = element;
11698
- let processedContent = el.content;
11699
- processedContent = processedContent.replace(
11700
- /<style(?:\s+[^>]*)?>([\s\S]*?)<\/style>/gi,
11701
- (_match, cssContent) => {
11702
- const styleEl = document.createElement("style");
11703
- styleEl.setAttribute("data-nr-global", "");
11704
- styleEl.textContent = cssContent;
11705
- document.head.appendChild(styleEl);
11706
- return "";
11707
- }
11708
- );
11709
- const wrapper = document.createElement("div");
11710
- wrapper.className = "nr-raw-html";
11711
- wrapper.innerHTML = processedContent;
11712
- const scripts = wrapper.querySelectorAll("script");
11713
- scripts.forEach((oldScript) => {
11714
- const newScript = document.createElement("script");
11715
- Array.from(oldScript.attributes).forEach(
11716
- (attr) => newScript.setAttribute(attr.name, attr.value)
11717
- );
11718
- newScript.textContent = oldScript.textContent;
11719
- oldScript.parentNode?.replaceChild(newScript, oldScript);
11720
- });
11721
- return wrapper;
11733
+ return renderHtmlString(el.content);
11722
11734
  }
11723
11735
  case "html-block": {
11724
11736
  const htmlBlock = element;
@@ -11811,6 +11823,7 @@ export {
11811
11823
  createTOC,
11812
11824
  createTable,
11813
11825
  directives_default as directiveRegistry,
11826
+ renderHtmlString,
11814
11827
  renderInline,
11815
11828
  renderMarkdownString,
11816
11829
  renderTokens