scribe-cms 0.0.9 → 0.0.11

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/runtime.cjs CHANGED
@@ -5,6 +5,9 @@ var zod = require('zod');
5
5
  var fs2 = require('fs');
6
6
  var matter = require('gray-matter');
7
7
  var Database = require('better-sqlite3');
8
+ var remarkMdx = require('remark-mdx');
9
+ var remarkParse = require('remark-parse');
10
+ var unified = require('unified');
8
11
 
9
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
13
 
@@ -12,6 +15,8 @@ var path__default = /*#__PURE__*/_interopDefault(path);
12
15
  var fs2__default = /*#__PURE__*/_interopDefault(fs2);
13
16
  var matter__default = /*#__PURE__*/_interopDefault(matter);
14
17
  var Database__default = /*#__PURE__*/_interopDefault(Database);
18
+ var remarkMdx__default = /*#__PURE__*/_interopDefault(remarkMdx);
19
+ var remarkParse__default = /*#__PURE__*/_interopDefault(remarkParse);
15
20
 
16
21
  // src/config/resolve-config.ts
17
22
 
@@ -551,6 +556,118 @@ function listTranslationsForType(db, contentType) {
551
556
  return db.prepare(`SELECT * FROM translations WHERE content_type = ? ORDER BY en_slug, locale`).all(contentType);
552
557
  }
553
558
 
559
+ // src/translate/normalize-mdx-body.ts
560
+ function needsMdxEscapeNormalization(body) {
561
+ return /\\n[ \t/>]|<[\w.-][^>]*\\n/.test(body);
562
+ }
563
+ function normalizeTranslatedMdxBody(body) {
564
+ if (!needsMdxEscapeNormalization(body)) {
565
+ return { body, adjusted: false };
566
+ }
567
+ const normalized = body.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\"/g, '"').replace(/\\\\/g, "\\");
568
+ return { body: normalized, adjusted: normalized !== body };
569
+ }
570
+
571
+ // src/translate/sanitize-mdx-jsx.ts
572
+ function sanitizeMdxJsxAttributeQuotes(body) {
573
+ let adjusted = false;
574
+ let out = "";
575
+ let i = 0;
576
+ while (i < body.length) {
577
+ if (body[i] !== "<" || !/[\w.]/.test(body[i + 1] ?? "")) {
578
+ out += body[i];
579
+ i += 1;
580
+ continue;
581
+ }
582
+ const tagStart = i;
583
+ i += 1;
584
+ while (i < body.length && /[\w.-]/.test(body[i] ?? "")) i += 1;
585
+ const tagName = body.slice(tagStart + 1, i);
586
+ let tagOut = `<${tagName}`;
587
+ let tagAdjusted = false;
588
+ while (i < body.length && body[i] !== ">" && body[i] !== "/") {
589
+ while (i < body.length && /\s/.test(body[i] ?? "")) {
590
+ tagOut += body[i];
591
+ i += 1;
592
+ }
593
+ if (i >= body.length || body[i] === ">" || body[i] === "/") break;
594
+ const attrStart = i;
595
+ while (i < body.length && /[\w:.-]/.test(body[i] ?? "")) i += 1;
596
+ body.slice(attrStart, i);
597
+ while (i < body.length && /\s/.test(body[i] ?? "")) i += 1;
598
+ if (body[i] !== "=") {
599
+ tagOut += body.slice(attrStart, i);
600
+ continue;
601
+ }
602
+ tagOut += body.slice(attrStart, i);
603
+ tagOut += "=";
604
+ i += 1;
605
+ while (i < body.length && /\s/.test(body[i] ?? "")) i += 1;
606
+ const quote = body[i];
607
+ if (quote !== '"' && quote !== "'") {
608
+ continue;
609
+ }
610
+ if (quote === "'") {
611
+ const valStart2 = i + 1;
612
+ i += 1;
613
+ while (i < body.length) {
614
+ if (body[i] === "\\") {
615
+ i += 2;
616
+ continue;
617
+ }
618
+ if (body[i] === "'") break;
619
+ i += 1;
620
+ }
621
+ tagOut += body.slice(valStart2 - 1, i + 1);
622
+ i += 1;
623
+ continue;
624
+ }
625
+ const valStart = i + 1;
626
+ i += 1;
627
+ let closeIdx = -1;
628
+ for (let scan = valStart; scan < body.length; scan += 1) {
629
+ if (body[scan] !== '"') continue;
630
+ let j = scan + 1;
631
+ while (j < body.length && /\s/.test(body[j] ?? "")) j += 1;
632
+ if (j < body.length && (body[j] === ">" || body[j] === "/" || /[a-zA-Z]/.test(body[j] ?? ""))) {
633
+ closeIdx = scan;
634
+ break;
635
+ }
636
+ }
637
+ if (closeIdx === -1) {
638
+ tagOut += body.slice(valStart - 1, i);
639
+ break;
640
+ }
641
+ const value = body.slice(valStart, closeIdx);
642
+ const hasInternalQuote = value.includes('"');
643
+ if (hasInternalQuote) {
644
+ const escaped = value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
645
+ tagOut += `'${escaped}'`;
646
+ tagAdjusted = true;
647
+ } else {
648
+ tagOut += `"${value}"`;
649
+ }
650
+ i = closeIdx + 1;
651
+ }
652
+ if (tagAdjusted) adjusted = true;
653
+ tagOut += body[i] ?? "";
654
+ out += tagOut;
655
+ i += 1;
656
+ }
657
+ return { body: out, adjusted };
658
+ }
659
+
660
+ // src/translate/validate-mdx-body.ts
661
+ unified.unified().use(remarkParse__default.default).use(remarkMdx__default.default);
662
+ function prepareTranslatedMdxBody(body) {
663
+ const normalized = normalizeTranslatedMdxBody(body);
664
+ const sanitized = sanitizeMdxJsxAttributeQuotes(normalized.body);
665
+ return {
666
+ body: sanitized.body,
667
+ adjusted: normalized.adjusted || sanitized.adjusted
668
+ };
669
+ }
670
+
554
671
  // src/loader/normalize-en.ts
555
672
  function normalizeEnFrontmatter(data) {
556
673
  const out = { ...data };
@@ -671,7 +788,7 @@ function buildDocumentFromTranslation(row, enDoc, type, config) {
671
788
  noindex: seo.noindex,
672
789
  canonicalPathOverride: seo.canonicalPathOverride,
673
790
  frontmatter,
674
- content: row.body
791
+ content: prepareTranslatedMdxBody(row.body).body
675
792
  };
676
793
  }
677
794
  var DEV_REVALIDATE_MS = 1500;