@valbuild/core 0.62.6 → 0.63.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.
@@ -1,6 +1,28 @@
1
1
  'use strict';
2
2
 
3
3
  var result = require('./result-26f67b40.cjs.prod.js');
4
+ var marked = require('marked');
5
+ var core = require('@valbuild/core');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var marked__namespace = /*#__PURE__*/_interopNamespace(marked);
4
26
 
5
27
  function _arrayWithoutHoles(arr) {
6
28
  if (Array.isArray(arr)) return result._arrayLikeToArray(arr);
@@ -397,7 +419,7 @@ var VAL_EXTENSION = "_type";
397
419
  **/
398
420
 
399
421
  var FILE_REF_PROP = "_ref";
400
- var FILE_REF_SUBTYPE_TAG = "_tag";
422
+ var FILE_REF_SUBTYPE_TAG = "_tag"; // TODO: used earlier by c.rt.image, when we remove c.rt we can remove this
401
423
 
402
424
  /**
403
425
  * A file source represents the path to a (local) file.
@@ -904,7 +926,7 @@ var ParserError = /*#__PURE__*/_createClass(function ParserError(message, span)
904
926
  this.message = message;
905
927
  this.span = span;
906
928
  });
907
- function parseTokens(inputTokens) {
929
+ function parseTokens$1(inputTokens) {
908
930
  var tokens = inputTokens.slice();
909
931
  function slurpCall(first, isAnon) {
910
932
  var _tokens$, _tokens$2, _tokens$3, _tokens$7, _tokens$8, _args$slice$0$span;
@@ -1040,7 +1062,7 @@ function parse$1(input) {
1040
1062
  _tokenize2 = _slicedToArray(_tokenize, 2),
1041
1063
  tokens = _tokenize2[0];
1042
1064
  _tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
1043
- return parseTokens(tokens);
1065
+ return parseTokens$1(tokens);
1044
1066
  }
1045
1067
 
1046
1068
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -1769,6 +1791,14 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1769
1791
  _createClass(RichTextSchema, [{
1770
1792
  key: "validate",
1771
1793
  value: function validate(path, src) {
1794
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1795
+ if (src !== null && src !== void 0 && src.markdownish) {
1796
+ return _defineProperty({}, path, [{
1797
+ message: "Replace markdown with structured format",
1798
+ value: src,
1799
+ fixes: ["fix:deprecated-richtext"]
1800
+ }]);
1801
+ }
1772
1802
  return false; //TODO
1773
1803
  }
1774
1804
  }, {
@@ -2584,40 +2614,247 @@ function initSchema() {
2584
2614
  };
2585
2615
  }
2586
2616
 
2587
- // Classes
2617
+ var VAL_START_TAG_PREFIX = '<val value="';
2618
+ var VAL_START_TAG_SUFFIX = '">';
2619
+ var VAL_END_TAG = "</val>";
2620
+ function parseTokens(tokens, sourceNodes, cursor) {
2621
+ var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
2622
+ var children = [];
2623
+ function merge(token, clazz) {
2624
+ var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
2625
+ children.push({
2626
+ tag: "span",
2627
+ styles: [clazz].concat(parsedTokens.children.flatMap(function (child) {
2628
+ return typeof child === "string" ? [] : child.styles;
2629
+ })),
2630
+ children: parsedTokens.children.flatMap(function (child) {
2631
+ return typeof child === "string" ? child : child.children;
2632
+ })
2633
+ });
2634
+ }
2635
+ var _loop = function _loop() {
2636
+ var token = tokens[cursor];
2637
+ if (token.type === "heading") {
2638
+ children.push({
2639
+ tag: "h".concat(token.depth),
2640
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2641
+ });
2642
+ } else if (token.type === "paragraph") {
2643
+ children.push({
2644
+ tag: "p",
2645
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2646
+ });
2647
+ } else if (token.type === "strong") {
2648
+ merge(token, "bold");
2649
+ } else if (token.type === "em") {
2650
+ merge(token, "italic");
2651
+ } else if (token.type === "del") {
2652
+ merge(token, "line-through");
2653
+ } else if (token.type === "text") {
2654
+ if ("tokens" in token && Array.isArray(token.tokens)) {
2655
+ children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
2656
+ } else {
2657
+ if (insideList && typeof token.raw === "string") {
2658
+ var lines = token.raw.split("\n");
2659
+ var tags = lines.flatMap(function (line, i) {
2660
+ if (i === lines.length - 1) return [line];
2661
+ if (i === lines.length - 1 && line === "") return [];
2662
+ if (line === "") return [{
2663
+ tag: "p",
2664
+ children: [{
2665
+ tag: "br"
2666
+ }]
2667
+ }];
2668
+ return [line, {
2669
+ tag: "p",
2670
+ children: [{
2671
+ tag: "br"
2672
+ }]
2673
+ }];
2674
+ });
2675
+ children.push.apply(children, _toConsumableArray(tags));
2676
+ } else {
2677
+ children.push(token.raw);
2678
+ }
2679
+ }
2680
+ } else if (token.type === "list") {
2681
+ children.push({
2682
+ tag: token.ordered ? "ol" : "ul",
2683
+ children: parseTokens(token.items, sourceNodes, 0).children
2684
+ });
2685
+ } else if (token.type === "list_item") {
2686
+ children.push({
2687
+ tag: "li",
2688
+ children: [{
2689
+ tag: "p",
2690
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
2691
+ }]
2692
+ });
2693
+ } else if (token.type === "space") ; else if (token.type === "html") {
2694
+ if (token.text === VAL_END_TAG) {
2695
+ return {
2696
+ v: {
2697
+ children: children,
2698
+ cursor: cursor
2699
+ }
2700
+ };
2701
+ }
2702
+ var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
2703
+ if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
2704
+ var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
2705
+ if (Number.isNaN(number)) {
2706
+ throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
2707
+ }
2708
+ var _parseTokens = parseTokens(tokens.map(function (token) {
2709
+ if (token.type === "link" || token.type === "list") {
2710
+ return {
2711
+ type: "text",
2712
+ raw: token.raw,
2713
+ text: token.raw
2714
+ };
2715
+ }
2716
+ return token;
2717
+ }), sourceNodes, cursor + 1),
2718
+ subChildren = _parseTokens.children,
2719
+ subCursor = _parseTokens.cursor;
2720
+ var sourceNode = sourceNodes[number];
2721
+ if (sourceNode._type === "link") {
2722
+ children.push({
2723
+ tag: "a",
2724
+ href: sourceNode.href,
2725
+ children: subChildren
2726
+ });
2727
+ } else if (sourceNode._type === "file") {
2728
+ // @ts-expect-error We are transitioning from markdown to structured objects, with structured objects we no longer want c.rt.image
2729
+ delete sourceNode[core.FILE_REF_SUBTYPE_TAG];
2730
+ children.push({
2731
+ tag: "img",
2732
+ src: sourceNode
2733
+ });
2734
+ }
2735
+ cursor = subCursor;
2736
+ }
2737
+ var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
2738
+ if (token.text.trim().match(br_html_regex)) {
2739
+ var _tokens;
2740
+ children.push({
2741
+ tag: "p",
2742
+ children: [{
2743
+ tag: "br"
2744
+ }]
2745
+ });
2746
+ if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
2747
+ // if next token is a new line or white-spaces, skip it
2748
+ // this typically means we have a <br> AND a new line, which, semantically, is just a <br>
2749
+ cursor++;
2750
+ }
2751
+ }
2752
+ } else if (token.type === "link") {
2753
+ if (token.raw === token.href) {
2754
+ // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
2755
+ children.push(token.raw);
2756
+ } else {
2757
+ children.push({
2758
+ tag: "a",
2759
+ href: token.href,
2760
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2761
+ });
2762
+ }
2763
+ } else if (token.type === "br") {
2764
+ children.push({
2765
+ tag: "p",
2766
+ children: [{
2767
+ tag: "br"
2768
+ }]
2769
+ });
2770
+ } else {
2771
+ console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
2772
+ }
2773
+ cursor++;
2774
+ },
2775
+ _ret;
2776
+ while (cursor < tokens.length) {
2777
+ _ret = _loop();
2778
+ if (_ret) return _ret.v;
2779
+ }
2780
+ return {
2781
+ children: children,
2782
+ cursor: cursor
2783
+ };
2784
+ }
2785
+ function parseRichTextSource(_ref) {
2786
+ var templateStrings = _ref.templateStrings,
2787
+ nodes = _ref.exprs;
2788
+ // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
2789
+ var inputText = templateStrings.flatMap(function (templateString, i) {
2790
+ var node = nodes[i];
2791
+ if (node) {
2792
+ if (node[core.VAL_EXTENSION] === "link") {
2793
+ return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(node.children[0]).concat(VAL_END_TAG));
2794
+ } else {
2795
+ return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(VAL_END_TAG));
2796
+ }
2797
+ }
2798
+ return templateString;
2799
+ }).join("");
2800
+ var tokenList = marked__namespace.lexer(inputText, {
2801
+ gfm: true
2802
+ });
2803
+ var _parseTokens2 = parseTokens(tokenList, nodes, 0),
2804
+ children = _parseTokens2.children,
2805
+ cursor = _parseTokens2.cursor;
2806
+ if (cursor !== tokenList.length) {
2807
+ throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
2808
+ }
2809
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2810
+ children.markdownish = true; // Markdown is an intermediate format - we are planning on replacing it with a structured object format
2811
+ return children;
2812
+ }
2813
+
2814
+ //#region Classes
2588
2815
 
2589
- /// Paragraph
2816
+ //#region Paragraph
2590
2817
 
2591
- /// Break
2818
+ //#region Break
2592
2819
 
2593
- /// Span
2820
+ //#region Span
2594
2821
 
2595
- /// Image
2822
+ //#region Image
2596
2823
 
2597
- /// Link
2824
+ //#region Link
2598
2825
 
2599
- /// List
2826
+ //#region List
2600
2827
 
2601
- /// Heading
2828
+ //#region Heading
2829
+
2830
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2602
2831
 
2603
- /// Root and nodes
2832
+ // export type CustomInlineNode<O extends RichTextOptions> = NonNullable<
2833
+ // NonNullable<O["inline"]>["custom"]
2834
+ // >[keyof NonNullable<NonNullable<O["inline"]>["custom"]>] extends Schema<
2835
+ // infer Src
2836
+ // >
2837
+ // ? ReplaceRawStringWithString<Src>
2838
+ // : never;
2839
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2604
2840
 
2605
- /// Main types
2841
+ //#region Block and Inline nodes:
2606
2842
 
2607
- /**
2608
- * RichTextSource is defined in ValModules
2609
- **/
2843
+ //#region Main types
2610
2844
 
2611
2845
  /**
2612
- * RichText is accessible by users (after conversion via useVal / fetchVal)
2613
- * Internally it is a Selector
2846
+ * RichText as defined in a ValModule
2614
2847
  **/
2615
2848
 
2616
2849
  function richtext(templateStrings) {
2617
2850
  for (var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2618
2851
  nodes[_key - 1] = arguments[_key];
2619
2852
  }
2620
- return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", nodes);
2853
+ return parseRichTextSource({
2854
+ templateStrings: templateStrings,
2855
+ exprs: nodes
2856
+ // eslint-disable-next-line @typescript-eslint/ban-types
2857
+ });
2621
2858
  }
2622
2859
  var RT_IMAGE_TAG = "rt_image";
2623
2860
  function image(ref, metadata) {
@@ -1,4 +1,6 @@
1
1
  import { _ as _arrayLikeToArray, a as _unsupportedIterableToArray, i as isErr, e as err, o as ok, b as isOk, c as _createForOfIteratorHelper, r as result } from './result-a8316efa.esm.js';
2
+ import * as marked from 'marked';
3
+ import { VAL_EXTENSION as VAL_EXTENSION$1, FILE_REF_SUBTYPE_TAG as FILE_REF_SUBTYPE_TAG$1 } from '@valbuild/core';
2
4
 
3
5
  function _arrayWithoutHoles(arr) {
4
6
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
@@ -395,7 +397,7 @@ var VAL_EXTENSION = "_type";
395
397
  **/
396
398
 
397
399
  var FILE_REF_PROP = "_ref";
398
- var FILE_REF_SUBTYPE_TAG = "_tag";
400
+ var FILE_REF_SUBTYPE_TAG = "_tag"; // TODO: used earlier by c.rt.image, when we remove c.rt we can remove this
399
401
 
400
402
  /**
401
403
  * A file source represents the path to a (local) file.
@@ -902,7 +904,7 @@ var ParserError = /*#__PURE__*/_createClass(function ParserError(message, span)
902
904
  this.message = message;
903
905
  this.span = span;
904
906
  });
905
- function parseTokens(inputTokens) {
907
+ function parseTokens$1(inputTokens) {
906
908
  var tokens = inputTokens.slice();
907
909
  function slurpCall(first, isAnon) {
908
910
  var _tokens$, _tokens$2, _tokens$3, _tokens$7, _tokens$8, _args$slice$0$span;
@@ -1038,7 +1040,7 @@ function parse$1(input) {
1038
1040
  _tokenize2 = _slicedToArray(_tokenize, 2),
1039
1041
  tokens = _tokenize2[0];
1040
1042
  _tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
1041
- return parseTokens(tokens);
1043
+ return parseTokens$1(tokens);
1042
1044
  }
1043
1045
 
1044
1046
  /* eslint-disable @typescript-eslint/no-unused-vars */
@@ -1767,6 +1769,14 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1767
1769
  _createClass(RichTextSchema, [{
1768
1770
  key: "validate",
1769
1771
  value: function validate(path, src) {
1772
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1773
+ if (src !== null && src !== void 0 && src.markdownish) {
1774
+ return _defineProperty({}, path, [{
1775
+ message: "Replace markdown with structured format",
1776
+ value: src,
1777
+ fixes: ["fix:deprecated-richtext"]
1778
+ }]);
1779
+ }
1770
1780
  return false; //TODO
1771
1781
  }
1772
1782
  }, {
@@ -2582,40 +2592,247 @@ function initSchema() {
2582
2592
  };
2583
2593
  }
2584
2594
 
2585
- // Classes
2595
+ var VAL_START_TAG_PREFIX = '<val value="';
2596
+ var VAL_START_TAG_SUFFIX = '">';
2597
+ var VAL_END_TAG = "</val>";
2598
+ function parseTokens(tokens, sourceNodes, cursor) {
2599
+ var insideList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
2600
+ var children = [];
2601
+ function merge(token, clazz) {
2602
+ var parsedTokens = parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0);
2603
+ children.push({
2604
+ tag: "span",
2605
+ styles: [clazz].concat(parsedTokens.children.flatMap(function (child) {
2606
+ return typeof child === "string" ? [] : child.styles;
2607
+ })),
2608
+ children: parsedTokens.children.flatMap(function (child) {
2609
+ return typeof child === "string" ? child : child.children;
2610
+ })
2611
+ });
2612
+ }
2613
+ var _loop = function _loop() {
2614
+ var token = tokens[cursor];
2615
+ if (token.type === "heading") {
2616
+ children.push({
2617
+ tag: "h".concat(token.depth),
2618
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2619
+ });
2620
+ } else if (token.type === "paragraph") {
2621
+ children.push({
2622
+ tag: "p",
2623
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2624
+ });
2625
+ } else if (token.type === "strong") {
2626
+ merge(token, "bold");
2627
+ } else if (token.type === "em") {
2628
+ merge(token, "italic");
2629
+ } else if (token.type === "del") {
2630
+ merge(token, "line-through");
2631
+ } else if (token.type === "text") {
2632
+ if ("tokens" in token && Array.isArray(token.tokens)) {
2633
+ children.push.apply(children, _toConsumableArray(parseTokens(token.tokens, sourceNodes, cursor, insideList).children));
2634
+ } else {
2635
+ if (insideList && typeof token.raw === "string") {
2636
+ var lines = token.raw.split("\n");
2637
+ var tags = lines.flatMap(function (line, i) {
2638
+ if (i === lines.length - 1) return [line];
2639
+ if (i === lines.length - 1 && line === "") return [];
2640
+ if (line === "") return [{
2641
+ tag: "p",
2642
+ children: [{
2643
+ tag: "br"
2644
+ }]
2645
+ }];
2646
+ return [line, {
2647
+ tag: "p",
2648
+ children: [{
2649
+ tag: "br"
2650
+ }]
2651
+ }];
2652
+ });
2653
+ children.push.apply(children, _toConsumableArray(tags));
2654
+ } else {
2655
+ children.push(token.raw);
2656
+ }
2657
+ }
2658
+ } else if (token.type === "list") {
2659
+ children.push({
2660
+ tag: token.ordered ? "ol" : "ul",
2661
+ children: parseTokens(token.items, sourceNodes, 0).children
2662
+ });
2663
+ } else if (token.type === "list_item") {
2664
+ children.push({
2665
+ tag: "li",
2666
+ children: [{
2667
+ tag: "p",
2668
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0, true).children
2669
+ }]
2670
+ });
2671
+ } else if (token.type === "space") ; else if (token.type === "html") {
2672
+ if (token.text === VAL_END_TAG) {
2673
+ return {
2674
+ v: {
2675
+ children: children,
2676
+ cursor: cursor
2677
+ }
2678
+ };
2679
+ }
2680
+ var suffixIndex = token.text.indexOf(VAL_START_TAG_SUFFIX);
2681
+ if (token.text.startsWith(VAL_START_TAG_PREFIX) && suffixIndex > -1) {
2682
+ var number = Number(token.text.slice(VAL_START_TAG_PREFIX.length, suffixIndex));
2683
+ if (Number.isNaN(number)) {
2684
+ throw Error("Illegal val intermediate node: ".concat(JSON.stringify(token)));
2685
+ }
2686
+ var _parseTokens = parseTokens(tokens.map(function (token) {
2687
+ if (token.type === "link" || token.type === "list") {
2688
+ return {
2689
+ type: "text",
2690
+ raw: token.raw,
2691
+ text: token.raw
2692
+ };
2693
+ }
2694
+ return token;
2695
+ }), sourceNodes, cursor + 1),
2696
+ subChildren = _parseTokens.children,
2697
+ subCursor = _parseTokens.cursor;
2698
+ var sourceNode = sourceNodes[number];
2699
+ if (sourceNode._type === "link") {
2700
+ children.push({
2701
+ tag: "a",
2702
+ href: sourceNode.href,
2703
+ children: subChildren
2704
+ });
2705
+ } else if (sourceNode._type === "file") {
2706
+ // @ts-expect-error We are transitioning from markdown to structured objects, with structured objects we no longer want c.rt.image
2707
+ delete sourceNode[FILE_REF_SUBTYPE_TAG$1];
2708
+ children.push({
2709
+ tag: "img",
2710
+ src: sourceNode
2711
+ });
2712
+ }
2713
+ cursor = subCursor;
2714
+ }
2715
+ var br_html_regex = /<br\s*\/?>/gi; // matches <br>, <br/>, <br />; case insensitive
2716
+ if (token.text.trim().match(br_html_regex)) {
2717
+ var _tokens;
2718
+ children.push({
2719
+ tag: "p",
2720
+ children: [{
2721
+ tag: "br"
2722
+ }]
2723
+ });
2724
+ if (((_tokens = tokens[cursor + 1]) === null || _tokens === void 0 ? void 0 : _tokens.raw.trim()) === "") {
2725
+ // if next token is a new line or white-spaces, skip it
2726
+ // this typically means we have a <br> AND a new line, which, semantically, is just a <br>
2727
+ cursor++;
2728
+ }
2729
+ }
2730
+ } else if (token.type === "link") {
2731
+ if (token.raw === token.href) {
2732
+ // avoid auto-linking (provided by github flavoured markdown, but we want strikethrough so keep it enabled)
2733
+ children.push(token.raw);
2734
+ } else {
2735
+ children.push({
2736
+ tag: "a",
2737
+ href: token.href,
2738
+ children: parseTokens(token.tokens ? token.tokens : [], sourceNodes, 0).children
2739
+ });
2740
+ }
2741
+ } else if (token.type === "br") {
2742
+ children.push({
2743
+ tag: "p",
2744
+ children: [{
2745
+ tag: "br"
2746
+ }]
2747
+ });
2748
+ } else {
2749
+ console.error("Could not parse markdown: unsupported token type: ".concat(token.type, ". Found: ").concat(token.raw));
2750
+ }
2751
+ cursor++;
2752
+ },
2753
+ _ret;
2754
+ while (cursor < tokens.length) {
2755
+ _ret = _loop();
2756
+ if (_ret) return _ret.v;
2757
+ }
2758
+ return {
2759
+ children: children,
2760
+ cursor: cursor
2761
+ };
2762
+ }
2763
+ function parseRichTextSource(_ref) {
2764
+ var templateStrings = _ref.templateStrings,
2765
+ nodes = _ref.exprs;
2766
+ // TODO: validate that templateStrings does not contain VAL_NODE_PREFIX
2767
+ var inputText = templateStrings.flatMap(function (templateString, i) {
2768
+ var node = nodes[i];
2769
+ if (node) {
2770
+ if (node[VAL_EXTENSION$1] === "link") {
2771
+ return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(node.children[0]).concat(VAL_END_TAG));
2772
+ } else {
2773
+ return templateString.concat("".concat(VAL_START_TAG_PREFIX).concat(i).concat(VAL_START_TAG_SUFFIX).concat(VAL_END_TAG));
2774
+ }
2775
+ }
2776
+ return templateString;
2777
+ }).join("");
2778
+ var tokenList = marked.lexer(inputText, {
2779
+ gfm: true
2780
+ });
2781
+ var _parseTokens2 = parseTokens(tokenList, nodes, 0),
2782
+ children = _parseTokens2.children,
2783
+ cursor = _parseTokens2.cursor;
2784
+ if (cursor !== tokenList.length) {
2785
+ throw Error("Unexpectedly terminated markdown parsing. Possible reason: unclosed html tag?");
2786
+ }
2787
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2788
+ children.markdownish = true; // Markdown is an intermediate format - we are planning on replacing it with a structured object format
2789
+ return children;
2790
+ }
2586
2791
 
2587
- /// Paragraph
2792
+ //#region Classes
2588
2793
 
2589
- /// Break
2794
+ //#region Paragraph
2590
2795
 
2591
- /// Span
2796
+ //#region Break
2592
2797
 
2593
- /// Image
2798
+ //#region Span
2594
2799
 
2595
- /// Link
2800
+ //#region Image
2596
2801
 
2597
- /// List
2802
+ //#region Link
2598
2803
 
2599
- /// Heading
2804
+ //#region List
2600
2805
 
2601
- /// Root and nodes
2806
+ //#region Heading
2602
2807
 
2603
- /// Main types
2808
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2604
2809
 
2605
- /**
2606
- * RichTextSource is defined in ValModules
2607
- **/
2810
+ // export type CustomInlineNode<O extends RichTextOptions> = NonNullable<
2811
+ // NonNullable<O["inline"]>["custom"]
2812
+ // >[keyof NonNullable<NonNullable<O["inline"]>["custom"]>] extends Schema<
2813
+ // infer Src
2814
+ // >
2815
+ // ? ReplaceRawStringWithString<Src>
2816
+ // : never;
2817
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2818
+
2819
+ //#region Block and Inline nodes:
2820
+
2821
+ //#region Main types
2608
2822
 
2609
2823
  /**
2610
- * RichText is accessible by users (after conversion via useVal / fetchVal)
2611
- * Internally it is a Selector
2824
+ * RichText as defined in a ValModule
2612
2825
  **/
2613
2826
 
2614
2827
  function richtext(templateStrings) {
2615
2828
  for (var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2616
2829
  nodes[_key - 1] = arguments[_key];
2617
2830
  }
2618
- return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", nodes);
2831
+ return parseRichTextSource({
2832
+ templateStrings: templateStrings,
2833
+ exprs: nodes
2834
+ // eslint-disable-next-line @typescript-eslint/ban-types
2835
+ });
2619
2836
  }
2620
2837
  var RT_IMAGE_TAG = "rt_image";
2621
2838
  function image(ref, metadata) {