@noirmd/previewer 1.0.2 → 1.1.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/NReditor.js CHANGED
@@ -1,9 +1,9 @@
1
- // NReditor.tsx
1
+ // react/NReditor.tsx
2
2
  import React9, { useRef as useRef6, useState as useState5 } from "react";
3
3
  import CodeMirror from "@uiw/react-codemirror";
4
4
  import { EditorView, Decoration, ViewPlugin, lineNumbers, scrollPastEnd, keymap } from "@codemirror/view";
5
5
 
6
- // custom-syntax.ts
6
+ // react/custom-syntax.ts
7
7
  import { StreamLanguage } from "@codemirror/language";
8
8
  import { tags as t } from "@lezer/highlight";
9
9
  var customStreamParserV2 = StreamLanguage.define({
@@ -297,12 +297,12 @@ var customStreamParserV2 = StreamLanguage.define({
297
297
  }
298
298
  });
299
299
 
300
- // NReditor.tsx
300
+ // react/NReditor.tsx
301
301
  import { RangeSetBuilder } from "@codemirror/state";
302
302
  import { syntaxHighlighting, HighlightStyle, foldService, foldGutter, foldAll, unfoldAll } from "@codemirror/language";
303
303
  import { tags as t2 } from "@lezer/highlight";
304
304
 
305
- // useDebounce.ts
305
+ // react/useDebounce.ts
306
306
  import { useState, useEffect } from "react";
307
307
  function useDebounce(value, delay) {
308
308
  const [debouncedValue, setDebouncedValue] = useState(value);
@@ -313,10 +313,10 @@ function useDebounce(value, delay) {
313
313
  return debouncedValue;
314
314
  }
315
315
 
316
- // CustomMarkdownRenderer.tsx
316
+ // react/CustomMarkdownRenderer.tsx
317
317
  import React8, { useState as useState4, useEffect as useEffect5, useCallback as useCallback2, useMemo, useId as useId3, useRef as useRef5 } from "react";
318
318
 
319
- // utils.ts
319
+ // core/utils.ts
320
320
  function parseCssString(cssText) {
321
321
  if (!cssText) return {};
322
322
  return cssText.split(";").filter(Boolean).reduce((styleObj, styleString) => {
@@ -332,6 +332,7 @@ function generateId(text) {
332
332
  return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
333
333
  }
334
334
  function scrollToId(id) {
335
+ if (typeof document === "undefined") return;
335
336
  const element = document.getElementById(id);
336
337
  if (element) {
337
338
  element.scrollIntoView({ behavior: "smooth", block: "start" });
@@ -393,11 +394,8 @@ function parseHtmlAttrs(attrsString) {
393
394
  const pairRegex = /([a-zA-Z0-9_-]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
394
395
  let match;
395
396
  while ((match = pairRegex.exec(attrsString)) !== null) {
396
- let key = match[1];
397
+ const key = match[1];
397
398
  const value = match[2] ?? match[3] ?? match[4] ?? true;
398
- if (key === "class") key = "className";
399
- else if (key === "for") key = "htmlFor";
400
- else if (key === "tabindex") key = "tabIndex";
401
399
  if (key === "style" && typeof value === "string") {
402
400
  props[key] = parseCssString(value);
403
401
  } else {
@@ -407,10 +405,10 @@ function parseHtmlAttrs(attrsString) {
407
405
  return props;
408
406
  }
409
407
 
410
- // parser.ts
408
+ // core/parser.ts
411
409
  function parseMarkdown(markdown2) {
412
410
  if (!markdown2) return [];
413
- const lines = markdown2.split("\n");
411
+ const lines = markdown2.replace(/\r\n/g, "\n").replace(/\r/g, "").split("\n");
414
412
  const result = [];
415
413
  let i = 0;
416
414
  while (i < lines.length) {
@@ -722,26 +720,24 @@ function splitSlots(rawContent) {
722
720
  nestingDepth++;
723
721
  }
724
722
  }
725
- const slotMatch = trimmed.match(/^#([\w-]+)$/);
726
- if (slotMatch && nestingDepth === 0) {
727
- slots[currentSlot] = buffer.join("\n").trim();
723
+ if (nestingDepth === 0 && trimmed.match(/^#([\w-]+)$/)) {
724
+ if (buffer.length > 0 || currentSlot !== "default") {
725
+ slots[currentSlot] = buffer.join("\n").trim();
726
+ }
727
+ currentSlot = trimmed.slice(1);
728
728
  buffer = [];
729
- currentSlot = slotMatch[1];
730
729
  } else {
731
730
  buffer.push(line);
732
731
  }
733
732
  }
734
733
  slots[currentSlot] = buffer.join("\n").trim();
735
- for (const key of Object.keys(slots)) {
736
- if (!slots[key]) delete slots[key];
737
- }
738
734
  return slots;
739
735
  }
740
736
 
741
- // ui-components.tsx
737
+ // react/ui-components.tsx
742
738
  import { useState as useState2, useRef } from "react";
743
739
 
744
- // highlightSetup.ts
740
+ // react/highlightSetup.ts
745
741
  import hljs from "highlight.js/lib/core";
746
742
  import javascript from "highlight.js/lib/languages/javascript";
747
743
  import typescript from "highlight.js/lib/languages/typescript";
@@ -811,7 +807,7 @@ hljs.registerLanguage("diff", diff);
811
807
  hljs.registerLanguage("shell", shell);
812
808
  var highlightSetup_default = hljs;
813
809
 
814
- // ui-components.tsx
810
+ // react/ui-components.tsx
815
811
  import { Dialog } from "@base-ui/react/dialog";
816
812
  import { jsx, jsxs } from "react/jsx-runtime";
817
813
  var IconRenderer = ({ iconName, extraClasses = "" }) => {
@@ -947,7 +943,7 @@ var Modal = ({ title, isOpen, onClose, children }) => {
947
943
  ] }) });
948
944
  };
949
945
 
950
- // renderers.tsx
946
+ // react/renderers.tsx
951
947
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
952
948
  function renderInline(text) {
953
949
  if (!text) return text;
@@ -1078,7 +1074,7 @@ function extractHeaders(elements) {
1078
1074
  return elements.filter((el) => el.type === "header");
1079
1075
  }
1080
1076
 
1081
- // directives/AdmonitionDirective.tsx
1077
+ // react/directives/AdmonitionDirective.tsx
1082
1078
  import { jsx as jsx3 } from "react/jsx-runtime";
1083
1079
  var AdmonitionDirective = ({
1084
1080
  directiveType,
@@ -1099,7 +1095,7 @@ var AdmonitionDirective = ({
1099
1095
  };
1100
1096
  var AdmonitionDirective_default = AdmonitionDirective;
1101
1097
 
1102
- // directives/CardDirective.tsx
1098
+ // react/directives/CardDirective.tsx
1103
1099
  import React2, { useId } from "react";
1104
1100
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
1105
1101
  var CardDirective = ({
@@ -1185,7 +1181,7 @@ var CardDirective = ({
1185
1181
  };
1186
1182
  var CardDirective_default = CardDirective;
1187
1183
 
1188
- // directives/DetailsDirective.tsx
1184
+ // react/directives/DetailsDirective.tsx
1189
1185
  import { jsx as jsx5 } from "react/jsx-runtime";
1190
1186
  var DetailsDirective = ({
1191
1187
  props,
@@ -1205,7 +1201,7 @@ var DetailsDirective = ({
1205
1201
  };
1206
1202
  var DetailsDirective_default = DetailsDirective;
1207
1203
 
1208
- // directives/ModalDirective.tsx
1204
+ // react/directives/ModalDirective.tsx
1209
1205
  import { useId as useId2 } from "react";
1210
1206
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
1211
1207
  var ModalDirective = ({
@@ -1256,7 +1252,7 @@ var ModalDirective = ({
1256
1252
  };
1257
1253
  var ModalDirective_default = ModalDirective;
1258
1254
 
1259
- // directives/ButtonDirective.tsx
1255
+ // react/directives/ButtonDirective.tsx
1260
1256
  import React4 from "react";
1261
1257
  import { Fragment, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1262
1258
  var ButtonDirective = ({
@@ -1336,7 +1332,7 @@ var ButtonDirective = ({
1336
1332
  };
1337
1333
  var ButtonDirective_default = ButtonDirective;
1338
1334
 
1339
- // directives/WrapperDirective.tsx
1335
+ // react/directives/WrapperDirective.tsx
1340
1336
  import { jsx as jsx8 } from "react/jsx-runtime";
1341
1337
  var WrapperDirective = ({
1342
1338
  props,
@@ -1358,7 +1354,7 @@ var WrapperDirective = ({
1358
1354
  };
1359
1355
  var WrapperDirective_default = WrapperDirective;
1360
1356
 
1361
- // directives/SlideDirective.tsx
1357
+ // react/directives/SlideDirective.tsx
1362
1358
  import { useState as useState3, useEffect as useEffect2, useCallback, useRef as useRef2, useLayoutEffect } from "react";
1363
1359
  import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1364
1360
  var slideCounter = 0;
@@ -1450,7 +1446,7 @@ var SlideDirective = ({
1450
1446
  };
1451
1447
  var SlideDirective_default = SlideDirective;
1452
1448
 
1453
- // directives/index.ts
1449
+ // react/directives/index.ts
1454
1450
  var directiveRegistry = {
1455
1451
  // Admonitions
1456
1452
  note: AdmonitionDirective_default,
@@ -1476,7 +1472,7 @@ var directiveRegistry = {
1476
1472
  };
1477
1473
  var directives_default = directiveRegistry;
1478
1474
 
1479
- // DirectiveRenderer.tsx
1475
+ // react/DirectiveRenderer.tsx
1480
1476
  import { jsx as jsx10 } from "react/jsx-runtime";
1481
1477
  var DirectiveRenderer = ({
1482
1478
  element,
@@ -1508,17 +1504,17 @@ var DirectiveRenderer = ({
1508
1504
  };
1509
1505
  var DirectiveRenderer_default = DirectiveRenderer;
1510
1506
 
1511
- // RawHtmlRenderer.tsx
1507
+ // react/RawHtmlRenderer.tsx
1512
1508
  import { useRef as useRef4, useEffect as useEffect4 } from "react";
1513
1509
 
1514
- // useTailwindCDN.ts
1510
+ // react/useTailwindCDN.ts
1515
1511
  import { useEffect as useEffect3, useRef as useRef3 } from "react";
1516
1512
  function scanTailwindCDN() {
1517
1513
  const tw = window.tailwind;
1518
1514
  if (tw?.scan) tw.scan();
1519
1515
  }
1520
1516
 
1521
- // RawHtmlRenderer.tsx
1517
+ // react/RawHtmlRenderer.tsx
1522
1518
  import { jsx as jsx11 } from "react/jsx-runtime";
1523
1519
  var RawHtmlRenderer = ({
1524
1520
  content,
@@ -1553,12 +1549,12 @@ var RawHtmlRenderer = ({
1553
1549
  };
1554
1550
  var RawHtmlRenderer_default = RawHtmlRenderer;
1555
1551
 
1556
- // context.tsx
1552
+ // react/context.tsx
1557
1553
  import { createContext, useContext } from "react";
1558
1554
  var RenderCtx = createContext(null);
1559
1555
  var RenderContextProvider = RenderCtx.Provider;
1560
1556
 
1561
- // CustomMarkdownRenderer.tsx
1557
+ // react/CustomMarkdownRenderer.tsx
1562
1558
  import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
1563
1559
  var CustomMarkdownRenderer = ({ content: initialContent }) => {
1564
1560
  const [modals, setModals] = useState4({});
@@ -1670,7 +1666,14 @@ var CustomMarkdownRenderer = ({ content: initialContent }) => {
1670
1666
  }
1671
1667
  case "html-block": {
1672
1668
  const htmlBlock = element;
1673
- const props = parseHtmlAttrs(htmlBlock.attrs);
1669
+ const rawProps = parseHtmlAttrs(htmlBlock.attrs);
1670
+ const props = {};
1671
+ for (const [key, value] of Object.entries(rawProps)) {
1672
+ if (key === "class") props["className"] = value;
1673
+ else if (key === "for") props["htmlFor"] = value;
1674
+ else if (key === "tabindex") props["tabIndex"] = value;
1675
+ else props[key] = value;
1676
+ }
1674
1677
  return React8.createElement(
1675
1678
  htmlBlock.tag,
1676
1679
  { key: index, ...props },
@@ -1775,7 +1778,7 @@ var CustomMarkdownRenderer = ({ content: initialContent }) => {
1775
1778
  };
1776
1779
  var CustomMarkdownRenderer_default = CustomMarkdownRenderer;
1777
1780
 
1778
- // NReditor.tsx
1781
+ // react/NReditor.tsx
1779
1782
  import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
1780
1783
  var customSyntaxHighlighting = HighlightStyle.define([
1781
1784
  { tag: t2.heading, fontWeight: "bold", color: "var(--tc-heading, #e2e8f0)" },