@noirmd/previewer 1.0.2 → 1.1.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.cjs CHANGED
@@ -1579,19 +1579,24 @@ __export(index_exports, {
1579
1579
  IconRenderer: () => IconRenderer,
1580
1580
  Modal: () => Modal,
1581
1581
  NRpreviewer: () => NRpreviewer_default,
1582
+ extractAttributes: () => extractAttributes,
1582
1583
  extractHeaders: () => extractHeaders,
1584
+ generateId: () => generateId,
1585
+ generateScopeId: () => generateScopeId,
1586
+ parseCssString: () => parseCssString,
1587
+ parseHtmlAttrs: () => parseHtmlAttrs,
1583
1588
  parseMarkdown: () => parseMarkdown,
1589
+ parseProps: () => parseProps,
1584
1590
  preloadTailwindCDN: () => preloadTailwindCDN,
1591
+ resetScopeCounter: () => resetScopeCounter,
1585
1592
  scanTailwindCDN: () => scanTailwindCDN,
1593
+ scrollToId: () => scrollToId,
1586
1594
  useDebounce: () => useDebounce,
1587
1595
  useLazyTailwindCDN: () => useLazyTailwindCDN
1588
1596
  });
1589
1597
  module.exports = __toCommonJS(index_exports);
1590
1598
 
1591
- // CustomMarkdownRenderer.tsx
1592
- var import_react9 = __toESM(require("react"), 1);
1593
-
1594
- // utils.ts
1599
+ // core/utils.ts
1595
1600
  function parseCssString(cssText) {
1596
1601
  if (!cssText) return {};
1597
1602
  return cssText.split(";").filter(Boolean).reduce((styleObj, styleString) => {
@@ -1607,6 +1612,7 @@ function generateId(text) {
1607
1612
  return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
1608
1613
  }
1609
1614
  function scrollToId(id) {
1615
+ if (typeof document === "undefined") return;
1610
1616
  const element = document.getElementById(id);
1611
1617
  if (element) {
1612
1618
  element.scrollIntoView({ behavior: "smooth", block: "start" });
@@ -1668,11 +1674,8 @@ function parseHtmlAttrs(attrsString) {
1668
1674
  const pairRegex = /([a-zA-Z0-9_-]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
1669
1675
  let match;
1670
1676
  while ((match = pairRegex.exec(attrsString)) !== null) {
1671
- let key = match[1];
1677
+ const key = match[1];
1672
1678
  const value = match[2] ?? match[3] ?? match[4] ?? true;
1673
- if (key === "class") key = "className";
1674
- else if (key === "for") key = "htmlFor";
1675
- else if (key === "tabindex") key = "tabIndex";
1676
1679
  if (key === "style" && typeof value === "string") {
1677
1680
  props[key] = parseCssString(value);
1678
1681
  } else {
@@ -1682,7 +1685,7 @@ function parseHtmlAttrs(attrsString) {
1682
1685
  return props;
1683
1686
  }
1684
1687
 
1685
- // parser.ts
1688
+ // core/parser.ts
1686
1689
  function parseMarkdown(markdown2) {
1687
1690
  if (!markdown2) return [];
1688
1691
  const lines = markdown2.split("\n");
@@ -1997,23 +2000,24 @@ function splitSlots(rawContent) {
1997
2000
  nestingDepth++;
1998
2001
  }
1999
2002
  }
2000
- const slotMatch = trimmed.match(/^#([\w-]+)$/);
2001
- if (slotMatch && nestingDepth === 0) {
2002
- slots[currentSlot] = buffer.join("\n").trim();
2003
+ if (nestingDepth === 0 && trimmed.match(/^#([\w-]+)$/)) {
2004
+ if (buffer.length > 0 || currentSlot !== "default") {
2005
+ slots[currentSlot] = buffer.join("\n").trim();
2006
+ }
2007
+ currentSlot = trimmed.slice(1);
2003
2008
  buffer = [];
2004
- currentSlot = slotMatch[1];
2005
2009
  } else {
2006
2010
  buffer.push(line);
2007
2011
  }
2008
2012
  }
2009
2013
  slots[currentSlot] = buffer.join("\n").trim();
2010
- for (const key of Object.keys(slots)) {
2011
- if (!slots[key]) delete slots[key];
2012
- }
2013
2014
  return slots;
2014
2015
  }
2015
2016
 
2016
- // ui-components.tsx
2017
+ // react/CustomMarkdownRenderer.tsx
2018
+ var import_react9 = __toESM(require("react"), 1);
2019
+
2020
+ // react/ui-components.tsx
2017
2021
  var import_react = require("react");
2018
2022
 
2019
2023
  // node_modules/highlight.js/es/core.js
@@ -10912,7 +10916,7 @@ function shell(hljs) {
10912
10916
  };
10913
10917
  }
10914
10918
 
10915
- // highlightSetup.ts
10919
+ // react/highlightSetup.ts
10916
10920
  core_default.registerLanguage("javascript", javascript);
10917
10921
  core_default.registerLanguage("js", javascript);
10918
10922
  core_default.registerLanguage("jsx", javascript);
@@ -10957,7 +10961,7 @@ core_default.registerLanguage("diff", diff);
10957
10961
  core_default.registerLanguage("shell", shell);
10958
10962
  var highlightSetup_default = core_default;
10959
10963
 
10960
- // ui-components.tsx
10964
+ // react/ui-components.tsx
10961
10965
  var import_dialog = require("@base-ui/react/dialog");
10962
10966
  var import_jsx_runtime = require("react/jsx-runtime");
10963
10967
  var IconRenderer = ({ iconName, extraClasses = "" }) => {
@@ -11093,7 +11097,7 @@ var Modal = ({ title, isOpen, onClose, children }) => {
11093
11097
  ] }) });
11094
11098
  };
11095
11099
 
11096
- // renderers.tsx
11100
+ // react/renderers.tsx
11097
11101
  var import_jsx_runtime2 = require("react/jsx-runtime");
11098
11102
  function renderInline(text) {
11099
11103
  if (!text) return text;
@@ -11224,7 +11228,7 @@ function extractHeaders(elements) {
11224
11228
  return elements.filter((el) => el.type === "header");
11225
11229
  }
11226
11230
 
11227
- // directives/AdmonitionDirective.tsx
11231
+ // react/directives/AdmonitionDirective.tsx
11228
11232
  var import_jsx_runtime3 = require("react/jsx-runtime");
11229
11233
  var AdmonitionDirective = ({
11230
11234
  directiveType,
@@ -11245,7 +11249,7 @@ var AdmonitionDirective = ({
11245
11249
  };
11246
11250
  var AdmonitionDirective_default = AdmonitionDirective;
11247
11251
 
11248
- // directives/CardDirective.tsx
11252
+ // react/directives/CardDirective.tsx
11249
11253
  var import_react2 = __toESM(require("react"), 1);
11250
11254
  var import_jsx_runtime4 = require("react/jsx-runtime");
11251
11255
  var CardDirective = ({
@@ -11331,7 +11335,7 @@ var CardDirective = ({
11331
11335
  };
11332
11336
  var CardDirective_default = CardDirective;
11333
11337
 
11334
- // directives/DetailsDirective.tsx
11338
+ // react/directives/DetailsDirective.tsx
11335
11339
  var import_jsx_runtime5 = require("react/jsx-runtime");
11336
11340
  var DetailsDirective = ({
11337
11341
  props,
@@ -11351,7 +11355,7 @@ var DetailsDirective = ({
11351
11355
  };
11352
11356
  var DetailsDirective_default = DetailsDirective;
11353
11357
 
11354
- // directives/ModalDirective.tsx
11358
+ // react/directives/ModalDirective.tsx
11355
11359
  var import_react3 = require("react");
11356
11360
  var import_jsx_runtime6 = require("react/jsx-runtime");
11357
11361
  var ModalDirective = ({
@@ -11402,7 +11406,7 @@ var ModalDirective = ({
11402
11406
  };
11403
11407
  var ModalDirective_default = ModalDirective;
11404
11408
 
11405
- // directives/ButtonDirective.tsx
11409
+ // react/directives/ButtonDirective.tsx
11406
11410
  var import_react4 = __toESM(require("react"), 1);
11407
11411
  var import_jsx_runtime7 = require("react/jsx-runtime");
11408
11412
  var ButtonDirective = ({
@@ -11482,7 +11486,7 @@ var ButtonDirective = ({
11482
11486
  };
11483
11487
  var ButtonDirective_default = ButtonDirective;
11484
11488
 
11485
- // directives/WrapperDirective.tsx
11489
+ // react/directives/WrapperDirective.tsx
11486
11490
  var import_jsx_runtime8 = require("react/jsx-runtime");
11487
11491
  var WrapperDirective = ({
11488
11492
  props,
@@ -11504,7 +11508,7 @@ var WrapperDirective = ({
11504
11508
  };
11505
11509
  var WrapperDirective_default = WrapperDirective;
11506
11510
 
11507
- // directives/SlideDirective.tsx
11511
+ // react/directives/SlideDirective.tsx
11508
11512
  var import_react5 = require("react");
11509
11513
  var import_jsx_runtime9 = require("react/jsx-runtime");
11510
11514
  var slideCounter = 0;
@@ -11596,7 +11600,7 @@ var SlideDirective = ({
11596
11600
  };
11597
11601
  var SlideDirective_default = SlideDirective;
11598
11602
 
11599
- // directives/index.ts
11603
+ // react/directives/index.ts
11600
11604
  var directiveRegistry = {
11601
11605
  // Admonitions
11602
11606
  note: AdmonitionDirective_default,
@@ -11622,7 +11626,7 @@ var directiveRegistry = {
11622
11626
  };
11623
11627
  var directives_default = directiveRegistry;
11624
11628
 
11625
- // DirectiveRenderer.tsx
11629
+ // react/DirectiveRenderer.tsx
11626
11630
  var import_jsx_runtime10 = require("react/jsx-runtime");
11627
11631
  var DirectiveRenderer = ({
11628
11632
  element,
@@ -11654,10 +11658,10 @@ var DirectiveRenderer = ({
11654
11658
  };
11655
11659
  var DirectiveRenderer_default = DirectiveRenderer;
11656
11660
 
11657
- // RawHtmlRenderer.tsx
11661
+ // react/RawHtmlRenderer.tsx
11658
11662
  var import_react7 = require("react");
11659
11663
 
11660
- // useTailwindCDN.ts
11664
+ // react/useTailwindCDN.ts
11661
11665
  var import_react6 = require("react");
11662
11666
  var CDN_URL = "https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4";
11663
11667
  var SCRIPT_ID = "tailwind-cdn-v4-runtime";
@@ -11735,7 +11739,7 @@ function preloadTailwindCDN() {
11735
11739
  }
11736
11740
  }
11737
11741
 
11738
- // RawHtmlRenderer.tsx
11742
+ // react/RawHtmlRenderer.tsx
11739
11743
  var import_jsx_runtime11 = require("react/jsx-runtime");
11740
11744
  var RawHtmlRenderer = ({
11741
11745
  content,
@@ -11770,12 +11774,12 @@ var RawHtmlRenderer = ({
11770
11774
  };
11771
11775
  var RawHtmlRenderer_default = RawHtmlRenderer;
11772
11776
 
11773
- // context.tsx
11777
+ // react/context.tsx
11774
11778
  var import_react8 = require("react");
11775
11779
  var RenderCtx = (0, import_react8.createContext)(null);
11776
11780
  var RenderContextProvider = RenderCtx.Provider;
11777
11781
 
11778
- // CustomMarkdownRenderer.tsx
11782
+ // react/CustomMarkdownRenderer.tsx
11779
11783
  var import_jsx_runtime12 = require("react/jsx-runtime");
11780
11784
  var CustomMarkdownRenderer = ({ content: initialContent }) => {
11781
11785
  const [modals, setModals] = (0, import_react9.useState)({});
@@ -11887,7 +11891,14 @@ var CustomMarkdownRenderer = ({ content: initialContent }) => {
11887
11891
  }
11888
11892
  case "html-block": {
11889
11893
  const htmlBlock = element;
11890
- const props = parseHtmlAttrs(htmlBlock.attrs);
11894
+ const rawProps = parseHtmlAttrs(htmlBlock.attrs);
11895
+ const props = {};
11896
+ for (const [key, value] of Object.entries(rawProps)) {
11897
+ if (key === "class") props["className"] = value;
11898
+ else if (key === "for") props["htmlFor"] = value;
11899
+ else if (key === "tabindex") props["tabIndex"] = value;
11900
+ else props[key] = value;
11901
+ }
11891
11902
  return import_react9.default.createElement(
11892
11903
  htmlBlock.tag,
11893
11904
  { key: index, ...props },
@@ -11992,7 +12003,7 @@ var CustomMarkdownRenderer = ({ content: initialContent }) => {
11992
12003
  };
11993
12004
  var CustomMarkdownRenderer_default = CustomMarkdownRenderer;
11994
12005
 
11995
- // NRpreviewer.tsx
12006
+ // react/NRpreviewer.tsx
11996
12007
  var import_jsx_runtime13 = require("react/jsx-runtime");
11997
12008
  var NRpreviewer = ({
11998
12009
  content,
@@ -12012,7 +12023,7 @@ var NRpreviewer = ({
12012
12023
  };
12013
12024
  var NRpreviewer_default = NRpreviewer;
12014
12025
 
12015
- // useDebounce.ts
12026
+ // react/useDebounce.ts
12016
12027
  var import_react10 = require("react");
12017
12028
  function useDebounce(value, delay) {
12018
12029
  const [debouncedValue, setDebouncedValue] = (0, import_react10.useState)(value);
@@ -12031,10 +12042,18 @@ function useDebounce(value, delay) {
12031
12042
  IconRenderer,
12032
12043
  Modal,
12033
12044
  NRpreviewer,
12045
+ extractAttributes,
12034
12046
  extractHeaders,
12047
+ generateId,
12048
+ generateScopeId,
12049
+ parseCssString,
12050
+ parseHtmlAttrs,
12035
12051
  parseMarkdown,
12052
+ parseProps,
12036
12053
  preloadTailwindCDN,
12054
+ resetScopeCounter,
12037
12055
  scanTailwindCDN,
12056
+ scrollToId,
12038
12057
  useDebounce,
12039
12058
  useLazyTailwindCDN
12040
12059
  });