@limetech/lime-elements 39.12.5 → 39.13.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 (79) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/{_baseForOwn-CMhQVS1J.js → _baseForOwn-QM0kHQT5.js} +1 -1
  3. package/dist/cjs/{_baseIsEqual-DmV6vCh4.js → _baseIsEqual-D6hrjmx4.js} +1 -1
  4. package/dist/cjs/{_baseIteratee-DrEpOCx4.js → _baseIteratee-iGEZ9pZY.js} +1 -1
  5. package/dist/cjs/{_getPrototype-B0YUXP6e.js → _getPrototype-BK9cL-57.js} +1 -1
  6. package/dist/cjs/{index-nxo2UO7I.js → index-mbfaT7TB.js} +4 -3
  7. package/dist/cjs/{isArrayLikeObject-Bwh0a-dZ.js → isArrayLikeObject-CTP6Ak01.js} +1 -1
  8. package/dist/cjs/{isEmpty-B8-0FBZ_.js → isEmpty-DCC_l2Xp.js} +1 -1
  9. package/dist/cjs/{isEqual-B32SmSAJ.js → isEqual-BsHLqE-x.js} +1 -1
  10. package/dist/cjs/lime-elements.cjs.js +1 -1
  11. package/dist/cjs/limel-breadcrumbs_7.cjs.entry.js +22 -1
  12. package/dist/cjs/limel-button.cjs.entry.js +3 -3
  13. package/dist/cjs/limel-chip_2.cjs.entry.js +3 -3
  14. package/dist/cjs/limel-dialog.cjs.entry.js +2 -2
  15. package/dist/cjs/limel-file-dropzone_2.cjs.entry.js +3 -3
  16. package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
  17. package/dist/cjs/limel-form.cjs.entry.js +31 -19
  18. package/dist/cjs/limel-markdown.cjs.entry.js +2 -2
  19. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +13 -6
  20. package/dist/cjs/limel-tab-bar.cjs.entry.js +3 -3
  21. package/dist/cjs/limel-table.cjs.entry.js +4 -4
  22. package/dist/cjs/loader.cjs.js +1 -1
  23. package/dist/cjs/{markdown-parser-VvYe9xWW.js → markdown-parser-DCnW9yak.js} +840 -2723
  24. package/dist/collection/components/button/button.css +18 -13
  25. package/dist/collection/components/button/button.js +16 -2
  26. package/dist/collection/components/menu/menu.js +43 -1
  27. package/dist/esm/{_baseForOwn-ByPjzJ4R.js → _baseForOwn-CfpQNnvA.js} +1 -1
  28. package/dist/esm/{_baseIsEqual-DEKrwcEh.js → _baseIsEqual-BvHnKRmD.js} +1 -1
  29. package/dist/esm/{_baseIteratee-1mEitKxK.js → _baseIteratee-DFBCJcMA.js} +1 -1
  30. package/dist/esm/{_getPrototype-C17KNemI.js → _getPrototype-jV9gkkJy.js} +1 -1
  31. package/dist/esm/{index-CJ0GYrWG.js → index-DJJymEnS.js} +3 -4
  32. package/dist/esm/{isArrayLikeObject-hcrPUpXp.js → isArrayLikeObject-D7yRwRv4.js} +1 -1
  33. package/dist/esm/{isEmpty-CTmDjx6B.js → isEmpty-tfwtR2ai.js} +1 -1
  34. package/dist/esm/{isEqual-m-UUey98.js → isEqual-BkQ4Z_9r.js} +1 -1
  35. package/dist/esm/lime-elements.js +1 -1
  36. package/dist/esm/limel-breadcrumbs_7.entry.js +22 -1
  37. package/dist/esm/limel-button.entry.js +3 -3
  38. package/dist/esm/limel-chip_2.entry.js +3 -3
  39. package/dist/esm/limel-dialog.entry.js +2 -2
  40. package/dist/esm/limel-file-dropzone_2.entry.js +3 -3
  41. package/dist/esm/limel-file-viewer.entry.js +1 -1
  42. package/dist/esm/limel-form.entry.js +31 -19
  43. package/dist/esm/limel-markdown.entry.js +2 -2
  44. package/dist/esm/limel-prosemirror-adapter.entry.js +13 -6
  45. package/dist/esm/limel-tab-bar.entry.js +3 -3
  46. package/dist/esm/limel-table.entry.js +4 -4
  47. package/dist/esm/loader.js +1 -1
  48. package/dist/esm/{markdown-parser-CeVA0wsI.js → markdown-parser-CXYHPPe2.js} +837 -2720
  49. package/dist/lime-elements/lime-elements.esm.js +1 -1
  50. package/dist/lime-elements/{p-8fed01b1.entry.js → p-00d6ccd6.entry.js} +1 -1
  51. package/dist/lime-elements/{p-803ec458.entry.js → p-45dfcaf3.entry.js} +1 -1
  52. package/dist/lime-elements/{p-6fd84e57.entry.js → p-5db2d069.entry.js} +1 -1
  53. package/dist/lime-elements/{p-f92f4f00.entry.js → p-846bca5d.entry.js} +1 -1
  54. package/dist/lime-elements/p-8a6721f9.entry.js +1 -0
  55. package/dist/lime-elements/{p-2kcqdtMr.js → p-B4YDb6f3.js} +1 -1
  56. package/dist/lime-elements/{p-Cv8K0N31.js → p-BlJd1RC5.js} +1 -1
  57. package/dist/lime-elements/p-CqEHNkif.js +1 -0
  58. package/dist/lime-elements/p-Cw1B5fXE.js +1 -0
  59. package/dist/lime-elements/p-DKxusNKT.js +1 -0
  60. package/dist/lime-elements/p-DrjUjEz3.js +1 -0
  61. package/dist/lime-elements/{p-DMyO3At_.js → p-DzlmgobW.js} +1 -1
  62. package/dist/lime-elements/{p-f93163eb.entry.js → p-a4a09ce9.entry.js} +2 -2
  63. package/dist/lime-elements/{p-57135b6a.entry.js → p-ad9cb573.entry.js} +1 -1
  64. package/dist/lime-elements/{p-537df672.entry.js → p-b1d6553c.entry.js} +1 -1
  65. package/dist/lime-elements/{p-2b1eda20.entry.js → p-dd7a2361.entry.js} +3 -3
  66. package/dist/lime-elements/{p-0f4b1953.entry.js → p-eeae0ef6.entry.js} +4 -4
  67. package/dist/lime-elements/{p-39689e8a.entry.js → p-f0f5eda1.entry.js} +1 -1
  68. package/dist/lime-elements/p-g3InYy9F.js +7 -0
  69. package/dist/types/components/button/button.d.ts +14 -0
  70. package/dist/types/components/menu/menu.d.ts +6 -0
  71. package/dist/types/components.d.ts +59 -0
  72. package/package.json +1 -5
  73. package/dist/lime-elements/p-CDEsXij4.js +0 -1
  74. package/dist/lime-elements/p-CaObZtau.js +0 -1
  75. package/dist/lime-elements/p-CfUOv15O.js +0 -7
  76. package/dist/lime-elements/p-DkL-aPMx.js +0 -1
  77. package/dist/lime-elements/p-a855de67.entry.js +0 -1
  78. package/dist/lime-elements/p-gWSB8lIW.js +0 -1
  79. /package/dist/lime-elements/{p-DTNvx8HZ.js → p-C6SEjICu.js} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { g as getDefaultExportFromCjs } from './_commonjsHelpers-BFTU3MAI.js';
2
- import { s as structuredClone, v as visit, e as convert, f as visitParents, E as EXIT, g as determineBranch, h as htmlDecodeTree, B as BinTrieFlags, u as unified, a as rehypeSanitize, b as rehypeStringify, r as rehypeParse, d as defaultSchema } from './index-CJ0GYrWG.js';
2
+ import { s as structuredClone, v as visit, e as convert, f as visitParents, g as ccount, E as EXIT, z as zwitch, h as determineBranch, i as htmlDecodeTree, B as BinTrieFlags, u as unified, a as rehypeSanitize, b as rehypeStringify, r as rehypeParse, d as defaultSchema } from './index-DJJymEnS.js';
3
3
 
4
4
  /**
5
5
  *
@@ -57,7 +57,7 @@ function isProtocolRelativeUrl(url) {
57
57
  */
58
58
 
59
59
  /** @type {Options} */
60
- const emptyOptions$5 = {};
60
+ const emptyOptions$3 = {};
61
61
 
62
62
  /**
63
63
  * Get the text content of a node or list of nodes.
@@ -72,8 +72,8 @@ const emptyOptions$5 = {};
72
72
  * @returns {string}
73
73
  * Serialized `value`.
74
74
  */
75
- function toString$2(value, options) {
76
- const settings = emptyOptions$5;
75
+ function toString(value, options) {
76
+ const settings = emptyOptions$3;
77
77
  const includeImageAlt =
78
78
  typeof settings.includeImageAlt === 'boolean'
79
79
  ? settings.includeImageAlt
@@ -81,7 +81,7 @@ function toString$2(value, options) {
81
81
  const includeHtml =
82
82
  typeof settings.includeHtml === 'boolean' ? settings.includeHtml : true;
83
83
 
84
- return one$4(value, includeImageAlt, includeHtml)
84
+ return one$2(value, includeImageAlt, includeHtml)
85
85
  }
86
86
 
87
87
  /**
@@ -96,8 +96,8 @@ function toString$2(value, options) {
96
96
  * @returns {string}
97
97
  * Serialized node.
98
98
  */
99
- function one$4(value, includeImageAlt, includeHtml) {
100
- if (node$2(value)) {
99
+ function one$2(value, includeImageAlt, includeHtml) {
100
+ if (node(value)) {
101
101
  if ('value' in value) {
102
102
  return value.type === 'html' && !includeHtml ? '' : value.value
103
103
  }
@@ -107,12 +107,12 @@ function one$4(value, includeImageAlt, includeHtml) {
107
107
  }
108
108
 
109
109
  if ('children' in value) {
110
- return all$5(value.children, includeImageAlt, includeHtml)
110
+ return all$3(value.children, includeImageAlt, includeHtml)
111
111
  }
112
112
  }
113
113
 
114
114
  if (Array.isArray(value)) {
115
- return all$5(value, includeImageAlt, includeHtml)
115
+ return all$3(value, includeImageAlt, includeHtml)
116
116
  }
117
117
 
118
118
  return ''
@@ -130,13 +130,13 @@ function one$4(value, includeImageAlt, includeHtml) {
130
130
  * @returns {string}
131
131
  * Serialized nodes.
132
132
  */
133
- function all$5(values, includeImageAlt, includeHtml) {
133
+ function all$3(values, includeImageAlt, includeHtml) {
134
134
  /** @type {Array<string>} */
135
135
  const result = [];
136
136
  let index = -1;
137
137
 
138
138
  while (++index < values.length) {
139
- result[index] = one$4(values[index], includeImageAlt, includeHtml);
139
+ result[index] = one$2(values[index], includeImageAlt, includeHtml);
140
140
  }
141
141
 
142
142
  return result.join('')
@@ -150,7 +150,7 @@ function all$5(values, includeImageAlt, includeHtml) {
150
150
  * @returns {value is Nodes}
151
151
  * Whether `value` is a node.
152
152
  */
153
- function node$2(value) {
153
+ function node(value) {
154
154
  return Boolean(value && typeof value === 'object')
155
155
  }
156
156
 
@@ -2287,7 +2287,7 @@ const characterEntities = {
2287
2287
  zwnj: '‌'
2288
2288
  };
2289
2289
 
2290
- const own$9 = {}.hasOwnProperty;
2290
+ const own$7 = {}.hasOwnProperty;
2291
2291
 
2292
2292
  /**
2293
2293
  * Decode a single character reference (without the `&` or `;`).
@@ -2301,7 +2301,7 @@ const own$9 = {}.hasOwnProperty;
2301
2301
  * Decoded reference.
2302
2302
  */
2303
2303
  function decodeNamedCharacterReference(value) {
2304
- return own$9.call(characterEntities, value) ? characterEntities[value] : false
2304
+ return own$7.call(characterEntities, value) ? characterEntities[value] : false
2305
2305
  }
2306
2306
 
2307
2307
  /**
@@ -6230,7 +6230,7 @@ function factoryWhitespace(effects, ok) {
6230
6230
  */
6231
6231
 
6232
6232
  /** @type {Construct} */
6233
- const definition$2 = {
6233
+ const definition$1 = {
6234
6234
  name: 'definition',
6235
6235
  tokenize: tokenizeDefinition
6236
6236
  };
@@ -9269,7 +9269,7 @@ function tokenizeLineEnding(effects, ok) {
9269
9269
  */
9270
9270
 
9271
9271
  /** @type {Construct} */
9272
- const thematicBreak$3 = {
9272
+ const thematicBreak$2 = {
9273
9273
  name: 'thematicBreak',
9274
9274
  tokenize: tokenizeThematicBreak
9275
9275
  };
@@ -9372,7 +9372,7 @@ function tokenizeThematicBreak(effects, ok, nok) {
9372
9372
 
9373
9373
 
9374
9374
  /** @type {Construct} */
9375
- const list$3 = {
9375
+ const list$2 = {
9376
9376
  name: 'list',
9377
9377
  tokenize: tokenizeListStart,
9378
9378
  continuation: {
@@ -9431,7 +9431,7 @@ function tokenizeListStart(effects, ok, nok) {
9431
9431
  if (kind === 'listUnordered') {
9432
9432
  effects.enter('listItemPrefix');
9433
9433
  return code === 42 || code === 45
9434
- ? effects.check(thematicBreak$3, nok, atMarker)(code)
9434
+ ? effects.check(thematicBreak$2, nok, atMarker)(code)
9435
9435
  : atMarker(code)
9436
9436
  }
9437
9437
  if (!self.interrupt || code === 49) {
@@ -9555,7 +9555,7 @@ function tokenizeListContinuation(effects, ok, nok) {
9555
9555
 
9556
9556
  return factorySpace(
9557
9557
  effects,
9558
- effects.attempt(list$3, ok, nok),
9558
+ effects.attempt(list$2, ok, nok),
9559
9559
  'linePrefix',
9560
9560
  self.parser.constructs.disable.null.includes('codeIndented')
9561
9561
  ? undefined
@@ -9885,7 +9885,7 @@ const resolver = {
9885
9885
  resolveAll: createResolver()
9886
9886
  };
9887
9887
  const string$1 = initializeFactory('string');
9888
- const text$7 = initializeFactory('text');
9888
+ const text$6 = initializeFactory('text');
9889
9889
 
9890
9890
  /**
9891
9891
  * @param {'string' | 'text'} field
@@ -10637,25 +10637,25 @@ function serializeChunks(chunks, expandTabs) {
10637
10637
 
10638
10638
  /** @satisfies {Extension['document']} */
10639
10639
  const document = {
10640
- [42]: list$3,
10641
- [43]: list$3,
10642
- [45]: list$3,
10643
- [48]: list$3,
10644
- [49]: list$3,
10645
- [50]: list$3,
10646
- [51]: list$3,
10647
- [52]: list$3,
10648
- [53]: list$3,
10649
- [54]: list$3,
10650
- [55]: list$3,
10651
- [56]: list$3,
10652
- [57]: list$3,
10640
+ [42]: list$2,
10641
+ [43]: list$2,
10642
+ [45]: list$2,
10643
+ [48]: list$2,
10644
+ [49]: list$2,
10645
+ [50]: list$2,
10646
+ [51]: list$2,
10647
+ [52]: list$2,
10648
+ [53]: list$2,
10649
+ [54]: list$2,
10650
+ [55]: list$2,
10651
+ [56]: list$2,
10652
+ [57]: list$2,
10653
10653
  [62]: blockQuote
10654
10654
  };
10655
10655
 
10656
10656
  /** @satisfies {Extension['contentInitial']} */
10657
10657
  const contentInitial = {
10658
- [91]: definition$2
10658
+ [91]: definition$1
10659
10659
  };
10660
10660
 
10661
10661
  /** @satisfies {Extension['flowInitial']} */
@@ -10668,11 +10668,11 @@ const flowInitial = {
10668
10668
  /** @satisfies {Extension['flow']} */
10669
10669
  const flow = {
10670
10670
  [35]: headingAtx,
10671
- [42]: thematicBreak$3,
10672
- [45]: [setextUnderline, thematicBreak$3],
10671
+ [42]: thematicBreak$2,
10672
+ [45]: [setextUnderline, thematicBreak$2],
10673
10673
  [60]: htmlFlow,
10674
10674
  [61]: setextUnderline,
10675
- [95]: thematicBreak$3,
10675
+ [95]: thematicBreak$2,
10676
10676
  [96]: codeFenced,
10677
10677
  [126]: codeFenced
10678
10678
  };
@@ -10684,7 +10684,7 @@ const string = {
10684
10684
  };
10685
10685
 
10686
10686
  /** @satisfies {Extension['text']} */
10687
- const text$6 = {
10687
+ const text$5 = {
10688
10688
  [-5]: lineEnding,
10689
10689
  [-4]: lineEnding,
10690
10690
  [-3]: lineEnding,
@@ -10724,7 +10724,7 @@ var defaultConstructs = /*#__PURE__*/Object.freeze({
10724
10724
  flowInitial: flowInitial,
10725
10725
  insideSpan: insideSpan,
10726
10726
  string: string,
10727
- text: text$6
10727
+ text: text$5
10728
10728
  });
10729
10729
 
10730
10730
  /**
@@ -10755,7 +10755,7 @@ function parse$3(options) {
10755
10755
  document: create(document$1),
10756
10756
  flow: create(flow$1),
10757
10757
  string: create(string$1),
10758
- text: create(text$7)
10758
+ text: create(text$6)
10759
10759
  };
10760
10760
  return parser
10761
10761
 
@@ -11062,7 +11062,7 @@ function index(value) {
11062
11062
  * @typedef {import('../index.js').CompileData} CompileData
11063
11063
  */
11064
11064
 
11065
- const own$8 = {}.hasOwnProperty;
11065
+ const own$6 = {}.hasOwnProperty;
11066
11066
 
11067
11067
  /**
11068
11068
  * Turn markdown into a syntax tree.
@@ -11255,7 +11255,7 @@ function compiler(options) {
11255
11255
  index = -1;
11256
11256
  while (++index < events.length) {
11257
11257
  const handler = config[events[index][0]];
11258
- if (own$8.call(handler, events[index][1].type)) {
11258
+ if (own$6.call(handler, events[index][1].type)) {
11259
11259
  handler[events[index][1].type].call(
11260
11260
  Object.assign(
11261
11261
  {
@@ -11562,7 +11562,7 @@ function compiler(options) {
11562
11562
  * @returns {string}
11563
11563
  */
11564
11564
  function resume() {
11565
- return toString$2(this.stack.pop())
11565
+ return toString(this.stack.pop())
11566
11566
  }
11567
11567
 
11568
11568
  //
@@ -12207,7 +12207,7 @@ function extension(combined, extension) {
12207
12207
  /** @type {keyof Extension} */
12208
12208
  let key;
12209
12209
  for (key in extension) {
12210
- if (own$8.call(extension, key)) {
12210
+ if (own$6.call(extension, key)) {
12211
12211
  switch (key) {
12212
12212
  case 'canContainEols': {
12213
12213
  const right = extension[key];
@@ -12311,12 +12311,11 @@ function remarkParse(options) {
12311
12311
  }
12312
12312
 
12313
12313
  /**
12314
- * @typedef {import('hast').Element} Element
12315
- * @typedef {import('mdast').Blockquote} Blockquote
12316
- * @typedef {import('../state.js').State} State
12314
+ * @import {Element} from 'hast'
12315
+ * @import {Blockquote} from 'mdast'
12316
+ * @import {State} from '../state.js'
12317
12317
  */
12318
12318
 
12319
-
12320
12319
  /**
12321
12320
  * Turn an mdast `blockquote` node into hast.
12322
12321
  *
@@ -12327,7 +12326,7 @@ function remarkParse(options) {
12327
12326
  * @returns {Element}
12328
12327
  * hast node.
12329
12328
  */
12330
- function blockquote$2(state, node) {
12329
+ function blockquote$1(state, node) {
12331
12330
  /** @type {Element} */
12332
12331
  const result = {
12333
12332
  type: 'element',
@@ -12340,13 +12339,11 @@ function blockquote$2(state, node) {
12340
12339
  }
12341
12340
 
12342
12341
  /**
12343
- * @typedef {import('hast').Element} Element
12344
- * @typedef {import('hast').Text} Text
12345
- * @typedef {import('mdast').Break} Break
12346
- * @typedef {import('../state.js').State} State
12342
+ * @import {Element, Text} from 'hast'
12343
+ * @import {Break} from 'mdast'
12344
+ * @import {State} from '../state.js'
12347
12345
  */
12348
12346
 
12349
-
12350
12347
  /**
12351
12348
  * Turn an mdast `break` node into hast.
12352
12349
  *
@@ -12357,7 +12354,7 @@ function blockquote$2(state, node) {
12357
12354
  * @returns {Array<Element | Text>}
12358
12355
  * hast element content.
12359
12356
  */
12360
- function hardBreak$2(state, node) {
12357
+ function hardBreak$1(state, node) {
12361
12358
  /** @type {Element} */
12362
12359
  const result = {type: 'element', tagName: 'br', properties: {}, children: []};
12363
12360
  state.patch(node, result);
@@ -12365,13 +12362,11 @@ function hardBreak$2(state, node) {
12365
12362
  }
12366
12363
 
12367
12364
  /**
12368
- * @typedef {import('hast').Element} Element
12369
- * @typedef {import('hast').Properties} Properties
12370
- * @typedef {import('mdast').Code} Code
12371
- * @typedef {import('../state.js').State} State
12365
+ * @import {Element, Properties} from 'hast'
12366
+ * @import {Code} from 'mdast'
12367
+ * @import {State} from '../state.js'
12372
12368
  */
12373
12369
 
12374
-
12375
12370
  /**
12376
12371
  * Turn an mdast `code` node into hast.
12377
12372
  *
@@ -12382,13 +12377,16 @@ function hardBreak$2(state, node) {
12382
12377
  * @returns {Element}
12383
12378
  * hast node.
12384
12379
  */
12385
- function code$3(state, node) {
12380
+ function code$2(state, node) {
12386
12381
  const value = node.value ? node.value + '\n' : '';
12387
12382
  /** @type {Properties} */
12388
12383
  const properties = {};
12384
+ // Someone can write `js&#x20;python&#x9;ruby`.
12385
+ const language = node.lang ? node.lang.split(/\s+/) : [];
12389
12386
 
12390
- if (node.lang) {
12391
- properties.className = ['language-' + node.lang];
12387
+ // GH/CM still drop the non-first languages.
12388
+ if (language.length > 0) {
12389
+ properties.className = ['language-' + language[0]];
12392
12390
  }
12393
12391
 
12394
12392
  // Create `<code>`.
@@ -12414,12 +12412,11 @@ function code$3(state, node) {
12414
12412
  }
12415
12413
 
12416
12414
  /**
12417
- * @typedef {import('hast').Element} Element
12418
- * @typedef {import('mdast').Delete} Delete
12419
- * @typedef {import('../state.js').State} State
12415
+ * @import {Element} from 'hast'
12416
+ * @import {Delete} from 'mdast'
12417
+ * @import {State} from '../state.js'
12420
12418
  */
12421
12419
 
12422
-
12423
12420
  /**
12424
12421
  * Turn an mdast `delete` node into hast.
12425
12422
  *
@@ -12443,12 +12440,11 @@ function strikethrough(state, node) {
12443
12440
  }
12444
12441
 
12445
12442
  /**
12446
- * @typedef {import('hast').Element} Element
12447
- * @typedef {import('mdast').Emphasis} Emphasis
12448
- * @typedef {import('../state.js').State} State
12443
+ * @import {Element} from 'hast'
12444
+ * @import {Emphasis} from 'mdast'
12445
+ * @import {State} from '../state.js'
12449
12446
  */
12450
12447
 
12451
-
12452
12448
  /**
12453
12449
  * Turn an mdast `emphasis` node into hast.
12454
12450
  *
@@ -12459,7 +12455,7 @@ function strikethrough(state, node) {
12459
12455
  * @returns {Element}
12460
12456
  * hast node.
12461
12457
  */
12462
- function emphasis$2(state, node) {
12458
+ function emphasis$1(state, node) {
12463
12459
  /** @type {Element} */
12464
12460
  const result = {
12465
12461
  type: 'element',
@@ -12472,9 +12468,9 @@ function emphasis$2(state, node) {
12472
12468
  }
12473
12469
 
12474
12470
  /**
12475
- * @typedef {import('hast').Element} Element
12476
- * @typedef {import('mdast').FootnoteReference} FootnoteReference
12477
- * @typedef {import('../state.js').State} State
12471
+ * @import {Element} from 'hast'
12472
+ * @import {FootnoteReference} from 'mdast'
12473
+ * @import {State} from '../state.js'
12478
12474
  */
12479
12475
 
12480
12476
 
@@ -12542,12 +12538,11 @@ function footnoteReference$1(state, node) {
12542
12538
  }
12543
12539
 
12544
12540
  /**
12545
- * @typedef {import('hast').Element} Element
12546
- * @typedef {import('mdast').Heading} Heading
12547
- * @typedef {import('../state.js').State} State
12541
+ * @import {Element} from 'hast'
12542
+ * @import {Heading} from 'mdast'
12543
+ * @import {State} from '../state.js'
12548
12544
  */
12549
12545
 
12550
-
12551
12546
  /**
12552
12547
  * Turn an mdast `heading` node into hast.
12553
12548
  *
@@ -12558,7 +12553,7 @@ function footnoteReference$1(state, node) {
12558
12553
  * @returns {Element}
12559
12554
  * hast node.
12560
12555
  */
12561
- function heading$2(state, node) {
12556
+ function heading$1(state, node) {
12562
12557
  /** @type {Element} */
12563
12558
  const result = {
12564
12559
  type: 'element',
@@ -12571,13 +12566,12 @@ function heading$2(state, node) {
12571
12566
  }
12572
12567
 
12573
12568
  /**
12574
- * @typedef {import('hast').Element} Element
12575
- * @typedef {import('mdast').Html} Html
12576
- * @typedef {import('../state.js').State} State
12577
- * @typedef {import('../../index.js').Raw} Raw
12569
+ * @import {Element} from 'hast'
12570
+ * @import {Html} from 'mdast'
12571
+ * @import {State} from '../state.js'
12572
+ * @import {Raw} from '../../index.js'
12578
12573
  */
12579
12574
 
12580
-
12581
12575
  /**
12582
12576
  * Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
12583
12577
  * nothing).
@@ -12589,7 +12583,7 @@ function heading$2(state, node) {
12589
12583
  * @returns {Element | Raw | undefined}
12590
12584
  * hast node.
12591
12585
  */
12592
- function html$6(state, node) {
12586
+ function html$5(state, node) {
12593
12587
  if (state.options.allowDangerousHtml) {
12594
12588
  /** @type {Raw} */
12595
12589
  const result = {type: 'raw', value: node.value};
@@ -12601,15 +12595,11 @@ function html$6(state, node) {
12601
12595
  }
12602
12596
 
12603
12597
  /**
12604
- * @typedef {import('hast').ElementContent} ElementContent
12605
- *
12606
- * @typedef {import('mdast').Nodes} Nodes
12607
- * @typedef {import('mdast').Reference} Reference
12608
- *
12609
- * @typedef {import('./state.js').State} State
12598
+ * @import {ElementContent} from 'hast'
12599
+ * @import {Reference, Nodes} from 'mdast'
12600
+ * @import {State} from './state.js'
12610
12601
  */
12611
12602
 
12612
-
12613
12603
  /**
12614
12604
  * Return the content of a reference without definition as plain text.
12615
12605
  *
@@ -12655,11 +12645,9 @@ function revert(state, node) {
12655
12645
  }
12656
12646
 
12657
12647
  /**
12658
- * @typedef {import('hast').Element} Element
12659
- * @typedef {import('hast').ElementContent} ElementContent
12660
- * @typedef {import('hast').Properties} Properties
12661
- * @typedef {import('mdast').ImageReference} ImageReference
12662
- * @typedef {import('../state.js').State} State
12648
+ * @import {ElementContent, Element, Properties} from 'hast'
12649
+ * @import {ImageReference} from 'mdast'
12650
+ * @import {State} from '../state.js'
12663
12651
  */
12664
12652
 
12665
12653
 
@@ -12673,19 +12661,19 @@ function revert(state, node) {
12673
12661
  * @returns {Array<ElementContent> | ElementContent}
12674
12662
  * hast node.
12675
12663
  */
12676
- function imageReference$2(state, node) {
12664
+ function imageReference$1(state, node) {
12677
12665
  const id = String(node.identifier).toUpperCase();
12678
- const def = state.definitionById.get(id);
12666
+ const definition = state.definitionById.get(id);
12679
12667
 
12680
- if (!def) {
12668
+ if (!definition) {
12681
12669
  return revert(state, node)
12682
12670
  }
12683
12671
 
12684
12672
  /** @type {Properties} */
12685
- const properties = {src: normalizeUri(def.url || ''), alt: node.alt};
12673
+ const properties = {src: normalizeUri(definition.url || ''), alt: node.alt};
12686
12674
 
12687
- if (def.title !== null && def.title !== undefined) {
12688
- properties.title = def.title;
12675
+ if (definition.title !== null && definition.title !== undefined) {
12676
+ properties.title = definition.title;
12689
12677
  }
12690
12678
 
12691
12679
  /** @type {Element} */
@@ -12695,10 +12683,9 @@ function imageReference$2(state, node) {
12695
12683
  }
12696
12684
 
12697
12685
  /**
12698
- * @typedef {import('hast').Element} Element
12699
- * @typedef {import('hast').Properties} Properties
12700
- * @typedef {import('mdast').Image} Image
12701
- * @typedef {import('../state.js').State} State
12686
+ * @import {Element, Properties} from 'hast'
12687
+ * @import {Image} from 'mdast'
12688
+ * @import {State} from '../state.js'
12702
12689
  */
12703
12690
 
12704
12691
 
@@ -12712,7 +12699,7 @@ function imageReference$2(state, node) {
12712
12699
  * @returns {Element}
12713
12700
  * hast node.
12714
12701
  */
12715
- function image$2(state, node) {
12702
+ function image$1(state, node) {
12716
12703
  /** @type {Properties} */
12717
12704
  const properties = {src: normalizeUri(node.url)};
12718
12705
 
@@ -12731,13 +12718,11 @@ function image$2(state, node) {
12731
12718
  }
12732
12719
 
12733
12720
  /**
12734
- * @typedef {import('hast').Element} Element
12735
- * @typedef {import('hast').Text} Text
12736
- * @typedef {import('mdast').InlineCode} InlineCode
12737
- * @typedef {import('../state.js').State} State
12721
+ * @import {Element, Text} from 'hast'
12722
+ * @import {InlineCode} from 'mdast'
12723
+ * @import {State} from '../state.js'
12738
12724
  */
12739
12725
 
12740
-
12741
12726
  /**
12742
12727
  * Turn an mdast `inlineCode` node into hast.
12743
12728
  *
@@ -12748,7 +12733,7 @@ function image$2(state, node) {
12748
12733
  * @returns {Element}
12749
12734
  * hast node.
12750
12735
  */
12751
- function inlineCode$2(state, node) {
12736
+ function inlineCode$1(state, node) {
12752
12737
  /** @type {Text} */
12753
12738
  const text = {type: 'text', value: node.value.replace(/\r?\n|\r/g, ' ')};
12754
12739
  state.patch(node, text);
@@ -12765,11 +12750,9 @@ function inlineCode$2(state, node) {
12765
12750
  }
12766
12751
 
12767
12752
  /**
12768
- * @typedef {import('hast').Element} Element
12769
- * @typedef {import('hast').ElementContent} ElementContent
12770
- * @typedef {import('hast').Properties} Properties
12771
- * @typedef {import('mdast').LinkReference} LinkReference
12772
- * @typedef {import('../state.js').State} State
12753
+ * @import {ElementContent, Element, Properties} from 'hast'
12754
+ * @import {LinkReference} from 'mdast'
12755
+ * @import {State} from '../state.js'
12773
12756
  */
12774
12757
 
12775
12758
 
@@ -12783,19 +12766,19 @@ function inlineCode$2(state, node) {
12783
12766
  * @returns {Array<ElementContent> | ElementContent}
12784
12767
  * hast node.
12785
12768
  */
12786
- function linkReference$2(state, node) {
12769
+ function linkReference$1(state, node) {
12787
12770
  const id = String(node.identifier).toUpperCase();
12788
- const def = state.definitionById.get(id);
12771
+ const definition = state.definitionById.get(id);
12789
12772
 
12790
- if (!def) {
12773
+ if (!definition) {
12791
12774
  return revert(state, node)
12792
12775
  }
12793
12776
 
12794
12777
  /** @type {Properties} */
12795
- const properties = {href: normalizeUri(def.url || '')};
12778
+ const properties = {href: normalizeUri(definition.url || '')};
12796
12779
 
12797
- if (def.title !== null && def.title !== undefined) {
12798
- properties.title = def.title;
12780
+ if (definition.title !== null && definition.title !== undefined) {
12781
+ properties.title = definition.title;
12799
12782
  }
12800
12783
 
12801
12784
  /** @type {Element} */
@@ -12810,10 +12793,9 @@ function linkReference$2(state, node) {
12810
12793
  }
12811
12794
 
12812
12795
  /**
12813
- * @typedef {import('hast').Element} Element
12814
- * @typedef {import('hast').Properties} Properties
12815
- * @typedef {import('mdast').Link} Link
12816
- * @typedef {import('../state.js').State} State
12796
+ * @import {Element, Properties} from 'hast'
12797
+ * @import {Link} from 'mdast'
12798
+ * @import {State} from '../state.js'
12817
12799
  */
12818
12800
 
12819
12801
 
@@ -12827,7 +12809,7 @@ function linkReference$2(state, node) {
12827
12809
  * @returns {Element}
12828
12810
  * hast node.
12829
12811
  */
12830
- function link$2(state, node) {
12812
+ function link$1(state, node) {
12831
12813
  /** @type {Properties} */
12832
12814
  const properties = {href: normalizeUri(node.url)};
12833
12815
 
@@ -12847,15 +12829,11 @@ function link$2(state, node) {
12847
12829
  }
12848
12830
 
12849
12831
  /**
12850
- * @typedef {import('hast').Element} Element
12851
- * @typedef {import('hast').ElementContent} ElementContent
12852
- * @typedef {import('hast').Properties} Properties
12853
- * @typedef {import('mdast').ListItem} ListItem
12854
- * @typedef {import('mdast').Parents} Parents
12855
- * @typedef {import('../state.js').State} State
12832
+ * @import {ElementContent, Element, Properties} from 'hast'
12833
+ * @import {ListItem, Parents} from 'mdast'
12834
+ * @import {State} from '../state.js'
12856
12835
  */
12857
12836
 
12858
-
12859
12837
  /**
12860
12838
  * Turn an mdast `listItem` node into hast.
12861
12839
  *
@@ -12868,7 +12846,7 @@ function link$2(state, node) {
12868
12846
  * @returns {Element}
12869
12847
  * hast node.
12870
12848
  */
12871
- function listItem$2(state, node, parent) {
12849
+ function listItem$1(state, node, parent) {
12872
12850
  const results = state.all(node);
12873
12851
  const loose = parent ? listLoose(parent) : listItemLoose(node);
12874
12852
  /** @type {Properties} */
@@ -12971,13 +12949,11 @@ function listItemLoose(node) {
12971
12949
  }
12972
12950
 
12973
12951
  /**
12974
- * @typedef {import('hast').Element} Element
12975
- * @typedef {import('hast').Properties} Properties
12976
- * @typedef {import('mdast').List} List
12977
- * @typedef {import('../state.js').State} State
12952
+ * @import {Element, Properties} from 'hast'
12953
+ * @import {List} from 'mdast'
12954
+ * @import {State} from '../state.js'
12978
12955
  */
12979
12956
 
12980
-
12981
12957
  /**
12982
12958
  * Turn an mdast `list` node into hast.
12983
12959
  *
@@ -12988,7 +12964,7 @@ function listItemLoose(node) {
12988
12964
  * @returns {Element}
12989
12965
  * hast node.
12990
12966
  */
12991
- function list$2(state, node) {
12967
+ function list$1(state, node) {
12992
12968
  /** @type {Properties} */
12993
12969
  const properties = {};
12994
12970
  const results = state.all(node);
@@ -13026,12 +13002,11 @@ function list$2(state, node) {
13026
13002
  }
13027
13003
 
13028
13004
  /**
13029
- * @typedef {import('hast').Element} Element
13030
- * @typedef {import('mdast').Paragraph} Paragraph
13031
- * @typedef {import('../state.js').State} State
13005
+ * @import {Element} from 'hast'
13006
+ * @import {Paragraph} from 'mdast'
13007
+ * @import {State} from '../state.js'
13032
13008
  */
13033
13009
 
13034
-
13035
13010
  /**
13036
13011
  * Turn an mdast `paragraph` node into hast.
13037
13012
  *
@@ -13042,7 +13017,7 @@ function list$2(state, node) {
13042
13017
  * @returns {Element}
13043
13018
  * hast node.
13044
13019
  */
13045
- function paragraph$2(state, node) {
13020
+ function paragraph$1(state, node) {
13046
13021
  /** @type {Element} */
13047
13022
  const result = {
13048
13023
  type: 'element',
@@ -13055,13 +13030,11 @@ function paragraph$2(state, node) {
13055
13030
  }
13056
13031
 
13057
13032
  /**
13058
- * @typedef {import('hast').Parents} HastParents
13059
- * @typedef {import('hast').Root} HastRoot
13060
- * @typedef {import('mdast').Root} MdastRoot
13061
- * @typedef {import('../state.js').State} State
13033
+ * @import {Parents as HastParents, Root as HastRoot} from 'hast'
13034
+ * @import {Root as MdastRoot} from 'mdast'
13035
+ * @import {State} from '../state.js'
13062
13036
  */
13063
13037
 
13064
-
13065
13038
  /**
13066
13039
  * Turn an mdast `root` node into hast.
13067
13040
  *
@@ -13072,7 +13045,7 @@ function paragraph$2(state, node) {
13072
13045
  * @returns {HastParents}
13073
13046
  * hast node.
13074
13047
  */
13075
- function root$4(state, node) {
13048
+ function root$3(state, node) {
13076
13049
  /** @type {HastRoot} */
13077
13050
  const result = {type: 'root', children: state.wrap(state.all(node))};
13078
13051
  state.patch(node, result);
@@ -13080,12 +13053,11 @@ function root$4(state, node) {
13080
13053
  }
13081
13054
 
13082
13055
  /**
13083
- * @typedef {import('hast').Element} Element
13084
- * @typedef {import('mdast').Strong} Strong
13085
- * @typedef {import('../state.js').State} State
13056
+ * @import {Element} from 'hast'
13057
+ * @import {Strong} from 'mdast'
13058
+ * @import {State} from '../state.js'
13086
13059
  */
13087
13060
 
13088
-
13089
13061
  /**
13090
13062
  * Turn an mdast `strong` node into hast.
13091
13063
  *
@@ -13096,7 +13068,7 @@ function root$4(state, node) {
13096
13068
  * @returns {Element}
13097
13069
  * hast node.
13098
13070
  */
13099
- function strong$2(state, node) {
13071
+ function strong$1(state, node) {
13100
13072
  /** @type {Element} */
13101
13073
  const result = {
13102
13074
  type: 'element',
@@ -13205,9 +13177,9 @@ function position$1(node) {
13205
13177
  }
13206
13178
 
13207
13179
  /**
13208
- * @typedef {import('hast').Element} Element
13209
- * @typedef {import('mdast').Table} Table
13210
- * @typedef {import('../state.js').State} State
13180
+ * @import {Table} from 'mdast'
13181
+ * @import {Element} from 'hast'
13182
+ * @import {State} from '../state.js'
13211
13183
  */
13212
13184
 
13213
13185
 
@@ -13266,15 +13238,11 @@ function table(state, node) {
13266
13238
  }
13267
13239
 
13268
13240
  /**
13269
- * @typedef {import('hast').Element} Element
13270
- * @typedef {import('hast').ElementContent} ElementContent
13271
- * @typedef {import('hast').Properties} Properties
13272
- * @typedef {import('mdast').Parents} Parents
13273
- * @typedef {import('mdast').TableRow} TableRow
13274
- * @typedef {import('../state.js').State} State
13241
+ * @import {Element, ElementContent, Properties} from 'hast'
13242
+ * @import {Parents, TableRow} from 'mdast'
13243
+ * @import {State} from '../state.js'
13275
13244
  */
13276
13245
 
13277
-
13278
13246
  /**
13279
13247
  * Turn an mdast `tableRow` node into hast.
13280
13248
  *
@@ -13334,12 +13302,11 @@ function tableRow(state, node, parent) {
13334
13302
  }
13335
13303
 
13336
13304
  /**
13337
- * @typedef {import('hast').Element} Element
13338
- * @typedef {import('mdast').TableCell} TableCell
13339
- * @typedef {import('../state.js').State} State
13305
+ * @import {Element} from 'hast'
13306
+ * @import {TableCell} from 'mdast'
13307
+ * @import {State} from '../state.js'
13340
13308
  */
13341
13309
 
13342
-
13343
13310
  /**
13344
13311
  * Turn an mdast `tableCell` node into hast.
13345
13312
  *
@@ -13435,10 +13402,9 @@ function trimLine(value, start, end) {
13435
13402
  }
13436
13403
 
13437
13404
  /**
13438
- * @typedef {import('hast').Element} HastElement
13439
- * @typedef {import('hast').Text} HastText
13440
- * @typedef {import('mdast').Text} MdastText
13441
- * @typedef {import('../state.js').State} State
13405
+ * @import {Element as HastElement, Text as HastText} from 'hast'
13406
+ * @import {Text as MdastText} from 'mdast'
13407
+ * @import {State} from '../state.js'
13442
13408
  */
13443
13409
 
13444
13410
 
@@ -13452,7 +13418,7 @@ function trimLine(value, start, end) {
13452
13418
  * @returns {HastElement | HastText}
13453
13419
  * hast node.
13454
13420
  */
13455
- function text$5(state, node) {
13421
+ function text$4(state, node) {
13456
13422
  /** @type {HastText} */
13457
13423
  const result = {type: 'text', value: trimLines(String(node.value))};
13458
13424
  state.patch(node, result);
@@ -13460,12 +13426,11 @@ function text$5(state, node) {
13460
13426
  }
13461
13427
 
13462
13428
  /**
13463
- * @typedef {import('hast').Element} Element
13464
- * @typedef {import('mdast').ThematicBreak} ThematicBreak
13465
- * @typedef {import('../state.js').State} State
13429
+ * @import {Element} from 'hast'
13430
+ * @import {ThematicBreak} from 'mdast'
13431
+ * @import {State} from '../state.js'
13466
13432
  */
13467
13433
 
13468
-
13469
13434
  /**
13470
13435
  * Turn an mdast `thematicBreak` node into hast.
13471
13436
  *
@@ -13476,7 +13441,7 @@ function text$5(state, node) {
13476
13441
  * @returns {Element}
13477
13442
  * hast node.
13478
13443
  */
13479
- function thematicBreak$2(state, node) {
13444
+ function thematicBreak$1(state, node) {
13480
13445
  /** @type {Element} */
13481
13446
  const result = {
13482
13447
  type: 'element',
@@ -13488,36 +13453,41 @@ function thematicBreak$2(state, node) {
13488
13453
  return state.applyData(node, result)
13489
13454
  }
13490
13455
 
13456
+ /**
13457
+ * @import {Handlers} from '../state.js'
13458
+ */
13459
+
13460
+
13491
13461
  /**
13492
13462
  * Default handlers for nodes.
13493
13463
  *
13494
- * @satisfies {import('../state.js').Handlers}
13464
+ * @satisfies {Handlers}
13495
13465
  */
13496
13466
  const handlers = {
13497
- blockquote: blockquote$2,
13498
- break: hardBreak$2,
13499
- code: code$3,
13467
+ blockquote: blockquote$1,
13468
+ break: hardBreak$1,
13469
+ code: code$2,
13500
13470
  delete: strikethrough,
13501
- emphasis: emphasis$2,
13471
+ emphasis: emphasis$1,
13502
13472
  footnoteReference: footnoteReference$1,
13503
- heading: heading$2,
13504
- html: html$6,
13505
- imageReference: imageReference$2,
13506
- image: image$2,
13507
- inlineCode: inlineCode$2,
13508
- linkReference: linkReference$2,
13509
- link: link$2,
13510
- listItem: listItem$2,
13511
- list: list$2,
13512
- paragraph: paragraph$2,
13473
+ heading: heading$1,
13474
+ html: html$5,
13475
+ imageReference: imageReference$1,
13476
+ image: image$1,
13477
+ inlineCode: inlineCode$1,
13478
+ linkReference: linkReference$1,
13479
+ link: link$1,
13480
+ listItem: listItem$1,
13481
+ list: list$1,
13482
+ paragraph: paragraph$1,
13513
13483
  // @ts-expect-error: root is different, but hard to type.
13514
- root: root$4,
13515
- strong: strong$2,
13484
+ root: root$3,
13485
+ strong: strong$1,
13516
13486
  table,
13517
13487
  tableCell,
13518
13488
  tableRow,
13519
- text: text$5,
13520
- thematicBreak: thematicBreak$2,
13489
+ text: text$4,
13490
+ thematicBreak: thematicBreak$1,
13521
13491
  toml: ignore,
13522
13492
  yaml: ignore,
13523
13493
  definition: ignore,
@@ -13530,10 +13500,8 @@ function ignore() {
13530
13500
  }
13531
13501
 
13532
13502
  /**
13533
- * @typedef {import('hast').Element} Element
13534
- * @typedef {import('hast').ElementContent} ElementContent
13535
- *
13536
- * @typedef {import('./state.js').State} State
13503
+ * @import {ElementContent, Element} from 'hast'
13504
+ * @import {State} from './state.js'
13537
13505
  */
13538
13506
 
13539
13507
 
@@ -13611,14 +13579,16 @@ function footer(state) {
13611
13579
  let referenceIndex = -1;
13612
13580
 
13613
13581
  while (++referenceIndex < state.footnoteOrder.length) {
13614
- const def = state.footnoteById.get(state.footnoteOrder[referenceIndex]);
13582
+ const definition = state.footnoteById.get(
13583
+ state.footnoteOrder[referenceIndex]
13584
+ );
13615
13585
 
13616
- if (!def) {
13586
+ if (!definition) {
13617
13587
  continue
13618
13588
  }
13619
13589
 
13620
- const content = state.all(def);
13621
- const id = String(def.identifier).toUpperCase();
13590
+ const content = state.all(definition);
13591
+ const id = String(definition.identifier).toUpperCase();
13622
13592
  const safeId = normalizeUri(id.toLowerCase());
13623
13593
  let rereferenceIndex = 0;
13624
13594
  /** @type {Array<ElementContent>} */
@@ -13684,7 +13654,7 @@ function footer(state) {
13684
13654
  children: state.wrap(content, true)
13685
13655
  };
13686
13656
 
13687
- state.patch(def, listItem);
13657
+ state.patch(definition, listItem);
13688
13658
 
13689
13659
  listItems.push(listItem);
13690
13660
  }
@@ -13720,27 +13690,32 @@ function footer(state) {
13720
13690
  }
13721
13691
 
13722
13692
  /**
13723
- * @typedef {import('hast').Element} HastElement
13724
- * @typedef {import('hast').ElementContent} HastElementContent
13725
- * @typedef {import('hast').Nodes} HastNodes
13726
- * @typedef {import('hast').Properties} HastProperties
13727
- * @typedef {import('hast').RootContent} HastRootContent
13728
- * @typedef {import('hast').Text} HastText
13729
- *
13730
- * @typedef {import('mdast').Definition} MdastDefinition
13731
- * @typedef {import('mdast').FootnoteDefinition} MdastFootnoteDefinition
13732
- * @typedef {import('mdast').Nodes} MdastNodes
13733
- * @typedef {import('mdast').Parents} MdastParents
13734
- *
13735
- * @typedef {import('./footer.js').FootnoteBackContentTemplate} FootnoteBackContentTemplate
13736
- * @typedef {import('./footer.js').FootnoteBackLabelTemplate} FootnoteBackLabelTemplate
13693
+ * @import {
13694
+ * ElementContent as HastElementContent,
13695
+ * Element as HastElement,
13696
+ * Nodes as HastNodes,
13697
+ * Properties as HastProperties,
13698
+ * RootContent as HastRootContent,
13699
+ * Text as HastText
13700
+ * } from 'hast'
13701
+ * @import {
13702
+ * Definition as MdastDefinition,
13703
+ * FootnoteDefinition as MdastFootnoteDefinition,
13704
+ * Nodes as MdastNodes,
13705
+ * Parents as MdastParents
13706
+ * } from 'mdast'
13707
+ * @import {VFile} from 'vfile'
13708
+ * @import {
13709
+ * FootnoteBackContentTemplate,
13710
+ * FootnoteBackLabelTemplate
13711
+ * } from './footer.js'
13737
13712
  */
13738
13713
 
13739
13714
 
13740
- const own$7 = {}.hasOwnProperty;
13715
+ const own$5 = {}.hasOwnProperty;
13741
13716
 
13742
13717
  /** @type {Options} */
13743
- const emptyOptions$4 = {};
13718
+ const emptyOptions$2 = {};
13744
13719
 
13745
13720
  /**
13746
13721
  * Create `state` from an mdast tree.
@@ -13753,7 +13728,7 @@ const emptyOptions$4 = {};
13753
13728
  * `state` function.
13754
13729
  */
13755
13730
  function createState(tree, options) {
13756
- const settings = options || emptyOptions$4;
13731
+ const settings = options || emptyOptions$2;
13757
13732
  /** @type {Map<string, MdastDefinition>} */
13758
13733
  const definitionById = new Map();
13759
13734
  /** @type {Map<string, MdastFootnoteDefinition>} */
@@ -13810,7 +13785,7 @@ function createState(tree, options) {
13810
13785
  const type = node.type;
13811
13786
  const handle = state.handlers[type];
13812
13787
 
13813
- if (own$7.call(state.handlers, type) && handle) {
13788
+ if (own$5.call(state.handlers, type) && handle) {
13814
13789
  return handle(state, node, parent)
13815
13790
  }
13816
13791
 
@@ -13966,7 +13941,7 @@ function defaultUnknownHandler(state, node) {
13966
13941
  /** @type {HastElement | HastText} */
13967
13942
  const result =
13968
13943
  'value' in node &&
13969
- !(own$7.call(data, 'hProperties') || own$7.call(data, 'hChildren'))
13944
+ !(own$5.call(data, 'hProperties') || own$5.call(data, 'hChildren'))
13970
13945
  ? {type: 'text', value: node.value}
13971
13946
  : {
13972
13947
  type: 'element',
@@ -14033,9 +14008,9 @@ function trimMarkdownSpaceStart(value) {
14033
14008
  }
14034
14009
 
14035
14010
  /**
14036
- * @typedef {import('hast').Nodes} HastNodes
14037
- * @typedef {import('mdast').Nodes} MdastNodes
14038
- * @typedef {import('./state.js').Options} Options
14011
+ * @import {Nodes as HastNodes} from 'hast'
14012
+ * @import {Nodes as MdastNodes} from 'mdast'
14013
+ * @import {Options} from './state.js'
14039
14014
  */
14040
14015
 
14041
14016
 
@@ -14132,8 +14107,13 @@ function toHast(tree, options) {
14132
14107
  return result
14133
14108
  }
14134
14109
 
14135
- // Include `data` fields in mdast and `raw` nodes in hast.
14136
- /// <reference types="mdast-util-to-hast" />
14110
+ /**
14111
+ * @import {Root as HastRoot} from 'hast'
14112
+ * @import {Root as MdastRoot} from 'mdast'
14113
+ * @import {Options as ToHastOptions} from 'mdast-util-to-hast'
14114
+ * @import {Processor} from 'unified'
14115
+ * @import {VFile} from 'vfile'
14116
+ */
14137
14117
 
14138
14118
 
14139
14119
  /**
@@ -14143,12 +14123,15 @@ function toHast(tree, options) {
14143
14123
  *
14144
14124
  * ###### Signature
14145
14125
  *
14146
- * * if a processor is given, runs the (rehype) plugins used on it with a
14147
- * hast tree, then discards the result (*bridge mode*)
14148
- * * otherwise, returns a hast tree, the plugins used after `remarkRehype`
14149
- * are rehype plugins (*mutate mode*)
14126
+ * * if a processor is given,
14127
+ * runs the (rehype) plugins used on it with a hast tree,
14128
+ * then discards the result (*bridge mode*)
14129
+ * * otherwise,
14130
+ * returns a hast tree,
14131
+ * the plugins used after `remarkRehype` are rehype plugins (*mutate mode*)
14150
14132
  *
14151
- * > 👉 **Note**: It’s highly unlikely that you want to pass a `processor`.
14133
+ * > 👉 **Note**:
14134
+ * > It’s highly unlikely that you want to pass a `processor`.
14152
14135
  *
14153
14136
  * ###### HTML
14154
14137
  *
@@ -14156,36 +14139,40 @@ function toHast(tree, options) {
14156
14139
  * as semistandard `raw` nodes.
14157
14140
  * Most plugins ignore `raw` nodes but two notable ones don’t:
14158
14141
  *
14159
- * * `rehype-stringify` also has an option `allowDangerousHtml` which will
14160
- * output the raw HTML.
14161
- * This is typically discouraged as noted by the option name but is useful if
14162
- * you completely trust authors
14163
- * * `rehype-raw` can handle the raw embedded HTML strings by parsing them
14164
- * into standard hast nodes (`element`, `text`, etc).
14165
- * This is a heavy task as it needs a full HTML parser, but it is the only way
14166
- * to support untrusted content
14142
+ * * `rehype-stringify` also has an option `allowDangerousHtml` which will
14143
+ * output the raw HTML.
14144
+ * This is typically discouraged as noted by the option name but is useful if
14145
+ * you completely trust authors
14146
+ * * `rehype-raw` can handle the raw embedded HTML strings by parsing them
14147
+ * into standard hast nodes (`element`, `text`, etc);
14148
+ * this is a heavy task as it needs a full HTML parser,
14149
+ * but it is the only way to support untrusted content
14167
14150
  *
14168
14151
  * ###### Footnotes
14169
14152
  *
14170
14153
  * Many options supported here relate to footnotes.
14171
- * Footnotes are not specified by CommonMark, which we follow by default.
14172
- * They are supported by GitHub, so footnotes can be enabled in markdown with
14173
- * `remark-gfm`.
14154
+ * Footnotes are not specified by CommonMark,
14155
+ * which we follow by default.
14156
+ * They are supported by GitHub,
14157
+ * so footnotes can be enabled in markdown with `remark-gfm`.
14174
14158
  *
14175
14159
  * The options `footnoteBackLabel` and `footnoteLabel` define natural language
14176
- * that explains footnotes, which is hidden for sighted users but shown to
14177
- * assistive technology.
14178
- * When your page is not in English, you must define translated values.
14160
+ * that explains footnotes,
14161
+ * which is hidden for sighted users but shown to assistive technology.
14162
+ * When your page is not in English,
14163
+ * you must define translated values.
14179
14164
  *
14180
- * Back references use ARIA attributes, but the section label itself uses a
14181
- * heading that is hidden with an `sr-only` class.
14182
- * To show it to sighted users, define different attributes in
14183
- * `footnoteLabelProperties`.
14165
+ * Back references use ARIA attributes,
14166
+ * but the section label itself uses a heading that is hidden with an
14167
+ * `sr-only` class.
14168
+ * To show it to sighted users,
14169
+ * define different attributes in `footnoteLabelProperties`.
14184
14170
  *
14185
14171
  * ###### Clobbering
14186
14172
  *
14187
- * Footnotes introduces a problem, as it links footnote calls to footnote
14188
- * definitions on the page through `id` attributes generated from user content,
14173
+ * Footnotes introduces a problem,
14174
+ * as it links footnote calls to footnote definitions on the page through `id`
14175
+ * attributes generated from user content,
14189
14176
  * which results in DOM clobbering.
14190
14177
  *
14191
14178
  * DOM clobbering is this:
@@ -14207,11 +14194,13 @@ function toHast(tree, options) {
14207
14194
  * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
14208
14195
  * The default behavior for unknown nodes is:
14209
14196
  *
14210
- * * when the node has a `value` (and doesn’t have `data.hName`,
14211
- * `data.hProperties`, or `data.hChildren`, see later), create a hast `text`
14212
- * node
14213
- * * otherwise, create a `<div>` element (which could be changed with
14214
- * `data.hName`), with its children mapped from mdast to hast as well
14197
+ * * when the node has a `value`
14198
+ * (and doesn’t have `data.hName`, `data.hProperties`, or `data.hChildren`,
14199
+ * see later),
14200
+ * create a hast `text` node
14201
+ * * otherwise,
14202
+ * create a `<div>` element (which could be changed with `data.hName`),
14203
+ * with its children mapped from mdast to hast as well
14215
14204
  *
14216
14205
  * This behavior can be changed by passing an `unknownHandler`.
14217
14206
  *
@@ -14224,10 +14213,16 @@ function toHast(tree, options) {
14224
14213
  * @param {Readonly<Options> | null | undefined} [options]
14225
14214
  * @returns {TransformMutate}
14226
14215
  *
14216
+ * @overload
14217
+ * @param {Readonly<Options> | Processor | null | undefined} [destination]
14218
+ * @param {Readonly<Options> | null | undefined} [options]
14219
+ * @returns {TransformBridge | TransformMutate}
14220
+ *
14227
14221
  * @param {Readonly<Options> | Processor | null | undefined} [destination]
14228
14222
  * Processor or configuration (optional).
14229
14223
  * @param {Readonly<Options> | null | undefined} [options]
14230
- * When a processor was given, configuration (optional).
14224
+ * When a processor was given,
14225
+ * configuration (optional).
14231
14226
  * @returns {TransformBridge | TransformMutate}
14232
14227
  * Transform.
14233
14228
  */
@@ -14260,34 +14255,6 @@ function remarkRehype(destination, options) {
14260
14255
  }
14261
14256
  }
14262
14257
 
14263
- /**
14264
- * Count how often a character (or substring) is used in a string.
14265
- *
14266
- * @param {string} value
14267
- * Value to search in.
14268
- * @param {string} character
14269
- * Character (or substring) to look for.
14270
- * @return {number}
14271
- * Number of times `character` occurred in `value`.
14272
- */
14273
- function ccount(value, character) {
14274
- const source = String(value);
14275
-
14276
- if (typeof character !== 'string') {
14277
- throw new TypeError('Expected character')
14278
- }
14279
-
14280
- let count = 0;
14281
- let index = source.indexOf(character);
14282
-
14283
- while (index !== -1) {
14284
- count++;
14285
- index = source.indexOf(character, index + character.length);
14286
- }
14287
-
14288
- return count
14289
- }
14290
-
14291
14258
  function escapeStringRegexp(string) {
14292
14259
  if (typeof string !== 'string') {
14293
14260
  throw new TypeError('Expected a string');
@@ -14975,7 +14942,7 @@ function footnoteDefinition(node, _, state, info) {
14975
14942
  );
14976
14943
  tracker.shift(4);
14977
14944
  value += tracker.move(
14978
- state.indentLines(state.containerFlow(node, tracker.current()), map$4)
14945
+ state.indentLines(state.containerFlow(node, tracker.current()), map$2)
14979
14946
  );
14980
14947
  exit();
14981
14948
 
@@ -14983,7 +14950,7 @@ function footnoteDefinition(node, _, state, info) {
14983
14950
  }
14984
14951
 
14985
14952
  /** @type {Map} */
14986
- function map$4(line, index, blank) {
14953
+ function map$2(line, index, blank) {
14987
14954
  if (index === 0) {
14988
14955
  return line
14989
14956
  }
@@ -15480,11 +15447,8 @@ function toAlignment(value) {
15480
15447
  }
15481
15448
 
15482
15449
  /**
15483
- * @typedef {import('mdast').Blockquote} Blockquote
15484
- * @typedef {import('mdast').Parents} Parents
15485
- * @typedef {import('../types.js').Info} Info
15486
- * @typedef {import('../types.js').Map} Map
15487
- * @typedef {import('../types.js').State} State
15450
+ * @import {Blockquote, Parents} from 'mdast'
15451
+ * @import {Info, Map, State} from 'mdast-util-to-markdown'
15488
15452
  */
15489
15453
 
15490
15454
  /**
@@ -15494,27 +15458,26 @@ function toAlignment(value) {
15494
15458
  * @param {Info} info
15495
15459
  * @returns {string}
15496
15460
  */
15497
- function blockquote$1(node, _, state, info) {
15461
+ function blockquote(node, _, state, info) {
15498
15462
  const exit = state.enter('blockquote');
15499
15463
  const tracker = state.createTracker(info);
15500
15464
  tracker.move('> ');
15501
15465
  tracker.shift(2);
15502
15466
  const value = state.indentLines(
15503
15467
  state.containerFlow(node, tracker.current()),
15504
- map$3
15468
+ map$1
15505
15469
  );
15506
15470
  exit();
15507
15471
  return value
15508
15472
  }
15509
15473
 
15510
15474
  /** @type {Map} */
15511
- function map$3(line, _, blank) {
15475
+ function map$1(line, _, blank) {
15512
15476
  return '>' + (blank ? '' : ' ') + line
15513
15477
  }
15514
15478
 
15515
15479
  /**
15516
- * @typedef {import('../types.js').ConstructName} ConstructName
15517
- * @typedef {import('../types.js').Unsafe} Unsafe
15480
+ * @import {ConstructName, Unsafe} from 'mdast-util-to-markdown'
15518
15481
  */
15519
15482
 
15520
15483
  /**
@@ -15522,10 +15485,10 @@ function map$3(line, _, blank) {
15522
15485
  * @param {Unsafe} pattern
15523
15486
  * @returns {boolean}
15524
15487
  */
15525
- function patternInScope$1(stack, pattern) {
15488
+ function patternInScope(stack, pattern) {
15526
15489
  return (
15527
- listInScope$1(stack, pattern.inConstruct, true) &&
15528
- !listInScope$1(stack, pattern.notInConstruct, false)
15490
+ listInScope(stack, pattern.inConstruct, true) &&
15491
+ !listInScope(stack, pattern.notInConstruct, false)
15529
15492
  )
15530
15493
  }
15531
15494
 
@@ -15535,7 +15498,7 @@ function patternInScope$1(stack, pattern) {
15535
15498
  * @param {boolean} none
15536
15499
  * @returns {boolean}
15537
15500
  */
15538
- function listInScope$1(stack, list, none) {
15501
+ function listInScope(stack, list, none) {
15539
15502
  if (typeof list === 'string') {
15540
15503
  list = [list];
15541
15504
  }
@@ -15556,10 +15519,8 @@ function listInScope$1(stack, list, none) {
15556
15519
  }
15557
15520
 
15558
15521
  /**
15559
- * @typedef {import('mdast').Break} Break
15560
- * @typedef {import('mdast').Parents} Parents
15561
- * @typedef {import('../types.js').Info} Info
15562
- * @typedef {import('../types.js').State} State
15522
+ * @import {Break, Parents} from 'mdast'
15523
+ * @import {Info, State} from 'mdast-util-to-markdown'
15563
15524
  */
15564
15525
 
15565
15526
 
@@ -15570,7 +15531,7 @@ function listInScope$1(stack, list, none) {
15570
15531
  * @param {Info} info
15571
15532
  * @returns {string}
15572
15533
  */
15573
- function hardBreak$1(_, _1, state, info) {
15534
+ function hardBreak(_, _1, state, info) {
15574
15535
  let index = -1;
15575
15536
 
15576
15537
  while (++index < state.unsafe.length) {
@@ -15578,7 +15539,7 @@ function hardBreak$1(_, _1, state, info) {
15578
15539
  // space instead.
15579
15540
  if (
15580
15541
  state.unsafe[index].character === '\n' &&
15581
- patternInScope$1(state.stack, state.unsafe[index])
15542
+ patternInScope(state.stack, state.unsafe[index])
15582
15543
  ) {
15583
15544
  return /[ \t]/.test(info.before) ? '' : ' '
15584
15545
  }
@@ -15625,8 +15586,8 @@ function longestStreak(value, substring) {
15625
15586
  }
15626
15587
 
15627
15588
  /**
15628
- * @typedef {import('mdast').Code} Code
15629
- * @typedef {import('../types.js').State} State
15589
+ * @import {State} from 'mdast-util-to-markdown'
15590
+ * @import {Code} from 'mdast'
15630
15591
  */
15631
15592
 
15632
15593
  /**
@@ -15634,7 +15595,7 @@ function longestStreak(value, substring) {
15634
15595
  * @param {State} state
15635
15596
  * @returns {boolean}
15636
15597
  */
15637
- function formatCodeAsIndented$1(node, state) {
15598
+ function formatCodeAsIndented(node, state) {
15638
15599
  return Boolean(
15639
15600
  state.options.fences === false &&
15640
15601
  node.value &&
@@ -15648,15 +15609,14 @@ function formatCodeAsIndented$1(node, state) {
15648
15609
  }
15649
15610
 
15650
15611
  /**
15651
- * @typedef {import('../types.js').Options} Options
15652
- * @typedef {import('../types.js').State} State
15612
+ * @import {Options, State} from 'mdast-util-to-markdown'
15653
15613
  */
15654
15614
 
15655
15615
  /**
15656
15616
  * @param {State} state
15657
15617
  * @returns {Exclude<Options['fence'], null | undefined>}
15658
15618
  */
15659
- function checkFence$1(state) {
15619
+ function checkFence(state) {
15660
15620
  const marker = state.options.fence || '`';
15661
15621
 
15662
15622
  if (marker !== '`' && marker !== '~') {
@@ -15671,11 +15631,8 @@ function checkFence$1(state) {
15671
15631
  }
15672
15632
 
15673
15633
  /**
15674
- * @typedef {import('mdast').Code} Code
15675
- * @typedef {import('mdast').Parents} Parents
15676
- * @typedef {import('../types.js').Info} Info
15677
- * @typedef {import('../types.js').Map} Map
15678
- * @typedef {import('../types.js').State} State
15634
+ * @import {Info, Map, State} from 'mdast-util-to-markdown'
15635
+ * @import {Code, Parents} from 'mdast'
15679
15636
  */
15680
15637
 
15681
15638
 
@@ -15686,14 +15643,14 @@ function checkFence$1(state) {
15686
15643
  * @param {Info} info
15687
15644
  * @returns {string}
15688
15645
  */
15689
- function code$2(node, _, state, info) {
15690
- const marker = checkFence$1(state);
15646
+ function code$1(node, _, state, info) {
15647
+ const marker = checkFence(state);
15691
15648
  const raw = node.value || '';
15692
15649
  const suffix = marker === '`' ? 'GraveAccent' : 'Tilde';
15693
15650
 
15694
- if (formatCodeAsIndented$1(node, state)) {
15651
+ if (formatCodeAsIndented(node, state)) {
15695
15652
  const exit = state.enter('codeIndented');
15696
- const value = state.indentLines(raw, map$2);
15653
+ const value = state.indentLines(raw, map);
15697
15654
  exit();
15698
15655
  return value
15699
15656
  }
@@ -15742,20 +15699,19 @@ function code$2(node, _, state, info) {
15742
15699
  }
15743
15700
 
15744
15701
  /** @type {Map} */
15745
- function map$2(line, _, blank) {
15702
+ function map(line, _, blank) {
15746
15703
  return (blank ? '' : ' ') + line
15747
15704
  }
15748
15705
 
15749
15706
  /**
15750
- * @typedef {import('../types.js').Options} Options
15751
- * @typedef {import('../types.js').State} State
15707
+ * @import {Options, State} from 'mdast-util-to-markdown'
15752
15708
  */
15753
15709
 
15754
15710
  /**
15755
15711
  * @param {State} state
15756
15712
  * @returns {Exclude<Options['quote'], null | undefined>}
15757
15713
  */
15758
- function checkQuote$1(state) {
15714
+ function checkQuote(state) {
15759
15715
  const marker = state.options.quote || '"';
15760
15716
 
15761
15717
  if (marker !== '"' && marker !== "'") {
@@ -15770,10 +15726,8 @@ function checkQuote$1(state) {
15770
15726
  }
15771
15727
 
15772
15728
  /**
15773
- * @typedef {import('mdast').Definition} Definition
15774
- * @typedef {import('mdast').Parents} Parents
15775
- * @typedef {import('../types.js').Info} Info
15776
- * @typedef {import('../types.js').State} State
15729
+ * @import {Info, State} from 'mdast-util-to-markdown'
15730
+ * @import {Definition, Parents} from 'mdast'
15777
15731
  */
15778
15732
 
15779
15733
 
@@ -15784,8 +15738,8 @@ function checkQuote$1(state) {
15784
15738
  * @param {Info} info
15785
15739
  * @returns {string}
15786
15740
  */
15787
- function definition$1(node, _, state, info) {
15788
- const quote = checkQuote$1(state);
15741
+ function definition(node, _, state, info) {
15742
+ const quote = checkQuote(state);
15789
15743
  const suffix = quote === '"' ? 'Quote' : 'Apostrophe';
15790
15744
  const exit = state.enter('definition');
15791
15745
  let subexit = state.enter('label');
@@ -15848,15 +15802,14 @@ function definition$1(node, _, state, info) {
15848
15802
  }
15849
15803
 
15850
15804
  /**
15851
- * @typedef {import('../types.js').Options} Options
15852
- * @typedef {import('../types.js').State} State
15805
+ * @import {Options, State} from 'mdast-util-to-markdown'
15853
15806
  */
15854
15807
 
15855
15808
  /**
15856
15809
  * @param {State} state
15857
15810
  * @returns {Exclude<Options['emphasis'], null | undefined>}
15858
15811
  */
15859
- function checkEmphasis$1(state) {
15812
+ function checkEmphasis(state) {
15860
15813
  const marker = state.options.emphasis || '*';
15861
15814
 
15862
15815
  if (marker !== '*' && marker !== '_') {
@@ -15871,165 +15824,169 @@ function checkEmphasis$1(state) {
15871
15824
  }
15872
15825
 
15873
15826
  /**
15874
- * @typedef {import('mdast').Emphasis} Emphasis
15875
- * @typedef {import('mdast').Parents} Parents
15876
- * @typedef {import('../types.js').Info} Info
15877
- * @typedef {import('../types.js').State} State
15878
- */
15879
-
15880
-
15881
- emphasis$1.peek = emphasisPeek$1;
15882
-
15883
- // To do: there are cases where emphasis cannot “form” depending on the
15884
- // previous or next character of sequences.
15885
- // There’s no way around that though, except for injecting zero-width stuff.
15886
- // Do we need to safeguard against that?
15887
- /**
15888
- * @param {Emphasis} node
15889
- * @param {Parents | undefined} _
15890
- * @param {State} state
15891
- * @param {Info} info
15892
- * @returns {string}
15893
- */
15894
- function emphasis$1(node, _, state, info) {
15895
- const marker = checkEmphasis$1(state);
15896
- const exit = state.enter('emphasis');
15897
- const tracker = state.createTracker(info);
15898
- let value = tracker.move(marker);
15899
- value += tracker.move(
15900
- state.containerPhrasing(node, {
15901
- before: value,
15902
- after: marker,
15903
- ...tracker.current()
15904
- })
15905
- );
15906
- value += tracker.move(marker);
15907
- exit();
15908
- return value
15909
- }
15910
-
15911
- /**
15912
- * @param {Emphasis} _
15913
- * @param {Parents | undefined} _1
15914
- * @param {State} state
15827
+ * Encode a code point as a character reference.
15828
+ *
15829
+ * @param {number} code
15830
+ * Code point to encode.
15915
15831
  * @returns {string}
15832
+ * Encoded character reference.
15916
15833
  */
15917
- function emphasisPeek$1(_, _1, state) {
15918
- return state.options.emphasis || '*'
15834
+ function encodeCharacterReference(code) {
15835
+ return '&#x' + code.toString(16).toUpperCase() + ';'
15919
15836
  }
15920
15837
 
15921
15838
  /**
15922
- * @typedef {import('mdast').Nodes} Nodes
15923
- *
15924
- * @typedef Options
15925
- * Configuration (optional).
15926
- * @property {boolean | null | undefined} [includeImageAlt=true]
15927
- * Whether to use `alt` for `image`s (default: `true`).
15928
- * @property {boolean | null | undefined} [includeHtml=true]
15929
- * Whether to use `value` of HTML (default: `true`).
15839
+ * @import {EncodeSides} from '../types.js'
15930
15840
  */
15931
15841
 
15932
- /** @type {Options} */
15933
- const emptyOptions$3 = {};
15934
15842
 
15935
15843
  /**
15936
- * Get the text content of a node or list of nodes.
15844
+ * Check whether to encode (as a character reference) the characters
15845
+ * surrounding an attention run.
15937
15846
  *
15938
- * Prefers the node’s plain-text fields, otherwise serializes its children,
15939
- * and if the given value is an array, serialize the nodes in it.
15847
+ * Which characters are around an attention run influence whether it works or
15848
+ * not.
15940
15849
  *
15941
- * @param {unknown} [value]
15942
- * Thing to serialize, typically `Node`.
15943
- * @param {Options | null | undefined} [options]
15944
- * Configuration (optional).
15945
- * @returns {string}
15946
- * Serialized `value`.
15850
+ * See <https://github.com/orgs/syntax-tree/discussions/60> for more info.
15851
+ * See this markdown in a particular renderer to see what works:
15852
+ *
15853
+ * ```markdown
15854
+ * | | A (letter inside) | B (punctuation inside) | C (whitespace inside) | D (nothing inside) |
15855
+ * | ----------------------- | ----------------- | ---------------------- | --------------------- | ------------------ |
15856
+ * | 1 (letter outside) | x*y*z | x*.*z | x* *z | x**z |
15857
+ * | 2 (punctuation outside) | .*y*. | .*.*. | .* *. | .**. |
15858
+ * | 3 (whitespace outside) | x *y* z | x *.* z | x * * z | x ** z |
15859
+ * | 4 (nothing outside) | *x* | *.* | * * | ** |
15860
+ * ```
15861
+ *
15862
+ * @param {number} outside
15863
+ * Code point on the outer side of the run.
15864
+ * @param {number} inside
15865
+ * Code point on the inner side of the run.
15866
+ * @param {'*' | '_'} marker
15867
+ * Marker of the run.
15868
+ * Underscores are handled more strictly (they form less often) than
15869
+ * asterisks.
15870
+ * @returns {EncodeSides}
15871
+ * Whether to encode characters.
15872
+ */
15873
+ // Important: punctuation must never be encoded.
15874
+ // Punctuation is solely used by markdown constructs.
15875
+ // And by encoding itself.
15876
+ // Encoding them will break constructs or double encode things.
15877
+ function encodeInfo(outside, inside, marker) {
15878
+ const outsideKind = classifyCharacter(outside);
15879
+ const insideKind = classifyCharacter(inside);
15880
+
15881
+ // Letter outside:
15882
+ if (outsideKind === undefined) {
15883
+ return insideKind === undefined
15884
+ ? // Letter inside:
15885
+ // we have to encode *both* letters for `_` as it is looser.
15886
+ // it already forms for `*` (and GFMs `~`).
15887
+ marker === '_'
15888
+ ? {inside: true, outside: true}
15889
+ : {inside: false, outside: false}
15890
+ : insideKind === 1
15891
+ ? // Whitespace inside: encode both (letter, whitespace).
15892
+ {inside: true, outside: true}
15893
+ : // Punctuation inside: encode outer (letter)
15894
+ {inside: false, outside: true}
15895
+ }
15896
+
15897
+ // Whitespace outside:
15898
+ if (outsideKind === 1) {
15899
+ return insideKind === undefined
15900
+ ? // Letter inside: already forms.
15901
+ {inside: false, outside: false}
15902
+ : insideKind === 1
15903
+ ? // Whitespace inside: encode both (whitespace).
15904
+ {inside: true, outside: true}
15905
+ : // Punctuation inside: already forms.
15906
+ {inside: false, outside: false}
15907
+ }
15908
+
15909
+ // Punctuation outside:
15910
+ return insideKind === undefined
15911
+ ? // Letter inside: already forms.
15912
+ {inside: false, outside: false}
15913
+ : insideKind === 1
15914
+ ? // Whitespace inside: encode inner (whitespace).
15915
+ {inside: true, outside: false}
15916
+ : // Punctuation inside: already forms.
15917
+ {inside: false, outside: false}
15918
+ }
15919
+
15920
+ /**
15921
+ * @import {Info, State} from 'mdast-util-to-markdown'
15922
+ * @import {Emphasis, Parents} from 'mdast'
15947
15923
  */
15948
- function toString$1(value, options) {
15949
- const settings = emptyOptions$3;
15950
- const includeImageAlt =
15951
- typeof settings.includeImageAlt === 'boolean'
15952
- ? settings.includeImageAlt
15953
- : true;
15954
- const includeHtml =
15955
- typeof settings.includeHtml === 'boolean' ? settings.includeHtml : true;
15956
15924
 
15957
- return one$3(value, includeImageAlt, includeHtml)
15958
- }
15925
+
15926
+ emphasis.peek = emphasisPeek;
15959
15927
 
15960
15928
  /**
15961
- * One node or several nodes.
15962
- *
15963
- * @param {unknown} value
15964
- * Thing to serialize.
15965
- * @param {boolean} includeImageAlt
15966
- * Include image `alt`s.
15967
- * @param {boolean} includeHtml
15968
- * Include HTML.
15929
+ * @param {Emphasis} node
15930
+ * @param {Parents | undefined} _
15931
+ * @param {State} state
15932
+ * @param {Info} info
15969
15933
  * @returns {string}
15970
- * Serialized node.
15971
15934
  */
15972
- function one$3(value, includeImageAlt, includeHtml) {
15973
- if (node$1(value)) {
15974
- if ('value' in value) {
15975
- return value.type === 'html' && !includeHtml ? '' : value.value
15976
- }
15935
+ function emphasis(node, _, state, info) {
15936
+ const marker = checkEmphasis(state);
15937
+ const exit = state.enter('emphasis');
15938
+ const tracker = state.createTracker(info);
15939
+ const before = tracker.move(marker);
15977
15940
 
15978
- if (includeImageAlt && 'alt' in value && value.alt) {
15979
- return value.alt
15980
- }
15941
+ let between = tracker.move(
15942
+ state.containerPhrasing(node, {
15943
+ after: marker,
15944
+ before,
15945
+ ...tracker.current()
15946
+ })
15947
+ );
15948
+ const betweenHead = between.charCodeAt(0);
15949
+ const open = encodeInfo(
15950
+ info.before.charCodeAt(info.before.length - 1),
15951
+ betweenHead,
15952
+ marker
15953
+ );
15981
15954
 
15982
- if ('children' in value) {
15983
- return all$4(value.children, includeImageAlt, includeHtml)
15984
- }
15955
+ if (open.inside) {
15956
+ between = encodeCharacterReference(betweenHead) + between.slice(1);
15985
15957
  }
15986
15958
 
15987
- if (Array.isArray(value)) {
15988
- return all$4(value, includeImageAlt, includeHtml)
15959
+ const betweenTail = between.charCodeAt(between.length - 1);
15960
+ const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
15961
+
15962
+ if (close.inside) {
15963
+ between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
15989
15964
  }
15990
15965
 
15991
- return ''
15992
- }
15966
+ const after = tracker.move(marker);
15993
15967
 
15994
- /**
15995
- * Serialize a list of nodes.
15996
- *
15997
- * @param {Array<unknown>} values
15998
- * Thing to serialize.
15999
- * @param {boolean} includeImageAlt
16000
- * Include image `alt`s.
16001
- * @param {boolean} includeHtml
16002
- * Include HTML.
16003
- * @returns {string}
16004
- * Serialized nodes.
16005
- */
16006
- function all$4(values, includeImageAlt, includeHtml) {
16007
- /** @type {Array<string>} */
16008
- const result = [];
16009
- let index = -1;
16010
-
16011
- while (++index < values.length) {
16012
- result[index] = one$3(values[index], includeImageAlt, includeHtml);
16013
- }
15968
+ exit();
16014
15969
 
16015
- return result.join('')
15970
+ state.attentionEncodeSurroundingInfo = {
15971
+ after: close.outside,
15972
+ before: open.outside
15973
+ };
15974
+ return before + between + after
16016
15975
  }
16017
15976
 
16018
15977
  /**
16019
- * Check if `value` looks like a node.
16020
- *
16021
- * @param {unknown} value
16022
- * Thing.
16023
- * @returns {value is Nodes}
16024
- * Whether `value` is a node.
15978
+ * @param {Emphasis} _
15979
+ * @param {Parents | undefined} _1
15980
+ * @param {State} state
15981
+ * @returns {string}
16025
15982
  */
16026
- function node$1(value) {
16027
- return Boolean(value && typeof value === 'object')
15983
+ function emphasisPeek(_, _1, state) {
15984
+ return state.options.emphasis || '*'
16028
15985
  }
16029
15986
 
16030
15987
  /**
16031
- * @typedef {import('mdast').Heading} Heading
16032
- * @typedef {import('../types.js').State} State
15988
+ * @import {State} from 'mdast-util-to-markdown'
15989
+ * @import {Heading} from 'mdast'
16033
15990
  */
16034
15991
 
16035
15992
 
@@ -16038,7 +15995,7 @@ function node$1(value) {
16038
15995
  * @param {State} state
16039
15996
  * @returns {boolean}
16040
15997
  */
16041
- function formatHeadingAsSetext$1(node, state) {
15998
+ function formatHeadingAsSetext(node, state) {
16042
15999
  let literalWithBreak = false;
16043
16000
 
16044
16001
  // Look for literals with a line break.
@@ -16055,16 +16012,14 @@ function formatHeadingAsSetext$1(node, state) {
16055
16012
 
16056
16013
  return Boolean(
16057
16014
  (!node.depth || node.depth < 3) &&
16058
- toString$1(node) &&
16015
+ toString(node) &&
16059
16016
  (state.options.setext || literalWithBreak)
16060
16017
  )
16061
16018
  }
16062
16019
 
16063
16020
  /**
16064
- * @typedef {import('mdast').Heading} Heading
16065
- * @typedef {import('mdast').Parents} Parents
16066
- * @typedef {import('../types.js').Info} Info
16067
- * @typedef {import('../types.js').State} State
16021
+ * @import {Info, State} from 'mdast-util-to-markdown'
16022
+ * @import {Heading, Parents} from 'mdast'
16068
16023
  */
16069
16024
 
16070
16025
 
@@ -16075,11 +16030,11 @@ function formatHeadingAsSetext$1(node, state) {
16075
16030
  * @param {Info} info
16076
16031
  * @returns {string}
16077
16032
  */
16078
- function heading$1(node, _, state, info) {
16033
+ function heading(node, _, state, info) {
16079
16034
  const rank = Math.max(Math.min(6, node.depth || 1), 1);
16080
16035
  const tracker = state.createTracker(info);
16081
16036
 
16082
- if (formatHeadingAsSetext$1(node, state)) {
16037
+ if (formatHeadingAsSetext(node, state)) {
16083
16038
  const exit = state.enter('headingSetext');
16084
16039
  const subexit = state.enter('phrasing');
16085
16040
  const value = state.containerPhrasing(node, {
@@ -16121,1917 +16076,7 @@ function heading$1(node, _, state, info) {
16121
16076
 
16122
16077
  if (/^[\t ]/.test(value)) {
16123
16078
  // To do: what effect has the character reference on tracking?
16124
- value =
16125
- '&#x' +
16126
- value.charCodeAt(0).toString(16).toUpperCase() +
16127
- ';' +
16128
- value.slice(1);
16129
- }
16130
-
16131
- value = value ? sequence + ' ' + value : sequence;
16132
-
16133
- if (state.options.closeAtx) {
16134
- value += ' ' + sequence;
16135
- }
16136
-
16137
- subexit();
16138
- exit();
16139
-
16140
- return value
16141
- }
16142
-
16143
- /**
16144
- * @typedef {import('mdast').Html} Html
16145
- */
16146
-
16147
- html$5.peek = htmlPeek$1;
16148
-
16149
- /**
16150
- * @param {Html} node
16151
- * @returns {string}
16152
- */
16153
- function html$5(node) {
16154
- return node.value || ''
16155
- }
16156
-
16157
- /**
16158
- * @returns {string}
16159
- */
16160
- function htmlPeek$1() {
16161
- return '<'
16162
- }
16163
-
16164
- /**
16165
- * @typedef {import('mdast').Image} Image
16166
- * @typedef {import('mdast').Parents} Parents
16167
- * @typedef {import('../types.js').Info} Info
16168
- * @typedef {import('../types.js').State} State
16169
- */
16170
-
16171
-
16172
- image$1.peek = imagePeek$1;
16173
-
16174
- /**
16175
- * @param {Image} node
16176
- * @param {Parents | undefined} _
16177
- * @param {State} state
16178
- * @param {Info} info
16179
- * @returns {string}
16180
- */
16181
- function image$1(node, _, state, info) {
16182
- const quote = checkQuote$1(state);
16183
- const suffix = quote === '"' ? 'Quote' : 'Apostrophe';
16184
- const exit = state.enter('image');
16185
- let subexit = state.enter('label');
16186
- const tracker = state.createTracker(info);
16187
- let value = tracker.move('![');
16188
- value += tracker.move(
16189
- state.safe(node.alt, {before: value, after: ']', ...tracker.current()})
16190
- );
16191
- value += tracker.move('](');
16192
-
16193
- subexit();
16194
-
16195
- if (
16196
- // If there’s no url but there is a title…
16197
- (!node.url && node.title) ||
16198
- // If there are control characters or whitespace.
16199
- /[\0- \u007F]/.test(node.url)
16200
- ) {
16201
- subexit = state.enter('destinationLiteral');
16202
- value += tracker.move('<');
16203
- value += tracker.move(
16204
- state.safe(node.url, {before: value, after: '>', ...tracker.current()})
16205
- );
16206
- value += tracker.move('>');
16207
- } else {
16208
- // No whitespace, raw is prettier.
16209
- subexit = state.enter('destinationRaw');
16210
- value += tracker.move(
16211
- state.safe(node.url, {
16212
- before: value,
16213
- after: node.title ? ' ' : ')',
16214
- ...tracker.current()
16215
- })
16216
- );
16217
- }
16218
-
16219
- subexit();
16220
-
16221
- if (node.title) {
16222
- subexit = state.enter(`title${suffix}`);
16223
- value += tracker.move(' ' + quote);
16224
- value += tracker.move(
16225
- state.safe(node.title, {
16226
- before: value,
16227
- after: quote,
16228
- ...tracker.current()
16229
- })
16230
- );
16231
- value += tracker.move(quote);
16232
- subexit();
16233
- }
16234
-
16235
- value += tracker.move(')');
16236
- exit();
16237
-
16238
- return value
16239
- }
16240
-
16241
- /**
16242
- * @returns {string}
16243
- */
16244
- function imagePeek$1() {
16245
- return '!'
16246
- }
16247
-
16248
- /**
16249
- * @typedef {import('mdast').ImageReference} ImageReference
16250
- * @typedef {import('mdast').Parents} Parents
16251
- * @typedef {import('../types.js').Info} Info
16252
- * @typedef {import('../types.js').State} State
16253
- */
16254
-
16255
- imageReference$1.peek = imageReferencePeek$1;
16256
-
16257
- /**
16258
- * @param {ImageReference} node
16259
- * @param {Parents | undefined} _
16260
- * @param {State} state
16261
- * @param {Info} info
16262
- * @returns {string}
16263
- */
16264
- function imageReference$1(node, _, state, info) {
16265
- const type = node.referenceType;
16266
- const exit = state.enter('imageReference');
16267
- let subexit = state.enter('label');
16268
- const tracker = state.createTracker(info);
16269
- let value = tracker.move('![');
16270
- const alt = state.safe(node.alt, {
16271
- before: value,
16272
- after: ']',
16273
- ...tracker.current()
16274
- });
16275
- value += tracker.move(alt + '][');
16276
-
16277
- subexit();
16278
- // Hide the fact that we’re in phrasing, because escapes don’t work.
16279
- const stack = state.stack;
16280
- state.stack = [];
16281
- subexit = state.enter('reference');
16282
- // Note: for proper tracking, we should reset the output positions when we end
16283
- // up making a `shortcut` reference, because then there is no brace output.
16284
- // Practically, in that case, there is no content, so it doesn’t matter that
16285
- // we’ve tracked one too many characters.
16286
- const reference = state.safe(state.associationId(node), {
16287
- before: value,
16288
- after: ']',
16289
- ...tracker.current()
16290
- });
16291
- subexit();
16292
- state.stack = stack;
16293
- exit();
16294
-
16295
- if (type === 'full' || !alt || alt !== reference) {
16296
- value += tracker.move(reference + ']');
16297
- } else if (type === 'shortcut') {
16298
- // Remove the unwanted `[`.
16299
- value = value.slice(0, -1);
16300
- } else {
16301
- value += tracker.move(']');
16302
- }
16303
-
16304
- return value
16305
- }
16306
-
16307
- /**
16308
- * @returns {string}
16309
- */
16310
- function imageReferencePeek$1() {
16311
- return '!'
16312
- }
16313
-
16314
- /**
16315
- * @typedef {import('mdast').InlineCode} InlineCode
16316
- * @typedef {import('mdast').Parents} Parents
16317
- * @typedef {import('../types.js').State} State
16318
- */
16319
-
16320
- inlineCode$1.peek = inlineCodePeek$1;
16321
-
16322
- /**
16323
- * @param {InlineCode} node
16324
- * @param {Parents | undefined} _
16325
- * @param {State} state
16326
- * @returns {string}
16327
- */
16328
- function inlineCode$1(node, _, state) {
16329
- let value = node.value || '';
16330
- let sequence = '`';
16331
- let index = -1;
16332
-
16333
- // If there is a single grave accent on its own in the code, use a fence of
16334
- // two.
16335
- // If there are two in a row, use one.
16336
- while (new RegExp('(^|[^`])' + sequence + '([^`]|$)').test(value)) {
16337
- sequence += '`';
16338
- }
16339
-
16340
- // If this is not just spaces or eols (tabs don’t count), and either the
16341
- // first or last character are a space, eol, or tick, then pad with spaces.
16342
- if (
16343
- /[^ \r\n]/.test(value) &&
16344
- ((/^[ \r\n]/.test(value) && /[ \r\n]$/.test(value)) || /^`|`$/.test(value))
16345
- ) {
16346
- value = ' ' + value + ' ';
16347
- }
16348
-
16349
- // We have a potential problem: certain characters after eols could result in
16350
- // blocks being seen.
16351
- // For example, if someone injected the string `'\n# b'`, then that would
16352
- // result in an ATX heading.
16353
- // We can’t escape characters in `inlineCode`, but because eols are
16354
- // transformed to spaces when going from markdown to HTML anyway, we can swap
16355
- // them out.
16356
- while (++index < state.unsafe.length) {
16357
- const pattern = state.unsafe[index];
16358
- const expression = state.compilePattern(pattern);
16359
- /** @type {RegExpExecArray | null} */
16360
- let match;
16361
-
16362
- // Only look for `atBreak`s.
16363
- // Btw: note that `atBreak` patterns will always start the regex at LF or
16364
- // CR.
16365
- if (!pattern.atBreak) continue
16366
-
16367
- while ((match = expression.exec(value))) {
16368
- let position = match.index;
16369
-
16370
- // Support CRLF (patterns only look for one of the characters).
16371
- if (
16372
- value.charCodeAt(position) === 10 /* `\n` */ &&
16373
- value.charCodeAt(position - 1) === 13 /* `\r` */
16374
- ) {
16375
- position--;
16376
- }
16377
-
16378
- value = value.slice(0, position) + ' ' + value.slice(match.index + 1);
16379
- }
16380
- }
16381
-
16382
- return sequence + value + sequence
16383
- }
16384
-
16385
- /**
16386
- * @returns {string}
16387
- */
16388
- function inlineCodePeek$1() {
16389
- return '`'
16390
- }
16391
-
16392
- /**
16393
- * @typedef {import('mdast').Link} Link
16394
- * @typedef {import('../types.js').State} State
16395
- */
16396
-
16397
-
16398
- /**
16399
- * @param {Link} node
16400
- * @param {State} state
16401
- * @returns {boolean}
16402
- */
16403
- function formatLinkAsAutolink$1(node, state) {
16404
- const raw = toString$1(node);
16405
-
16406
- return Boolean(
16407
- !state.options.resourceLink &&
16408
- // If there’s a url…
16409
- node.url &&
16410
- // And there’s a no title…
16411
- !node.title &&
16412
- // And the content of `node` is a single text node…
16413
- node.children &&
16414
- node.children.length === 1 &&
16415
- node.children[0].type === 'text' &&
16416
- // And if the url is the same as the content…
16417
- (raw === node.url || 'mailto:' + raw === node.url) &&
16418
- // And that starts w/ a protocol…
16419
- /^[a-z][a-z+.-]+:/i.test(node.url) &&
16420
- // And that doesn’t contain ASCII control codes (character escapes and
16421
- // references don’t work), space, or angle brackets…
16422
- !/[\0- <>\u007F]/.test(node.url)
16423
- )
16424
- }
16425
-
16426
- /**
16427
- * @typedef {import('mdast').Link} Link
16428
- * @typedef {import('mdast').Parents} Parents
16429
- * @typedef {import('../types.js').Exit} Exit
16430
- * @typedef {import('../types.js').Info} Info
16431
- * @typedef {import('../types.js').State} State
16432
- */
16433
-
16434
-
16435
- link$1.peek = linkPeek$1;
16436
-
16437
- /**
16438
- * @param {Link} node
16439
- * @param {Parents | undefined} _
16440
- * @param {State} state
16441
- * @param {Info} info
16442
- * @returns {string}
16443
- */
16444
- function link$1(node, _, state, info) {
16445
- const quote = checkQuote$1(state);
16446
- const suffix = quote === '"' ? 'Quote' : 'Apostrophe';
16447
- const tracker = state.createTracker(info);
16448
- /** @type {Exit} */
16449
- let exit;
16450
- /** @type {Exit} */
16451
- let subexit;
16452
-
16453
- if (formatLinkAsAutolink$1(node, state)) {
16454
- // Hide the fact that we’re in phrasing, because escapes don’t work.
16455
- const stack = state.stack;
16456
- state.stack = [];
16457
- exit = state.enter('autolink');
16458
- let value = tracker.move('<');
16459
- value += tracker.move(
16460
- state.containerPhrasing(node, {
16461
- before: value,
16462
- after: '>',
16463
- ...tracker.current()
16464
- })
16465
- );
16466
- value += tracker.move('>');
16467
- exit();
16468
- state.stack = stack;
16469
- return value
16470
- }
16471
-
16472
- exit = state.enter('link');
16473
- subexit = state.enter('label');
16474
- let value = tracker.move('[');
16475
- value += tracker.move(
16476
- state.containerPhrasing(node, {
16477
- before: value,
16478
- after: '](',
16479
- ...tracker.current()
16480
- })
16481
- );
16482
- value += tracker.move('](');
16483
- subexit();
16484
-
16485
- if (
16486
- // If there’s no url but there is a title…
16487
- (!node.url && node.title) ||
16488
- // If there are control characters or whitespace.
16489
- /[\0- \u007F]/.test(node.url)
16490
- ) {
16491
- subexit = state.enter('destinationLiteral');
16492
- value += tracker.move('<');
16493
- value += tracker.move(
16494
- state.safe(node.url, {before: value, after: '>', ...tracker.current()})
16495
- );
16496
- value += tracker.move('>');
16497
- } else {
16498
- // No whitespace, raw is prettier.
16499
- subexit = state.enter('destinationRaw');
16500
- value += tracker.move(
16501
- state.safe(node.url, {
16502
- before: value,
16503
- after: node.title ? ' ' : ')',
16504
- ...tracker.current()
16505
- })
16506
- );
16507
- }
16508
-
16509
- subexit();
16510
-
16511
- if (node.title) {
16512
- subexit = state.enter(`title${suffix}`);
16513
- value += tracker.move(' ' + quote);
16514
- value += tracker.move(
16515
- state.safe(node.title, {
16516
- before: value,
16517
- after: quote,
16518
- ...tracker.current()
16519
- })
16520
- );
16521
- value += tracker.move(quote);
16522
- subexit();
16523
- }
16524
-
16525
- value += tracker.move(')');
16526
-
16527
- exit();
16528
- return value
16529
- }
16530
-
16531
- /**
16532
- * @param {Link} node
16533
- * @param {Parents | undefined} _
16534
- * @param {State} state
16535
- * @returns {string}
16536
- */
16537
- function linkPeek$1(node, _, state) {
16538
- return formatLinkAsAutolink$1(node, state) ? '<' : '['
16539
- }
16540
-
16541
- /**
16542
- * @typedef {import('mdast').LinkReference} LinkReference
16543
- * @typedef {import('mdast').Parents} Parents
16544
- * @typedef {import('../types.js').Info} Info
16545
- * @typedef {import('../types.js').State} State
16546
- */
16547
-
16548
- linkReference$1.peek = linkReferencePeek$1;
16549
-
16550
- /**
16551
- * @param {LinkReference} node
16552
- * @param {Parents | undefined} _
16553
- * @param {State} state
16554
- * @param {Info} info
16555
- * @returns {string}
16556
- */
16557
- function linkReference$1(node, _, state, info) {
16558
- const type = node.referenceType;
16559
- const exit = state.enter('linkReference');
16560
- let subexit = state.enter('label');
16561
- const tracker = state.createTracker(info);
16562
- let value = tracker.move('[');
16563
- const text = state.containerPhrasing(node, {
16564
- before: value,
16565
- after: ']',
16566
- ...tracker.current()
16567
- });
16568
- value += tracker.move(text + '][');
16569
-
16570
- subexit();
16571
- // Hide the fact that we’re in phrasing, because escapes don’t work.
16572
- const stack = state.stack;
16573
- state.stack = [];
16574
- subexit = state.enter('reference');
16575
- // Note: for proper tracking, we should reset the output positions when we end
16576
- // up making a `shortcut` reference, because then there is no brace output.
16577
- // Practically, in that case, there is no content, so it doesn’t matter that
16578
- // we’ve tracked one too many characters.
16579
- const reference = state.safe(state.associationId(node), {
16580
- before: value,
16581
- after: ']',
16582
- ...tracker.current()
16583
- });
16584
- subexit();
16585
- state.stack = stack;
16586
- exit();
16587
-
16588
- if (type === 'full' || !text || text !== reference) {
16589
- value += tracker.move(reference + ']');
16590
- } else if (type === 'shortcut') {
16591
- // Remove the unwanted `[`.
16592
- value = value.slice(0, -1);
16593
- } else {
16594
- value += tracker.move(']');
16595
- }
16596
-
16597
- return value
16598
- }
16599
-
16600
- /**
16601
- * @returns {string}
16602
- */
16603
- function linkReferencePeek$1() {
16604
- return '['
16605
- }
16606
-
16607
- /**
16608
- * @typedef {import('../types.js').Options} Options
16609
- * @typedef {import('../types.js').State} State
16610
- */
16611
-
16612
- /**
16613
- * @param {State} state
16614
- * @returns {Exclude<Options['bullet'], null | undefined>}
16615
- */
16616
- function checkBullet$1(state) {
16617
- const marker = state.options.bullet || '*';
16618
-
16619
- if (marker !== '*' && marker !== '+' && marker !== '-') {
16620
- throw new Error(
16621
- 'Cannot serialize items with `' +
16622
- marker +
16623
- '` for `options.bullet`, expected `*`, `+`, or `-`'
16624
- )
16625
- }
16626
-
16627
- return marker
16628
- }
16629
-
16630
- /**
16631
- * @typedef {import('../types.js').Options} Options
16632
- * @typedef {import('../types.js').State} State
16633
- */
16634
-
16635
-
16636
- /**
16637
- * @param {State} state
16638
- * @returns {Exclude<Options['bullet'], null | undefined>}
16639
- */
16640
- function checkBulletOther$1(state) {
16641
- const bullet = checkBullet$1(state);
16642
- const bulletOther = state.options.bulletOther;
16643
-
16644
- if (!bulletOther) {
16645
- return bullet === '*' ? '-' : '*'
16646
- }
16647
-
16648
- if (bulletOther !== '*' && bulletOther !== '+' && bulletOther !== '-') {
16649
- throw new Error(
16650
- 'Cannot serialize items with `' +
16651
- bulletOther +
16652
- '` for `options.bulletOther`, expected `*`, `+`, or `-`'
16653
- )
16654
- }
16655
-
16656
- if (bulletOther === bullet) {
16657
- throw new Error(
16658
- 'Expected `bullet` (`' +
16659
- bullet +
16660
- '`) and `bulletOther` (`' +
16661
- bulletOther +
16662
- '`) to be different'
16663
- )
16664
- }
16665
-
16666
- return bulletOther
16667
- }
16668
-
16669
- /**
16670
- * @typedef {import('../types.js').Options} Options
16671
- * @typedef {import('../types.js').State} State
16672
- */
16673
-
16674
- /**
16675
- * @param {State} state
16676
- * @returns {Exclude<Options['bulletOrdered'], null | undefined>}
16677
- */
16678
- function checkBulletOrdered$1(state) {
16679
- const marker = state.options.bulletOrdered || '.';
16680
-
16681
- if (marker !== '.' && marker !== ')') {
16682
- throw new Error(
16683
- 'Cannot serialize items with `' +
16684
- marker +
16685
- '` for `options.bulletOrdered`, expected `.` or `)`'
16686
- )
16687
- }
16688
-
16689
- return marker
16690
- }
16691
-
16692
- /**
16693
- * @typedef {import('../types.js').Options} Options
16694
- * @typedef {import('../types.js').State} State
16695
- */
16696
-
16697
- /**
16698
- * @param {State} state
16699
- * @returns {Exclude<Options['rule'], null | undefined>}
16700
- */
16701
- function checkRule$1(state) {
16702
- const marker = state.options.rule || '*';
16703
-
16704
- if (marker !== '*' && marker !== '-' && marker !== '_') {
16705
- throw new Error(
16706
- 'Cannot serialize rules with `' +
16707
- marker +
16708
- '` for `options.rule`, expected `*`, `-`, or `_`'
16709
- )
16710
- }
16711
-
16712
- return marker
16713
- }
16714
-
16715
- /**
16716
- * @typedef {import('mdast').List} List
16717
- * @typedef {import('mdast').Parents} Parents
16718
- * @typedef {import('../types.js').Info} Info
16719
- * @typedef {import('../types.js').State} State
16720
- */
16721
-
16722
-
16723
- /**
16724
- * @param {List} node
16725
- * @param {Parents | undefined} parent
16726
- * @param {State} state
16727
- * @param {Info} info
16728
- * @returns {string}
16729
- */
16730
- function list$1(node, parent, state, info) {
16731
- const exit = state.enter('list');
16732
- const bulletCurrent = state.bulletCurrent;
16733
- /** @type {string} */
16734
- let bullet = node.ordered ? checkBulletOrdered$1(state) : checkBullet$1(state);
16735
- /** @type {string} */
16736
- const bulletOther = node.ordered
16737
- ? bullet === '.'
16738
- ? ')'
16739
- : '.'
16740
- : checkBulletOther$1(state);
16741
- let useDifferentMarker =
16742
- parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false;
16743
-
16744
- if (!node.ordered) {
16745
- const firstListItem = node.children ? node.children[0] : undefined;
16746
-
16747
- // If there’s an empty first list item directly in two list items,
16748
- // we have to use a different bullet:
16749
- //
16750
- // ```markdown
16751
- // * - *
16752
- // ```
16753
- //
16754
- // …because otherwise it would become one big thematic break.
16755
- if (
16756
- // Bullet could be used as a thematic break marker:
16757
- (bullet === '*' || bullet === '-') &&
16758
- // Empty first list item:
16759
- firstListItem &&
16760
- (!firstListItem.children || !firstListItem.children[0]) &&
16761
- // Directly in two other list items:
16762
- state.stack[state.stack.length - 1] === 'list' &&
16763
- state.stack[state.stack.length - 2] === 'listItem' &&
16764
- state.stack[state.stack.length - 3] === 'list' &&
16765
- state.stack[state.stack.length - 4] === 'listItem' &&
16766
- // That are each the first child.
16767
- state.indexStack[state.indexStack.length - 1] === 0 &&
16768
- state.indexStack[state.indexStack.length - 2] === 0 &&
16769
- state.indexStack[state.indexStack.length - 3] === 0
16770
- ) {
16771
- useDifferentMarker = true;
16772
- }
16773
-
16774
- // If there’s a thematic break at the start of the first list item,
16775
- // we have to use a different bullet:
16776
- //
16777
- // ```markdown
16778
- // * ---
16779
- // ```
16780
- //
16781
- // …because otherwise it would become one big thematic break.
16782
- if (checkRule$1(state) === bullet && firstListItem) {
16783
- let index = -1;
16784
-
16785
- while (++index < node.children.length) {
16786
- const item = node.children[index];
16787
-
16788
- if (
16789
- item &&
16790
- item.type === 'listItem' &&
16791
- item.children &&
16792
- item.children[0] &&
16793
- item.children[0].type === 'thematicBreak'
16794
- ) {
16795
- useDifferentMarker = true;
16796
- break
16797
- }
16798
- }
16799
- }
16800
- }
16801
-
16802
- if (useDifferentMarker) {
16803
- bullet = bulletOther;
16804
- }
16805
-
16806
- state.bulletCurrent = bullet;
16807
- const value = state.containerFlow(node, info);
16808
- state.bulletLastUsed = bullet;
16809
- state.bulletCurrent = bulletCurrent;
16810
- exit();
16811
- return value
16812
- }
16813
-
16814
- /**
16815
- * @typedef {import('../types.js').Options} Options
16816
- * @typedef {import('../types.js').State} State
16817
- */
16818
-
16819
- /**
16820
- * @param {State} state
16821
- * @returns {Exclude<Options['listItemIndent'], null | undefined>}
16822
- */
16823
- function checkListItemIndent$1(state) {
16824
- const style = state.options.listItemIndent || 'one';
16825
-
16826
- if (style !== 'tab' && style !== 'one' && style !== 'mixed') {
16827
- throw new Error(
16828
- 'Cannot serialize items with `' +
16829
- style +
16830
- '` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`'
16831
- )
16832
- }
16833
-
16834
- return style
16835
- }
16836
-
16837
- /**
16838
- * @typedef {import('mdast').ListItem} ListItem
16839
- * @typedef {import('mdast').Parents} Parents
16840
- * @typedef {import('../types.js').Info} Info
16841
- * @typedef {import('../types.js').Map} Map
16842
- * @typedef {import('../types.js').State} State
16843
- */
16844
-
16845
-
16846
- /**
16847
- * @param {ListItem} node
16848
- * @param {Parents | undefined} parent
16849
- * @param {State} state
16850
- * @param {Info} info
16851
- * @returns {string}
16852
- */
16853
- function listItem$1(node, parent, state, info) {
16854
- const listItemIndent = checkListItemIndent$1(state);
16855
- let bullet = state.bulletCurrent || checkBullet$1(state);
16856
-
16857
- // Add the marker value for ordered lists.
16858
- if (parent && parent.type === 'list' && parent.ordered) {
16859
- bullet =
16860
- (typeof parent.start === 'number' && parent.start > -1
16861
- ? parent.start
16862
- : 1) +
16863
- (state.options.incrementListMarker === false
16864
- ? 0
16865
- : parent.children.indexOf(node)) +
16866
- bullet;
16867
- }
16868
-
16869
- let size = bullet.length + 1;
16870
-
16871
- if (
16872
- listItemIndent === 'tab' ||
16873
- (listItemIndent === 'mixed' &&
16874
- ((parent && parent.type === 'list' && parent.spread) || node.spread))
16875
- ) {
16876
- size = Math.ceil(size / 4) * 4;
16877
- }
16878
-
16879
- const tracker = state.createTracker(info);
16880
- tracker.move(bullet + ' '.repeat(size - bullet.length));
16881
- tracker.shift(size);
16882
- const exit = state.enter('listItem');
16883
- const value = state.indentLines(
16884
- state.containerFlow(node, tracker.current()),
16885
- map
16886
- );
16887
- exit();
16888
-
16889
- return value
16890
-
16891
- /** @type {Map} */
16892
- function map(line, index, blank) {
16893
- if (index) {
16894
- return (blank ? '' : ' '.repeat(size)) + line
16895
- }
16896
-
16897
- return (blank ? bullet : bullet + ' '.repeat(size - bullet.length)) + line
16898
- }
16899
- }
16900
-
16901
- /**
16902
- * @typedef {import('mdast').Paragraph} Paragraph
16903
- * @typedef {import('mdast').Parents} Parents
16904
- * @typedef {import('../types.js').Info} Info
16905
- * @typedef {import('../types.js').State} State
16906
- */
16907
-
16908
- /**
16909
- * @param {Paragraph} node
16910
- * @param {Parents | undefined} _
16911
- * @param {State} state
16912
- * @param {Info} info
16913
- * @returns {string}
16914
- */
16915
- function paragraph$1(node, _, state, info) {
16916
- const exit = state.enter('paragraph');
16917
- const subexit = state.enter('phrasing');
16918
- const value = state.containerPhrasing(node, info);
16919
- subexit();
16920
- exit();
16921
- return value
16922
- }
16923
-
16924
- /**
16925
- * @typedef {import('mdast').PhrasingContent} PhrasingContent
16926
- */
16927
-
16928
-
16929
- /**
16930
- * Check if the given value is *phrasing content*.
16931
- *
16932
- * > 👉 **Note**: Excludes `html`, which can be both phrasing or flow.
16933
- *
16934
- * @param node
16935
- * Thing to check, typically `Node`.
16936
- * @returns
16937
- * Whether `value` is phrasing content.
16938
- */
16939
-
16940
- const phrasing =
16941
- /** @type {(node?: unknown) => node is PhrasingContent} */
16942
- (
16943
- convert([
16944
- 'break',
16945
- 'delete',
16946
- 'emphasis',
16947
- 'footnote',
16948
- 'footnoteReference',
16949
- 'image',
16950
- 'imageReference',
16951
- 'inlineCode',
16952
- 'link',
16953
- 'linkReference',
16954
- 'strong',
16955
- 'text'
16956
- ])
16957
- );
16958
-
16959
- /**
16960
- * @typedef {import('mdast').Parents} Parents
16961
- * @typedef {import('mdast').Root} Root
16962
- * @typedef {import('../types.js').Info} Info
16963
- * @typedef {import('../types.js').State} State
16964
- */
16965
-
16966
-
16967
- /**
16968
- * @param {Root} node
16969
- * @param {Parents | undefined} _
16970
- * @param {State} state
16971
- * @param {Info} info
16972
- * @returns {string}
16973
- */
16974
- function root$3(node, _, state, info) {
16975
- // Note: `html` nodes are ambiguous.
16976
- const hasPhrasing = node.children.some(function (d) {
16977
- return phrasing(d)
16978
- });
16979
- const fn = hasPhrasing ? state.containerPhrasing : state.containerFlow;
16980
- return fn.call(state, node, info)
16981
- }
16982
-
16983
- /**
16984
- * @typedef {import('../types.js').Options} Options
16985
- * @typedef {import('../types.js').State} State
16986
- */
16987
-
16988
- /**
16989
- * @param {State} state
16990
- * @returns {Exclude<Options['strong'], null | undefined>}
16991
- */
16992
- function checkStrong$1(state) {
16993
- const marker = state.options.strong || '*';
16994
-
16995
- if (marker !== '*' && marker !== '_') {
16996
- throw new Error(
16997
- 'Cannot serialize strong with `' +
16998
- marker +
16999
- '` for `options.strong`, expected `*`, or `_`'
17000
- )
17001
- }
17002
-
17003
- return marker
17004
- }
17005
-
17006
- /**
17007
- * @typedef {import('mdast').Parents} Parents
17008
- * @typedef {import('mdast').Strong} Strong
17009
- * @typedef {import('../types.js').Info} Info
17010
- * @typedef {import('../types.js').State} State
17011
- */
17012
-
17013
-
17014
- strong$1.peek = strongPeek$1;
17015
-
17016
- // To do: there are cases where emphasis cannot “form” depending on the
17017
- // previous or next character of sequences.
17018
- // There’s no way around that though, except for injecting zero-width stuff.
17019
- // Do we need to safeguard against that?
17020
- /**
17021
- * @param {Strong} node
17022
- * @param {Parents | undefined} _
17023
- * @param {State} state
17024
- * @param {Info} info
17025
- * @returns {string}
17026
- */
17027
- function strong$1(node, _, state, info) {
17028
- const marker = checkStrong$1(state);
17029
- const exit = state.enter('strong');
17030
- const tracker = state.createTracker(info);
17031
- let value = tracker.move(marker + marker);
17032
- value += tracker.move(
17033
- state.containerPhrasing(node, {
17034
- before: value,
17035
- after: marker,
17036
- ...tracker.current()
17037
- })
17038
- );
17039
- value += tracker.move(marker + marker);
17040
- exit();
17041
- return value
17042
- }
17043
-
17044
- /**
17045
- * @param {Strong} _
17046
- * @param {Parents | undefined} _1
17047
- * @param {State} state
17048
- * @returns {string}
17049
- */
17050
- function strongPeek$1(_, _1, state) {
17051
- return state.options.strong || '*'
17052
- }
17053
-
17054
- /**
17055
- * @typedef {import('mdast').Parents} Parents
17056
- * @typedef {import('mdast').Text} Text
17057
- * @typedef {import('../types.js').Info} Info
17058
- * @typedef {import('../types.js').State} State
17059
- */
17060
-
17061
- /**
17062
- * @param {Text} node
17063
- * @param {Parents | undefined} _
17064
- * @param {State} state
17065
- * @param {Info} info
17066
- * @returns {string}
17067
- */
17068
- function text$4(node, _, state, info) {
17069
- return state.safe(node.value, info)
17070
- }
17071
-
17072
- /**
17073
- * @typedef {import('../types.js').Options} Options
17074
- * @typedef {import('../types.js').State} State
17075
- */
17076
-
17077
- /**
17078
- * @param {State} state
17079
- * @returns {Exclude<Options['ruleRepetition'], null | undefined>}
17080
- */
17081
- function checkRuleRepetition$1(state) {
17082
- const repetition = state.options.ruleRepetition || 3;
17083
-
17084
- if (repetition < 3) {
17085
- throw new Error(
17086
- 'Cannot serialize rules with repetition `' +
17087
- repetition +
17088
- '` for `options.ruleRepetition`, expected `3` or more'
17089
- )
17090
- }
17091
-
17092
- return repetition
17093
- }
17094
-
17095
- /**
17096
- * @typedef {import('mdast').Parents} Parents
17097
- * @typedef {import('mdast').ThematicBreak} ThematicBreak
17098
- * @typedef {import('../types.js').State} State
17099
- */
17100
-
17101
-
17102
- /**
17103
- * @param {ThematicBreak} _
17104
- * @param {Parents | undefined} _1
17105
- * @param {State} state
17106
- * @returns {string}
17107
- */
17108
- function thematicBreak$1(_, _1, state) {
17109
- const value = (
17110
- checkRule$1(state) + (state.options.ruleSpaces ? ' ' : '')
17111
- ).repeat(checkRuleRepetition$1(state));
17112
-
17113
- return state.options.ruleSpaces ? value.slice(0, -1) : value
17114
- }
17115
-
17116
- /**
17117
- * Default (CommonMark) handlers.
17118
- */
17119
- const handle$1 = {
17120
- blockquote: blockquote$1,
17121
- break: hardBreak$1,
17122
- code: code$2,
17123
- definition: definition$1,
17124
- emphasis: emphasis$1,
17125
- hardBreak: hardBreak$1,
17126
- heading: heading$1,
17127
- html: html$5,
17128
- image: image$1,
17129
- imageReference: imageReference$1,
17130
- inlineCode: inlineCode$1,
17131
- link: link$1,
17132
- linkReference: linkReference$1,
17133
- list: list$1,
17134
- listItem: listItem$1,
17135
- paragraph: paragraph$1,
17136
- root: root$3,
17137
- strong: strong$1,
17138
- text: text$4,
17139
- thematicBreak: thematicBreak$1
17140
- };
17141
-
17142
- /**
17143
- * @typedef {import('mdast').InlineCode} InlineCode
17144
- * @typedef {import('mdast').Table} Table
17145
- * @typedef {import('mdast').TableCell} TableCell
17146
- * @typedef {import('mdast').TableRow} TableRow
17147
- *
17148
- * @typedef {import('markdown-table').Options} MarkdownTableOptions
17149
- *
17150
- * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
17151
- * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
17152
- * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
17153
- *
17154
- * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
17155
- * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
17156
- * @typedef {import('mdast-util-to-markdown').State} State
17157
- * @typedef {import('mdast-util-to-markdown').Info} Info
17158
- */
17159
-
17160
-
17161
- /**
17162
- * Create an extension for `mdast-util-from-markdown` to enable GFM tables in
17163
- * markdown.
17164
- *
17165
- * @returns {FromMarkdownExtension}
17166
- * Extension for `mdast-util-from-markdown` to enable GFM tables.
17167
- */
17168
- function gfmTableFromMarkdown() {
17169
- return {
17170
- enter: {
17171
- table: enterTable,
17172
- tableData: enterCell,
17173
- tableHeader: enterCell,
17174
- tableRow: enterRow
17175
- },
17176
- exit: {
17177
- codeText: exitCodeText,
17178
- table: exitTable,
17179
- tableData: exit,
17180
- tableHeader: exit,
17181
- tableRow: exit
17182
- }
17183
- }
17184
- }
17185
-
17186
- /**
17187
- * @this {CompileContext}
17188
- * @type {FromMarkdownHandle}
17189
- */
17190
- function enterTable(token) {
17191
- const align = token._align;
17192
- this.enter(
17193
- {
17194
- type: 'table',
17195
- align: align.map(function (d) {
17196
- return d === 'none' ? null : d
17197
- }),
17198
- children: []
17199
- },
17200
- token
17201
- );
17202
- this.data.inTable = true;
17203
- }
17204
-
17205
- /**
17206
- * @this {CompileContext}
17207
- * @type {FromMarkdownHandle}
17208
- */
17209
- function exitTable(token) {
17210
- this.exit(token);
17211
- this.data.inTable = undefined;
17212
- }
17213
-
17214
- /**
17215
- * @this {CompileContext}
17216
- * @type {FromMarkdownHandle}
17217
- */
17218
- function enterRow(token) {
17219
- this.enter({type: 'tableRow', children: []}, token);
17220
- }
17221
-
17222
- /**
17223
- * @this {CompileContext}
17224
- * @type {FromMarkdownHandle}
17225
- */
17226
- function exit(token) {
17227
- this.exit(token);
17228
- }
17229
-
17230
- /**
17231
- * @this {CompileContext}
17232
- * @type {FromMarkdownHandle}
17233
- */
17234
- function enterCell(token) {
17235
- this.enter({type: 'tableCell', children: []}, token);
17236
- }
17237
-
17238
- // Overwrite the default code text data handler to unescape escaped pipes when
17239
- // they are in tables.
17240
- /**
17241
- * @this {CompileContext}
17242
- * @type {FromMarkdownHandle}
17243
- */
17244
- function exitCodeText(token) {
17245
- let value = this.resume();
17246
-
17247
- if (this.data.inTable) {
17248
- value = value.replace(/\\([\\|])/g, replace);
17249
- }
17250
-
17251
- const node = this.stack[this.stack.length - 1];
17252
- node.value = value;
17253
- this.exit(token);
17254
- }
17255
-
17256
- /**
17257
- * @param {string} $0
17258
- * @param {string} $1
17259
- * @returns {string}
17260
- */
17261
- function replace($0, $1) {
17262
- // Pipes work, backslashes don’t (but can’t escape pipes).
17263
- return $1 === '|' ? $1 : $0
17264
- }
17265
-
17266
- /**
17267
- * Create an extension for `mdast-util-to-markdown` to enable GFM tables in
17268
- * markdown.
17269
- *
17270
- * @param {Options | null | undefined} [options]
17271
- * Configuration.
17272
- * @returns {ToMarkdownExtension}
17273
- * Extension for `mdast-util-to-markdown` to enable GFM tables.
17274
- */
17275
- function gfmTableToMarkdown(options) {
17276
- const settings = options || {};
17277
- const padding = settings.tableCellPadding;
17278
- const alignDelimiters = settings.tablePipeAlign;
17279
- const stringLength = settings.stringLength;
17280
- const around = padding ? ' ' : '|';
17281
-
17282
- return {
17283
- unsafe: [
17284
- {character: '\r', inConstruct: 'tableCell'},
17285
- {character: '\n', inConstruct: 'tableCell'},
17286
- // A pipe, when followed by a tab or space (padding), or a dash or colon
17287
- // (unpadded delimiter row), could result in a table.
17288
- {atBreak: true, character: '|', after: '[\t :-]'},
17289
- // A pipe in a cell must be encoded.
17290
- {character: '|', inConstruct: 'tableCell'},
17291
- // A colon must be followed by a dash, in which case it could start a
17292
- // delimiter row.
17293
- {atBreak: true, character: ':', after: '-'},
17294
- // A delimiter row can also start with a dash, when followed by more
17295
- // dashes, a colon, or a pipe.
17296
- // This is a stricter version than the built in check for lists, thematic
17297
- // breaks, and setex heading underlines though:
17298
- // <https://github.com/syntax-tree/mdast-util-to-markdown/blob/51a2038/lib/unsafe.js#L57>
17299
- {atBreak: true, character: '-', after: '[:|-]'}
17300
- ],
17301
- handlers: {
17302
- inlineCode: inlineCodeWithTable,
17303
- table: handleTable,
17304
- tableCell: handleTableCell,
17305
- tableRow: handleTableRow
17306
- }
17307
- }
17308
-
17309
- /**
17310
- * @type {ToMarkdownHandle}
17311
- * @param {Table} node
17312
- */
17313
- function handleTable(node, _, state, info) {
17314
- return serializeData(handleTableAsData(node, state, info), node.align)
17315
- }
17316
-
17317
- /**
17318
- * This function isn’t really used normally, because we handle rows at the
17319
- * table level.
17320
- * But, if someone passes in a table row, this ensures we make somewhat sense.
17321
- *
17322
- * @type {ToMarkdownHandle}
17323
- * @param {TableRow} node
17324
- */
17325
- function handleTableRow(node, _, state, info) {
17326
- const row = handleTableRowAsData(node, state, info);
17327
- const value = serializeData([row]);
17328
- // `markdown-table` will always add an align row
17329
- return value.slice(0, value.indexOf('\n'))
17330
- }
17331
-
17332
- /**
17333
- * @type {ToMarkdownHandle}
17334
- * @param {TableCell} node
17335
- */
17336
- function handleTableCell(node, _, state, info) {
17337
- const exit = state.enter('tableCell');
17338
- const subexit = state.enter('phrasing');
17339
- const value = state.containerPhrasing(node, {
17340
- ...info,
17341
- before: around,
17342
- after: around
17343
- });
17344
- subexit();
17345
- exit();
17346
- return value
17347
- }
17348
-
17349
- /**
17350
- * @param {Array<Array<string>>} matrix
17351
- * @param {Array<string | null | undefined> | null | undefined} [align]
17352
- */
17353
- function serializeData(matrix, align) {
17354
- return markdownTable(matrix, {
17355
- align,
17356
- // @ts-expect-error: `markdown-table` types should support `null`.
17357
- alignDelimiters,
17358
- // @ts-expect-error: `markdown-table` types should support `null`.
17359
- padding,
17360
- // @ts-expect-error: `markdown-table` types should support `null`.
17361
- stringLength
17362
- })
17363
- }
17364
-
17365
- /**
17366
- * @param {Table} node
17367
- * @param {State} state
17368
- * @param {Info} info
17369
- */
17370
- function handleTableAsData(node, state, info) {
17371
- const children = node.children;
17372
- let index = -1;
17373
- /** @type {Array<Array<string>>} */
17374
- const result = [];
17375
- const subexit = state.enter('table');
17376
-
17377
- while (++index < children.length) {
17378
- result[index] = handleTableRowAsData(children[index], state, info);
17379
- }
17380
-
17381
- subexit();
17382
-
17383
- return result
17384
- }
17385
-
17386
- /**
17387
- * @param {TableRow} node
17388
- * @param {State} state
17389
- * @param {Info} info
17390
- */
17391
- function handleTableRowAsData(node, state, info) {
17392
- const children = node.children;
17393
- let index = -1;
17394
- /** @type {Array<string>} */
17395
- const result = [];
17396
- const subexit = state.enter('tableRow');
17397
-
17398
- while (++index < children.length) {
17399
- // Note: the positional info as used here is incorrect.
17400
- // Making it correct would be impossible due to aligning cells?
17401
- // And it would need copy/pasting `markdown-table` into this project.
17402
- result[index] = handleTableCell(children[index], node, state, info);
17403
- }
17404
-
17405
- subexit();
17406
-
17407
- return result
17408
- }
17409
-
17410
- /**
17411
- * @type {ToMarkdownHandle}
17412
- * @param {InlineCode} node
17413
- */
17414
- function inlineCodeWithTable(node, parent, state) {
17415
- let value = handle$1.inlineCode(node, parent, state);
17416
-
17417
- if (state.stack.includes('tableCell')) {
17418
- value = value.replace(/\|/g, '\\$&');
17419
- }
17420
-
17421
- return value
17422
- }
17423
- }
17424
-
17425
- /**
17426
- * @typedef {import('mdast').Blockquote} Blockquote
17427
- * @typedef {import('mdast').Parents} Parents
17428
- * @typedef {import('../types.js').Info} Info
17429
- * @typedef {import('../types.js').Map} Map
17430
- * @typedef {import('../types.js').State} State
17431
- */
17432
-
17433
- /**
17434
- * @param {Blockquote} node
17435
- * @param {Parents | undefined} _
17436
- * @param {State} state
17437
- * @param {Info} info
17438
- * @returns {string}
17439
- */
17440
- function blockquote(node, _, state, info) {
17441
- const exit = state.enter('blockquote');
17442
- const tracker = state.createTracker(info);
17443
- tracker.move('> ');
17444
- tracker.shift(2);
17445
- const value = state.indentLines(
17446
- state.containerFlow(node, tracker.current()),
17447
- map$1
17448
- );
17449
- exit();
17450
- return value
17451
- }
17452
-
17453
- /** @type {Map} */
17454
- function map$1(line, _, blank) {
17455
- return '>' + (blank ? '' : ' ') + line
17456
- }
17457
-
17458
- /**
17459
- * @typedef {import('../types.js').ConstructName} ConstructName
17460
- * @typedef {import('../types.js').Unsafe} Unsafe
17461
- */
17462
-
17463
- /**
17464
- * @param {Array<ConstructName>} stack
17465
- * @param {Unsafe} pattern
17466
- * @returns {boolean}
17467
- */
17468
- function patternInScope(stack, pattern) {
17469
- return (
17470
- listInScope(stack, pattern.inConstruct, true) &&
17471
- !listInScope(stack, pattern.notInConstruct, false)
17472
- )
17473
- }
17474
-
17475
- /**
17476
- * @param {Array<ConstructName>} stack
17477
- * @param {Unsafe['inConstruct']} list
17478
- * @param {boolean} none
17479
- * @returns {boolean}
17480
- */
17481
- function listInScope(stack, list, none) {
17482
- if (typeof list === 'string') {
17483
- list = [list];
17484
- }
17485
-
17486
- if (!list || list.length === 0) {
17487
- return none
17488
- }
17489
-
17490
- let index = -1;
17491
-
17492
- while (++index < list.length) {
17493
- if (stack.includes(list[index])) {
17494
- return true
17495
- }
17496
- }
17497
-
17498
- return false
17499
- }
17500
-
17501
- /**
17502
- * @typedef {import('mdast').Break} Break
17503
- * @typedef {import('mdast').Parents} Parents
17504
- * @typedef {import('../types.js').Info} Info
17505
- * @typedef {import('../types.js').State} State
17506
- */
17507
-
17508
-
17509
- /**
17510
- * @param {Break} _
17511
- * @param {Parents | undefined} _1
17512
- * @param {State} state
17513
- * @param {Info} info
17514
- * @returns {string}
17515
- */
17516
- function hardBreak(_, _1, state, info) {
17517
- let index = -1;
17518
-
17519
- while (++index < state.unsafe.length) {
17520
- // If we can’t put eols in this construct (setext headings, tables), use a
17521
- // space instead.
17522
- if (
17523
- state.unsafe[index].character === '\n' &&
17524
- patternInScope(state.stack, state.unsafe[index])
17525
- ) {
17526
- return /[ \t]/.test(info.before) ? '' : ' '
17527
- }
17528
- }
17529
-
17530
- return '\\\n'
17531
- }
17532
-
17533
- /**
17534
- * @typedef {import('mdast').Code} Code
17535
- * @typedef {import('../types.js').State} State
17536
- */
17537
-
17538
- /**
17539
- * @param {Code} node
17540
- * @param {State} state
17541
- * @returns {boolean}
17542
- */
17543
- function formatCodeAsIndented(node, state) {
17544
- return Boolean(
17545
- state.options.fences === false &&
17546
- node.value &&
17547
- // If there’s no info…
17548
- !node.lang &&
17549
- // And there’s a non-whitespace character…
17550
- /[^ \r\n]/.test(node.value) &&
17551
- // And the value doesn’t start or end in a blank…
17552
- !/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node.value)
17553
- )
17554
- }
17555
-
17556
- /**
17557
- * @typedef {import('../types.js').Options} Options
17558
- * @typedef {import('../types.js').State} State
17559
- */
17560
-
17561
- /**
17562
- * @param {State} state
17563
- * @returns {Exclude<Options['fence'], null | undefined>}
17564
- */
17565
- function checkFence(state) {
17566
- const marker = state.options.fence || '`';
17567
-
17568
- if (marker !== '`' && marker !== '~') {
17569
- throw new Error(
17570
- 'Cannot serialize code with `' +
17571
- marker +
17572
- '` for `options.fence`, expected `` ` `` or `~`'
17573
- )
17574
- }
17575
-
17576
- return marker
17577
- }
17578
-
17579
- /**
17580
- * @typedef {import('mdast').Code} Code
17581
- * @typedef {import('mdast').Parents} Parents
17582
- * @typedef {import('../types.js').Info} Info
17583
- * @typedef {import('../types.js').Map} Map
17584
- * @typedef {import('../types.js').State} State
17585
- */
17586
-
17587
-
17588
- /**
17589
- * @param {Code} node
17590
- * @param {Parents | undefined} _
17591
- * @param {State} state
17592
- * @param {Info} info
17593
- * @returns {string}
17594
- */
17595
- function code$1(node, _, state, info) {
17596
- const marker = checkFence(state);
17597
- const raw = node.value || '';
17598
- const suffix = marker === '`' ? 'GraveAccent' : 'Tilde';
17599
-
17600
- if (formatCodeAsIndented(node, state)) {
17601
- const exit = state.enter('codeIndented');
17602
- const value = state.indentLines(raw, map);
17603
- exit();
17604
- return value
17605
- }
17606
-
17607
- const tracker = state.createTracker(info);
17608
- const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3));
17609
- const exit = state.enter('codeFenced');
17610
- let value = tracker.move(sequence);
17611
-
17612
- if (node.lang) {
17613
- const subexit = state.enter(`codeFencedLang${suffix}`);
17614
- value += tracker.move(
17615
- state.safe(node.lang, {
17616
- before: value,
17617
- after: ' ',
17618
- encode: ['`'],
17619
- ...tracker.current()
17620
- })
17621
- );
17622
- subexit();
17623
- }
17624
-
17625
- if (node.lang && node.meta) {
17626
- const subexit = state.enter(`codeFencedMeta${suffix}`);
17627
- value += tracker.move(' ');
17628
- value += tracker.move(
17629
- state.safe(node.meta, {
17630
- before: value,
17631
- after: '\n',
17632
- encode: ['`'],
17633
- ...tracker.current()
17634
- })
17635
- );
17636
- subexit();
17637
- }
17638
-
17639
- value += tracker.move('\n');
17640
-
17641
- if (raw) {
17642
- value += tracker.move(raw + '\n');
17643
- }
17644
-
17645
- value += tracker.move(sequence);
17646
- exit();
17647
- return value
17648
- }
17649
-
17650
- /** @type {Map} */
17651
- function map(line, _, blank) {
17652
- return (blank ? '' : ' ') + line
17653
- }
17654
-
17655
- /**
17656
- * @typedef {import('../types.js').Options} Options
17657
- * @typedef {import('../types.js').State} State
17658
- */
17659
-
17660
- /**
17661
- * @param {State} state
17662
- * @returns {Exclude<Options['quote'], null | undefined>}
17663
- */
17664
- function checkQuote(state) {
17665
- const marker = state.options.quote || '"';
17666
-
17667
- if (marker !== '"' && marker !== "'") {
17668
- throw new Error(
17669
- 'Cannot serialize title with `' +
17670
- marker +
17671
- '` for `options.quote`, expected `"`, or `\'`'
17672
- )
17673
- }
17674
-
17675
- return marker
17676
- }
17677
-
17678
- /**
17679
- * @typedef {import('mdast').Definition} Definition
17680
- * @typedef {import('mdast').Parents} Parents
17681
- * @typedef {import('../types.js').Info} Info
17682
- * @typedef {import('../types.js').State} State
17683
- */
17684
-
17685
-
17686
- /**
17687
- * @param {Definition} node
17688
- * @param {Parents | undefined} _
17689
- * @param {State} state
17690
- * @param {Info} info
17691
- * @returns {string}
17692
- */
17693
- function definition(node, _, state, info) {
17694
- const quote = checkQuote(state);
17695
- const suffix = quote === '"' ? 'Quote' : 'Apostrophe';
17696
- const exit = state.enter('definition');
17697
- let subexit = state.enter('label');
17698
- const tracker = state.createTracker(info);
17699
- let value = tracker.move('[');
17700
- value += tracker.move(
17701
- state.safe(state.associationId(node), {
17702
- before: value,
17703
- after: ']',
17704
- ...tracker.current()
17705
- })
17706
- );
17707
- value += tracker.move(']: ');
17708
-
17709
- subexit();
17710
-
17711
- if (
17712
- // If there’s no url, or…
17713
- !node.url ||
17714
- // If there are control characters or whitespace.
17715
- /[\0- \u007F]/.test(node.url)
17716
- ) {
17717
- subexit = state.enter('destinationLiteral');
17718
- value += tracker.move('<');
17719
- value += tracker.move(
17720
- state.safe(node.url, {before: value, after: '>', ...tracker.current()})
17721
- );
17722
- value += tracker.move('>');
17723
- } else {
17724
- // No whitespace, raw is prettier.
17725
- subexit = state.enter('destinationRaw');
17726
- value += tracker.move(
17727
- state.safe(node.url, {
17728
- before: value,
17729
- after: node.title ? ' ' : '\n',
17730
- ...tracker.current()
17731
- })
17732
- );
17733
- }
17734
-
17735
- subexit();
17736
-
17737
- if (node.title) {
17738
- subexit = state.enter(`title${suffix}`);
17739
- value += tracker.move(' ' + quote);
17740
- value += tracker.move(
17741
- state.safe(node.title, {
17742
- before: value,
17743
- after: quote,
17744
- ...tracker.current()
17745
- })
17746
- );
17747
- value += tracker.move(quote);
17748
- subexit();
17749
- }
17750
-
17751
- exit();
17752
-
17753
- return value
17754
- }
17755
-
17756
- /**
17757
- * @typedef {import('../types.js').Options} Options
17758
- * @typedef {import('../types.js').State} State
17759
- */
17760
-
17761
- /**
17762
- * @param {State} state
17763
- * @returns {Exclude<Options['emphasis'], null | undefined>}
17764
- */
17765
- function checkEmphasis(state) {
17766
- const marker = state.options.emphasis || '*';
17767
-
17768
- if (marker !== '*' && marker !== '_') {
17769
- throw new Error(
17770
- 'Cannot serialize emphasis with `' +
17771
- marker +
17772
- '` for `options.emphasis`, expected `*`, or `_`'
17773
- )
17774
- }
17775
-
17776
- return marker
17777
- }
17778
-
17779
- /**
17780
- * @typedef {import('mdast').Emphasis} Emphasis
17781
- * @typedef {import('mdast').Parents} Parents
17782
- * @typedef {import('../types.js').Info} Info
17783
- * @typedef {import('../types.js').State} State
17784
- */
17785
-
17786
-
17787
- emphasis.peek = emphasisPeek;
17788
-
17789
- // To do: there are cases where emphasis cannot “form” depending on the
17790
- // previous or next character of sequences.
17791
- // There’s no way around that though, except for injecting zero-width stuff.
17792
- // Do we need to safeguard against that?
17793
- /**
17794
- * @param {Emphasis} node
17795
- * @param {Parents | undefined} _
17796
- * @param {State} state
17797
- * @param {Info} info
17798
- * @returns {string}
17799
- */
17800
- function emphasis(node, _, state, info) {
17801
- const marker = checkEmphasis(state);
17802
- const exit = state.enter('emphasis');
17803
- const tracker = state.createTracker(info);
17804
- let value = tracker.move(marker);
17805
- value += tracker.move(
17806
- state.containerPhrasing(node, {
17807
- before: value,
17808
- after: marker,
17809
- ...tracker.current()
17810
- })
17811
- );
17812
- value += tracker.move(marker);
17813
- exit();
17814
- return value
17815
- }
17816
-
17817
- /**
17818
- * @param {Emphasis} _
17819
- * @param {Parents | undefined} _1
17820
- * @param {State} state
17821
- * @returns {string}
17822
- */
17823
- function emphasisPeek(_, _1, state) {
17824
- return state.options.emphasis || '*'
17825
- }
17826
-
17827
- /**
17828
- * @typedef {import('mdast').Nodes} Nodes
17829
- *
17830
- * @typedef Options
17831
- * Configuration (optional).
17832
- * @property {boolean | null | undefined} [includeImageAlt=true]
17833
- * Whether to use `alt` for `image`s (default: `true`).
17834
- * @property {boolean | null | undefined} [includeHtml=true]
17835
- * Whether to use `value` of HTML (default: `true`).
17836
- */
17837
-
17838
- /** @type {Options} */
17839
- const emptyOptions$2 = {};
17840
-
17841
- /**
17842
- * Get the text content of a node or list of nodes.
17843
- *
17844
- * Prefers the node’s plain-text fields, otherwise serializes its children,
17845
- * and if the given value is an array, serialize the nodes in it.
17846
- *
17847
- * @param {unknown} [value]
17848
- * Thing to serialize, typically `Node`.
17849
- * @param {Options | null | undefined} [options]
17850
- * Configuration (optional).
17851
- * @returns {string}
17852
- * Serialized `value`.
17853
- */
17854
- function toString(value, options) {
17855
- const settings = emptyOptions$2;
17856
- const includeImageAlt =
17857
- typeof settings.includeImageAlt === 'boolean'
17858
- ? settings.includeImageAlt
17859
- : true;
17860
- const includeHtml =
17861
- typeof settings.includeHtml === 'boolean' ? settings.includeHtml : true;
17862
-
17863
- return one$2(value, includeImageAlt, includeHtml)
17864
- }
17865
-
17866
- /**
17867
- * One node or several nodes.
17868
- *
17869
- * @param {unknown} value
17870
- * Thing to serialize.
17871
- * @param {boolean} includeImageAlt
17872
- * Include image `alt`s.
17873
- * @param {boolean} includeHtml
17874
- * Include HTML.
17875
- * @returns {string}
17876
- * Serialized node.
17877
- */
17878
- function one$2(value, includeImageAlt, includeHtml) {
17879
- if (node(value)) {
17880
- if ('value' in value) {
17881
- return value.type === 'html' && !includeHtml ? '' : value.value
17882
- }
17883
-
17884
- if (includeImageAlt && 'alt' in value && value.alt) {
17885
- return value.alt
17886
- }
17887
-
17888
- if ('children' in value) {
17889
- return all$3(value.children, includeImageAlt, includeHtml)
17890
- }
17891
- }
17892
-
17893
- if (Array.isArray(value)) {
17894
- return all$3(value, includeImageAlt, includeHtml)
17895
- }
17896
-
17897
- return ''
17898
- }
17899
-
17900
- /**
17901
- * Serialize a list of nodes.
17902
- *
17903
- * @param {Array<unknown>} values
17904
- * Thing to serialize.
17905
- * @param {boolean} includeImageAlt
17906
- * Include image `alt`s.
17907
- * @param {boolean} includeHtml
17908
- * Include HTML.
17909
- * @returns {string}
17910
- * Serialized nodes.
17911
- */
17912
- function all$3(values, includeImageAlt, includeHtml) {
17913
- /** @type {Array<string>} */
17914
- const result = [];
17915
- let index = -1;
17916
-
17917
- while (++index < values.length) {
17918
- result[index] = one$2(values[index], includeImageAlt, includeHtml);
17919
- }
17920
-
17921
- return result.join('')
17922
- }
17923
-
17924
- /**
17925
- * Check if `value` looks like a node.
17926
- *
17927
- * @param {unknown} value
17928
- * Thing.
17929
- * @returns {value is Nodes}
17930
- * Whether `value` is a node.
17931
- */
17932
- function node(value) {
17933
- return Boolean(value && typeof value === 'object')
17934
- }
17935
-
17936
- /**
17937
- * @typedef {import('mdast').Heading} Heading
17938
- * @typedef {import('../types.js').State} State
17939
- */
17940
-
17941
-
17942
- /**
17943
- * @param {Heading} node
17944
- * @param {State} state
17945
- * @returns {boolean}
17946
- */
17947
- function formatHeadingAsSetext(node, state) {
17948
- let literalWithBreak = false;
17949
-
17950
- // Look for literals with a line break.
17951
- // Note that this also
17952
- visit(node, function (node) {
17953
- if (
17954
- ('value' in node && /\r?\n|\r/.test(node.value)) ||
17955
- node.type === 'break'
17956
- ) {
17957
- literalWithBreak = true;
17958
- return EXIT
17959
- }
17960
- });
17961
-
17962
- return Boolean(
17963
- (!node.depth || node.depth < 3) &&
17964
- toString(node) &&
17965
- (state.options.setext || literalWithBreak)
17966
- )
17967
- }
17968
-
17969
- /**
17970
- * @typedef {import('mdast').Heading} Heading
17971
- * @typedef {import('mdast').Parents} Parents
17972
- * @typedef {import('../types.js').Info} Info
17973
- * @typedef {import('../types.js').State} State
17974
- */
17975
-
17976
-
17977
- /**
17978
- * @param {Heading} node
17979
- * @param {Parents | undefined} _
17980
- * @param {State} state
17981
- * @param {Info} info
17982
- * @returns {string}
17983
- */
17984
- function heading(node, _, state, info) {
17985
- const rank = Math.max(Math.min(6, node.depth || 1), 1);
17986
- const tracker = state.createTracker(info);
17987
-
17988
- if (formatHeadingAsSetext(node, state)) {
17989
- const exit = state.enter('headingSetext');
17990
- const subexit = state.enter('phrasing');
17991
- const value = state.containerPhrasing(node, {
17992
- ...tracker.current(),
17993
- before: '\n',
17994
- after: '\n'
17995
- });
17996
- subexit();
17997
- exit();
17998
-
17999
- return (
18000
- value +
18001
- '\n' +
18002
- (rank === 1 ? '=' : '-').repeat(
18003
- // The whole size…
18004
- value.length -
18005
- // Minus the position of the character after the last EOL (or
18006
- // 0 if there is none)…
18007
- (Math.max(value.lastIndexOf('\r'), value.lastIndexOf('\n')) + 1)
18008
- )
18009
- )
18010
- }
18011
-
18012
- const sequence = '#'.repeat(rank);
18013
- const exit = state.enter('headingAtx');
18014
- const subexit = state.enter('phrasing');
18015
-
18016
- // Note: for proper tracking, we should reset the output positions when there
18017
- // is no content returned, because then the space is not output.
18018
- // Practically, in that case, there is no content, so it doesn’t matter that
18019
- // we’ve tracked one too many characters.
18020
- tracker.move(sequence + ' ');
18021
-
18022
- let value = state.containerPhrasing(node, {
18023
- before: '# ',
18024
- after: '\n',
18025
- ...tracker.current()
18026
- });
18027
-
18028
- if (/^[\t ]/.test(value)) {
18029
- // To do: what effect has the character reference on tracking?
18030
- value =
18031
- '&#x' +
18032
- value.charCodeAt(0).toString(16).toUpperCase() +
18033
- ';' +
18034
- value.slice(1);
16079
+ value = encodeCharacterReference(value.charCodeAt(0)) + value.slice(1);
18035
16080
  }
18036
16081
 
18037
16082
  value = value ? sequence + ' ' + value : sequence;
@@ -18047,7 +16092,7 @@ function heading(node, _, state, info) {
18047
16092
  }
18048
16093
 
18049
16094
  /**
18050
- * @typedef {import('mdast').Html} Html
16095
+ * @import {Html} from 'mdast'
18051
16096
  */
18052
16097
 
18053
16098
  html$4.peek = htmlPeek;
@@ -18068,10 +16113,8 @@ function htmlPeek() {
18068
16113
  }
18069
16114
 
18070
16115
  /**
18071
- * @typedef {import('mdast').Image} Image
18072
- * @typedef {import('mdast').Parents} Parents
18073
- * @typedef {import('../types.js').Info} Info
18074
- * @typedef {import('../types.js').State} State
16116
+ * @import {Info, State} from 'mdast-util-to-markdown'
16117
+ * @import {Image, Parents} from 'mdast'
18075
16118
  */
18076
16119
 
18077
16120
 
@@ -18152,10 +16195,8 @@ function imagePeek() {
18152
16195
  }
18153
16196
 
18154
16197
  /**
18155
- * @typedef {import('mdast').ImageReference} ImageReference
18156
- * @typedef {import('mdast').Parents} Parents
18157
- * @typedef {import('../types.js').Info} Info
18158
- * @typedef {import('../types.js').State} State
16198
+ * @import {Info, State} from 'mdast-util-to-markdown'
16199
+ * @import {ImageReference, Parents} from 'mdast'
18159
16200
  */
18160
16201
 
18161
16202
  imageReference.peek = imageReferencePeek;
@@ -18218,9 +16259,8 @@ function imageReferencePeek() {
18218
16259
  }
18219
16260
 
18220
16261
  /**
18221
- * @typedef {import('mdast').InlineCode} InlineCode
18222
- * @typedef {import('mdast').Parents} Parents
18223
- * @typedef {import('../types.js').State} State
16262
+ * @import {State} from 'mdast-util-to-markdown'
16263
+ * @import {InlineCode, Parents} from 'mdast'
18224
16264
  */
18225
16265
 
18226
16266
  inlineCode.peek = inlineCodePeek;
@@ -18296,8 +16336,8 @@ function inlineCodePeek() {
18296
16336
  }
18297
16337
 
18298
16338
  /**
18299
- * @typedef {import('mdast').Link} Link
18300
- * @typedef {import('../types.js').State} State
16339
+ * @import {State} from 'mdast-util-to-markdown'
16340
+ * @import {Link} from 'mdast'
18301
16341
  */
18302
16342
 
18303
16343
 
@@ -18330,11 +16370,9 @@ function formatLinkAsAutolink(node, state) {
18330
16370
  }
18331
16371
 
18332
16372
  /**
18333
- * @typedef {import('mdast').Link} Link
18334
- * @typedef {import('mdast').Parents} Parents
18335
- * @typedef {import('../types.js').Exit} Exit
18336
- * @typedef {import('../types.js').Info} Info
18337
- * @typedef {import('../types.js').State} State
16373
+ * @import {Info, State} from 'mdast-util-to-markdown'
16374
+ * @import {Link, Parents} from 'mdast'
16375
+ * @import {Exit} from '../types.js'
18338
16376
  */
18339
16377
 
18340
16378
 
@@ -18445,10 +16483,8 @@ function linkPeek(node, _, state) {
18445
16483
  }
18446
16484
 
18447
16485
  /**
18448
- * @typedef {import('mdast').LinkReference} LinkReference
18449
- * @typedef {import('mdast').Parents} Parents
18450
- * @typedef {import('../types.js').Info} Info
18451
- * @typedef {import('../types.js').State} State
16486
+ * @import {Info, State} from 'mdast-util-to-markdown'
16487
+ * @import {LinkReference, Parents} from 'mdast'
18452
16488
  */
18453
16489
 
18454
16490
  linkReference.peek = linkReferencePeek;
@@ -18511,8 +16547,7 @@ function linkReferencePeek() {
18511
16547
  }
18512
16548
 
18513
16549
  /**
18514
- * @typedef {import('../types.js').Options} Options
18515
- * @typedef {import('../types.js').State} State
16550
+ * @import {Options, State} from 'mdast-util-to-markdown'
18516
16551
  */
18517
16552
 
18518
16553
  /**
@@ -18534,8 +16569,7 @@ function checkBullet(state) {
18534
16569
  }
18535
16570
 
18536
16571
  /**
18537
- * @typedef {import('../types.js').Options} Options
18538
- * @typedef {import('../types.js').State} State
16572
+ * @import {Options, State} from 'mdast-util-to-markdown'
18539
16573
  */
18540
16574
 
18541
16575
 
@@ -18573,8 +16607,7 @@ function checkBulletOther(state) {
18573
16607
  }
18574
16608
 
18575
16609
  /**
18576
- * @typedef {import('../types.js').Options} Options
18577
- * @typedef {import('../types.js').State} State
16610
+ * @import {Options, State} from 'mdast-util-to-markdown'
18578
16611
  */
18579
16612
 
18580
16613
  /**
@@ -18596,8 +16629,7 @@ function checkBulletOrdered(state) {
18596
16629
  }
18597
16630
 
18598
16631
  /**
18599
- * @typedef {import('../types.js').Options} Options
18600
- * @typedef {import('../types.js').State} State
16632
+ * @import {Options, State} from 'mdast-util-to-markdown'
18601
16633
  */
18602
16634
 
18603
16635
  /**
@@ -18619,10 +16651,8 @@ function checkRule(state) {
18619
16651
  }
18620
16652
 
18621
16653
  /**
18622
- * @typedef {import('mdast').List} List
18623
- * @typedef {import('mdast').Parents} Parents
18624
- * @typedef {import('../types.js').Info} Info
18625
- * @typedef {import('../types.js').State} State
16654
+ * @import {Info, State} from 'mdast-util-to-markdown'
16655
+ * @import {List, Parents} from 'mdast'
18626
16656
  */
18627
16657
 
18628
16658
 
@@ -18718,8 +16748,7 @@ function list(node, parent, state, info) {
18718
16748
  }
18719
16749
 
18720
16750
  /**
18721
- * @typedef {import('../types.js').Options} Options
18722
- * @typedef {import('../types.js').State} State
16751
+ * @import {Options, State} from 'mdast-util-to-markdown'
18723
16752
  */
18724
16753
 
18725
16754
  /**
@@ -18741,11 +16770,8 @@ function checkListItemIndent(state) {
18741
16770
  }
18742
16771
 
18743
16772
  /**
18744
- * @typedef {import('mdast').ListItem} ListItem
18745
- * @typedef {import('mdast').Parents} Parents
18746
- * @typedef {import('../types.js').Info} Info
18747
- * @typedef {import('../types.js').Map} Map
18748
- * @typedef {import('../types.js').State} State
16773
+ * @import {Info, Map, State} from 'mdast-util-to-markdown'
16774
+ * @import {ListItem, Parents} from 'mdast'
18749
16775
  */
18750
16776
 
18751
16777
 
@@ -18805,10 +16831,8 @@ function listItem(node, parent, state, info) {
18805
16831
  }
18806
16832
 
18807
16833
  /**
18808
- * @typedef {import('mdast').Paragraph} Paragraph
18809
- * @typedef {import('mdast').Parents} Parents
18810
- * @typedef {import('../types.js').Info} Info
18811
- * @typedef {import('../types.js').State} State
16834
+ * @import {Info, State} from 'mdast-util-to-markdown'
16835
+ * @import {Paragraph, Parents} from 'mdast'
18812
16836
  */
18813
16837
 
18814
16838
  /**
@@ -18828,10 +16852,43 @@ function paragraph(node, _, state, info) {
18828
16852
  }
18829
16853
 
18830
16854
  /**
18831
- * @typedef {import('mdast').Parents} Parents
18832
- * @typedef {import('mdast').Root} Root
18833
- * @typedef {import('../types.js').Info} Info
18834
- * @typedef {import('../types.js').State} State
16855
+ * @typedef {import('mdast').PhrasingContent} PhrasingContent
16856
+ */
16857
+
16858
+
16859
+ /**
16860
+ * Check if the given value is *phrasing content*.
16861
+ *
16862
+ * > 👉 **Note**: Excludes `html`, which can be both phrasing or flow.
16863
+ *
16864
+ * @param node
16865
+ * Thing to check, typically `Node`.
16866
+ * @returns
16867
+ * Whether `value` is phrasing content.
16868
+ */
16869
+
16870
+ const phrasing =
16871
+ /** @type {(node?: unknown) => node is PhrasingContent} */
16872
+ (
16873
+ convert([
16874
+ 'break',
16875
+ 'delete',
16876
+ 'emphasis',
16877
+ 'footnote',
16878
+ 'footnoteReference',
16879
+ 'image',
16880
+ 'imageReference',
16881
+ 'inlineCode',
16882
+ 'link',
16883
+ 'linkReference',
16884
+ 'strong',
16885
+ 'text'
16886
+ ])
16887
+ );
16888
+
16889
+ /**
16890
+ * @import {Info, State} from 'mdast-util-to-markdown'
16891
+ * @import {Parents, Root} from 'mdast'
18835
16892
  */
18836
16893
 
18837
16894
 
@@ -18847,13 +16904,13 @@ function root$2(node, _, state, info) {
18847
16904
  const hasPhrasing = node.children.some(function (d) {
18848
16905
  return phrasing(d)
18849
16906
  });
18850
- const fn = hasPhrasing ? state.containerPhrasing : state.containerFlow;
18851
- return fn.call(state, node, info)
16907
+
16908
+ const container = hasPhrasing ? state.containerPhrasing : state.containerFlow;
16909
+ return container.call(state, node, info)
18852
16910
  }
18853
16911
 
18854
16912
  /**
18855
- * @typedef {import('../types.js').Options} Options
18856
- * @typedef {import('../types.js').State} State
16913
+ * @import {Options, State} from 'mdast-util-to-markdown'
18857
16914
  */
18858
16915
 
18859
16916
  /**
@@ -18875,19 +16932,13 @@ function checkStrong(state) {
18875
16932
  }
18876
16933
 
18877
16934
  /**
18878
- * @typedef {import('mdast').Parents} Parents
18879
- * @typedef {import('mdast').Strong} Strong
18880
- * @typedef {import('../types.js').Info} Info
18881
- * @typedef {import('../types.js').State} State
16935
+ * @import {Info, State} from 'mdast-util-to-markdown'
16936
+ * @import {Parents, Strong} from 'mdast'
18882
16937
  */
18883
16938
 
18884
16939
 
18885
16940
  strong.peek = strongPeek;
18886
16941
 
18887
- // To do: there are cases where emphasis cannot “form” depending on the
18888
- // previous or next character of sequences.
18889
- // There’s no way around that though, except for injecting zero-width stuff.
18890
- // Do we need to safeguard against that?
18891
16942
  /**
18892
16943
  * @param {Strong} node
18893
16944
  * @param {Parents | undefined} _
@@ -18899,17 +16950,42 @@ function strong(node, _, state, info) {
18899
16950
  const marker = checkStrong(state);
18900
16951
  const exit = state.enter('strong');
18901
16952
  const tracker = state.createTracker(info);
18902
- let value = tracker.move(marker + marker);
18903
- value += tracker.move(
16953
+ const before = tracker.move(marker + marker);
16954
+
16955
+ let between = tracker.move(
18904
16956
  state.containerPhrasing(node, {
18905
- before: value,
18906
16957
  after: marker,
16958
+ before,
18907
16959
  ...tracker.current()
18908
16960
  })
18909
16961
  );
18910
- value += tracker.move(marker + marker);
16962
+ const betweenHead = between.charCodeAt(0);
16963
+ const open = encodeInfo(
16964
+ info.before.charCodeAt(info.before.length - 1),
16965
+ betweenHead,
16966
+ marker
16967
+ );
16968
+
16969
+ if (open.inside) {
16970
+ between = encodeCharacterReference(betweenHead) + between.slice(1);
16971
+ }
16972
+
16973
+ const betweenTail = between.charCodeAt(between.length - 1);
16974
+ const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
16975
+
16976
+ if (close.inside) {
16977
+ between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
16978
+ }
16979
+
16980
+ const after = tracker.move(marker + marker);
16981
+
18911
16982
  exit();
18912
- return value
16983
+
16984
+ state.attentionEncodeSurroundingInfo = {
16985
+ after: close.outside,
16986
+ before: open.outside
16987
+ };
16988
+ return before + between + after
18913
16989
  }
18914
16990
 
18915
16991
  /**
@@ -18923,10 +16999,8 @@ function strongPeek(_, _1, state) {
18923
16999
  }
18924
17000
 
18925
17001
  /**
18926
- * @typedef {import('mdast').Parents} Parents
18927
- * @typedef {import('mdast').Text} Text
18928
- * @typedef {import('../types.js').Info} Info
18929
- * @typedef {import('../types.js').State} State
17002
+ * @import {Info, State} from 'mdast-util-to-markdown'
17003
+ * @import {Parents, Text} from 'mdast'
18930
17004
  */
18931
17005
 
18932
17006
  /**
@@ -18941,8 +17015,7 @@ function text$3(node, _, state, info) {
18941
17015
  }
18942
17016
 
18943
17017
  /**
18944
- * @typedef {import('../types.js').Options} Options
18945
- * @typedef {import('../types.js').State} State
17018
+ * @import {Options, State} from 'mdast-util-to-markdown'
18946
17019
  */
18947
17020
 
18948
17021
  /**
@@ -18964,9 +17037,8 @@ function checkRuleRepetition(state) {
18964
17037
  }
18965
17038
 
18966
17039
  /**
18967
- * @typedef {import('mdast').Parents} Parents
18968
- * @typedef {import('mdast').ThematicBreak} ThematicBreak
18969
- * @typedef {import('../types.js').State} State
17040
+ * @import {State} from 'mdast-util-to-markdown'
17041
+ * @import {Parents, ThematicBreak} from 'mdast'
18970
17042
  */
18971
17043
 
18972
17044
 
@@ -19010,6 +17082,289 @@ const handle = {
19010
17082
  thematicBreak
19011
17083
  };
19012
17084
 
17085
+ /**
17086
+ * @typedef {import('mdast').InlineCode} InlineCode
17087
+ * @typedef {import('mdast').Table} Table
17088
+ * @typedef {import('mdast').TableCell} TableCell
17089
+ * @typedef {import('mdast').TableRow} TableRow
17090
+ *
17091
+ * @typedef {import('markdown-table').Options} MarkdownTableOptions
17092
+ *
17093
+ * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
17094
+ * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
17095
+ * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
17096
+ *
17097
+ * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
17098
+ * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
17099
+ * @typedef {import('mdast-util-to-markdown').State} State
17100
+ * @typedef {import('mdast-util-to-markdown').Info} Info
17101
+ */
17102
+
17103
+
17104
+ /**
17105
+ * Create an extension for `mdast-util-from-markdown` to enable GFM tables in
17106
+ * markdown.
17107
+ *
17108
+ * @returns {FromMarkdownExtension}
17109
+ * Extension for `mdast-util-from-markdown` to enable GFM tables.
17110
+ */
17111
+ function gfmTableFromMarkdown() {
17112
+ return {
17113
+ enter: {
17114
+ table: enterTable,
17115
+ tableData: enterCell,
17116
+ tableHeader: enterCell,
17117
+ tableRow: enterRow
17118
+ },
17119
+ exit: {
17120
+ codeText: exitCodeText,
17121
+ table: exitTable,
17122
+ tableData: exit,
17123
+ tableHeader: exit,
17124
+ tableRow: exit
17125
+ }
17126
+ }
17127
+ }
17128
+
17129
+ /**
17130
+ * @this {CompileContext}
17131
+ * @type {FromMarkdownHandle}
17132
+ */
17133
+ function enterTable(token) {
17134
+ const align = token._align;
17135
+ this.enter(
17136
+ {
17137
+ type: 'table',
17138
+ align: align.map(function (d) {
17139
+ return d === 'none' ? null : d
17140
+ }),
17141
+ children: []
17142
+ },
17143
+ token
17144
+ );
17145
+ this.data.inTable = true;
17146
+ }
17147
+
17148
+ /**
17149
+ * @this {CompileContext}
17150
+ * @type {FromMarkdownHandle}
17151
+ */
17152
+ function exitTable(token) {
17153
+ this.exit(token);
17154
+ this.data.inTable = undefined;
17155
+ }
17156
+
17157
+ /**
17158
+ * @this {CompileContext}
17159
+ * @type {FromMarkdownHandle}
17160
+ */
17161
+ function enterRow(token) {
17162
+ this.enter({type: 'tableRow', children: []}, token);
17163
+ }
17164
+
17165
+ /**
17166
+ * @this {CompileContext}
17167
+ * @type {FromMarkdownHandle}
17168
+ */
17169
+ function exit(token) {
17170
+ this.exit(token);
17171
+ }
17172
+
17173
+ /**
17174
+ * @this {CompileContext}
17175
+ * @type {FromMarkdownHandle}
17176
+ */
17177
+ function enterCell(token) {
17178
+ this.enter({type: 'tableCell', children: []}, token);
17179
+ }
17180
+
17181
+ // Overwrite the default code text data handler to unescape escaped pipes when
17182
+ // they are in tables.
17183
+ /**
17184
+ * @this {CompileContext}
17185
+ * @type {FromMarkdownHandle}
17186
+ */
17187
+ function exitCodeText(token) {
17188
+ let value = this.resume();
17189
+
17190
+ if (this.data.inTable) {
17191
+ value = value.replace(/\\([\\|])/g, replace);
17192
+ }
17193
+
17194
+ const node = this.stack[this.stack.length - 1];
17195
+ node.value = value;
17196
+ this.exit(token);
17197
+ }
17198
+
17199
+ /**
17200
+ * @param {string} $0
17201
+ * @param {string} $1
17202
+ * @returns {string}
17203
+ */
17204
+ function replace($0, $1) {
17205
+ // Pipes work, backslashes don’t (but can’t escape pipes).
17206
+ return $1 === '|' ? $1 : $0
17207
+ }
17208
+
17209
+ /**
17210
+ * Create an extension for `mdast-util-to-markdown` to enable GFM tables in
17211
+ * markdown.
17212
+ *
17213
+ * @param {Options | null | undefined} [options]
17214
+ * Configuration.
17215
+ * @returns {ToMarkdownExtension}
17216
+ * Extension for `mdast-util-to-markdown` to enable GFM tables.
17217
+ */
17218
+ function gfmTableToMarkdown(options) {
17219
+ const settings = options || {};
17220
+ const padding = settings.tableCellPadding;
17221
+ const alignDelimiters = settings.tablePipeAlign;
17222
+ const stringLength = settings.stringLength;
17223
+ const around = padding ? ' ' : '|';
17224
+
17225
+ return {
17226
+ unsafe: [
17227
+ {character: '\r', inConstruct: 'tableCell'},
17228
+ {character: '\n', inConstruct: 'tableCell'},
17229
+ // A pipe, when followed by a tab or space (padding), or a dash or colon
17230
+ // (unpadded delimiter row), could result in a table.
17231
+ {atBreak: true, character: '|', after: '[\t :-]'},
17232
+ // A pipe in a cell must be encoded.
17233
+ {character: '|', inConstruct: 'tableCell'},
17234
+ // A colon must be followed by a dash, in which case it could start a
17235
+ // delimiter row.
17236
+ {atBreak: true, character: ':', after: '-'},
17237
+ // A delimiter row can also start with a dash, when followed by more
17238
+ // dashes, a colon, or a pipe.
17239
+ // This is a stricter version than the built in check for lists, thematic
17240
+ // breaks, and setex heading underlines though:
17241
+ // <https://github.com/syntax-tree/mdast-util-to-markdown/blob/51a2038/lib/unsafe.js#L57>
17242
+ {atBreak: true, character: '-', after: '[:|-]'}
17243
+ ],
17244
+ handlers: {
17245
+ inlineCode: inlineCodeWithTable,
17246
+ table: handleTable,
17247
+ tableCell: handleTableCell,
17248
+ tableRow: handleTableRow
17249
+ }
17250
+ }
17251
+
17252
+ /**
17253
+ * @type {ToMarkdownHandle}
17254
+ * @param {Table} node
17255
+ */
17256
+ function handleTable(node, _, state, info) {
17257
+ return serializeData(handleTableAsData(node, state, info), node.align)
17258
+ }
17259
+
17260
+ /**
17261
+ * This function isn’t really used normally, because we handle rows at the
17262
+ * table level.
17263
+ * But, if someone passes in a table row, this ensures we make somewhat sense.
17264
+ *
17265
+ * @type {ToMarkdownHandle}
17266
+ * @param {TableRow} node
17267
+ */
17268
+ function handleTableRow(node, _, state, info) {
17269
+ const row = handleTableRowAsData(node, state, info);
17270
+ const value = serializeData([row]);
17271
+ // `markdown-table` will always add an align row
17272
+ return value.slice(0, value.indexOf('\n'))
17273
+ }
17274
+
17275
+ /**
17276
+ * @type {ToMarkdownHandle}
17277
+ * @param {TableCell} node
17278
+ */
17279
+ function handleTableCell(node, _, state, info) {
17280
+ const exit = state.enter('tableCell');
17281
+ const subexit = state.enter('phrasing');
17282
+ const value = state.containerPhrasing(node, {
17283
+ ...info,
17284
+ before: around,
17285
+ after: around
17286
+ });
17287
+ subexit();
17288
+ exit();
17289
+ return value
17290
+ }
17291
+
17292
+ /**
17293
+ * @param {Array<Array<string>>} matrix
17294
+ * @param {Array<string | null | undefined> | null | undefined} [align]
17295
+ */
17296
+ function serializeData(matrix, align) {
17297
+ return markdownTable(matrix, {
17298
+ align,
17299
+ // @ts-expect-error: `markdown-table` types should support `null`.
17300
+ alignDelimiters,
17301
+ // @ts-expect-error: `markdown-table` types should support `null`.
17302
+ padding,
17303
+ // @ts-expect-error: `markdown-table` types should support `null`.
17304
+ stringLength
17305
+ })
17306
+ }
17307
+
17308
+ /**
17309
+ * @param {Table} node
17310
+ * @param {State} state
17311
+ * @param {Info} info
17312
+ */
17313
+ function handleTableAsData(node, state, info) {
17314
+ const children = node.children;
17315
+ let index = -1;
17316
+ /** @type {Array<Array<string>>} */
17317
+ const result = [];
17318
+ const subexit = state.enter('table');
17319
+
17320
+ while (++index < children.length) {
17321
+ result[index] = handleTableRowAsData(children[index], state, info);
17322
+ }
17323
+
17324
+ subexit();
17325
+
17326
+ return result
17327
+ }
17328
+
17329
+ /**
17330
+ * @param {TableRow} node
17331
+ * @param {State} state
17332
+ * @param {Info} info
17333
+ */
17334
+ function handleTableRowAsData(node, state, info) {
17335
+ const children = node.children;
17336
+ let index = -1;
17337
+ /** @type {Array<string>} */
17338
+ const result = [];
17339
+ const subexit = state.enter('tableRow');
17340
+
17341
+ while (++index < children.length) {
17342
+ // Note: the positional info as used here is incorrect.
17343
+ // Making it correct would be impossible due to aligning cells?
17344
+ // And it would need copy/pasting `markdown-table` into this project.
17345
+ result[index] = handleTableCell(children[index], node, state, info);
17346
+ }
17347
+
17348
+ subexit();
17349
+
17350
+ return result
17351
+ }
17352
+
17353
+ /**
17354
+ * @type {ToMarkdownHandle}
17355
+ * @param {InlineCode} node
17356
+ */
17357
+ function inlineCodeWithTable(node, parent, state) {
17358
+ let value = handle.inlineCode(node, parent, state);
17359
+
17360
+ if (state.stack.includes('tableCell')) {
17361
+ value = value.replace(/\|/g, '\\$&');
17362
+ }
17363
+
17364
+ return value
17365
+ }
17366
+ }
17367
+
19013
17368
  /**
19014
17369
  * @typedef {import('mdast').ListItem} ListItem
19015
17370
  * @typedef {import('mdast').Paragraph} Paragraph
@@ -22379,7 +20734,7 @@ function mark$1(values, key, value) {
22379
20734
  */
22380
20735
 
22381
20736
 
22382
- const own$6 = {}.hasOwnProperty;
20737
+ const own$4 = {}.hasOwnProperty;
22383
20738
 
22384
20739
  /**
22385
20740
  * @param {Definition} definition
@@ -22394,7 +20749,7 @@ function create$1(definition) {
22394
20749
  let prop;
22395
20750
 
22396
20751
  for (prop in definition.properties) {
22397
- if (own$6.call(definition.properties, prop)) {
20752
+ if (own$4.call(definition.properties, prop)) {
22398
20753
  const value = definition.properties[prop];
22399
20754
  const info = new DefinedInfo$1(
22400
20755
  prop,
@@ -23629,7 +21984,7 @@ function parse$1(value) {
23629
21984
 
23630
21985
  const buttonTypes = new Set(['button', 'menu', 'reset', 'submit']);
23631
21986
 
23632
- const own$5 = {}.hasOwnProperty;
21987
+ const own$3 = {}.hasOwnProperty;
23633
21988
 
23634
21989
  /**
23635
21990
  * @param {Schema} schema
@@ -23686,7 +22041,7 @@ function createH(schema, defaultTagName, caseSensitive) {
23686
22041
  node = parseSelector(selector, defaultTagName);
23687
22042
  // Normalize the name.
23688
22043
  node.tagName = node.tagName.toLowerCase();
23689
- if (adjust && own$5.call(adjust, node.tagName)) {
22044
+ if (adjust && own$3.call(adjust, node.tagName)) {
23690
22045
  node.tagName = adjust[node.tagName];
23691
22046
  }
23692
22047
 
@@ -23696,7 +22051,7 @@ function createH(schema, defaultTagName, caseSensitive) {
23696
22051
  let key;
23697
22052
 
23698
22053
  for (key in properties) {
23699
- if (own$5.call(properties, key)) {
22054
+ if (own$3.call(properties, key)) {
23700
22055
  addProperty(schema, node.properties, key, properties[key]);
23701
22056
  }
23702
22057
  }
@@ -23901,7 +22256,7 @@ function style(value) {
23901
22256
  let key;
23902
22257
 
23903
22258
  for (key in value) {
23904
- if (own$5.call(value, key)) {
22259
+ if (own$3.call(value, key)) {
23905
22260
  result.push([key, value[key]].join(': '));
23906
22261
  }
23907
22262
  }
@@ -24140,7 +22495,7 @@ const webNamespaces$1 = {
24140
22495
  */
24141
22496
 
24142
22497
 
24143
- const own$4 = {}.hasOwnProperty;
22498
+ const own$2 = {}.hasOwnProperty;
24144
22499
  /** @type {unknown} */
24145
22500
  // type-coverage:ignore-next-line
24146
22501
  const proto = Object.prototype;
@@ -24287,7 +22642,7 @@ function element$2(state, node) {
24287
22642
  const attribute = node.attrs[index];
24288
22643
  const name =
24289
22644
  (attribute.prefix ? attribute.prefix + ':' : '') + attribute.name;
24290
- if (!own$4.call(proto, name)) {
22645
+ if (!own$2.call(proto, name)) {
24291
22646
  props[name] = attribute.value;
24292
22647
  }
24293
22648
  }
@@ -24380,7 +22735,7 @@ function createLocation(state, node, location) {
24380
22735
 
24381
22736
  if (location.attrs) {
24382
22737
  for (key in location.attrs) {
24383
- if (own$4.call(location.attrs, key)) {
22738
+ if (own$2.call(location.attrs, key)) {
24384
22739
  props[find$1(state.schema, key).property] = position(
24385
22740
  location.attrs[key]
24386
22741
  );
@@ -24644,7 +22999,7 @@ function mark(values, key, value) {
24644
22999
  */
24645
23000
 
24646
23001
 
24647
- const own$3 = {}.hasOwnProperty;
23002
+ const own$1 = {}.hasOwnProperty;
24648
23003
 
24649
23004
  /**
24650
23005
  * @param {Definition} definition
@@ -24659,7 +23014,7 @@ function create(definition) {
24659
23014
  let prop;
24660
23015
 
24661
23016
  for (prop in definition.properties) {
24662
- if (own$3.call(definition.properties, prop)) {
23017
+ if (own$1.call(definition.properties, prop)) {
24663
23018
  const value = definition.properties[prop];
24664
23019
  const info = new DefinedInfo(
24665
23020
  prop,
@@ -25765,125 +24120,6 @@ const webNamespaces = {
25765
24120
  xmlns: 'http://www.w3.org/2000/xmlns/'
25766
24121
  };
25767
24122
 
25768
- /**
25769
- * @callback Handler
25770
- * Handle a value, with a certain ID field set to a certain value.
25771
- * The ID field is passed to `zwitch`, and it’s value is this function’s
25772
- * place on the `handlers` record.
25773
- * @param {...any} parameters
25774
- * Arbitrary parameters passed to the zwitch.
25775
- * The first will be an object with a certain ID field set to a certain value.
25776
- * @returns {any}
25777
- * Anything!
25778
- */
25779
-
25780
- /**
25781
- * @callback UnknownHandler
25782
- * Handle values that do have a certain ID field, but it’s set to a value
25783
- * that is not listed in the `handlers` record.
25784
- * @param {unknown} value
25785
- * An object with a certain ID field set to an unknown value.
25786
- * @param {...any} rest
25787
- * Arbitrary parameters passed to the zwitch.
25788
- * @returns {any}
25789
- * Anything!
25790
- */
25791
-
25792
- /**
25793
- * @callback InvalidHandler
25794
- * Handle values that do not have a certain ID field.
25795
- * @param {unknown} value
25796
- * Any unknown value.
25797
- * @param {...any} rest
25798
- * Arbitrary parameters passed to the zwitch.
25799
- * @returns {void|null|undefined|never}
25800
- * This should crash or return nothing.
25801
- */
25802
-
25803
- /**
25804
- * @template {InvalidHandler} [Invalid=InvalidHandler]
25805
- * @template {UnknownHandler} [Unknown=UnknownHandler]
25806
- * @template {Record<string, Handler>} [Handlers=Record<string, Handler>]
25807
- * @typedef Options
25808
- * Configuration (required).
25809
- * @property {Invalid} [invalid]
25810
- * Handler to use for invalid values.
25811
- * @property {Unknown} [unknown]
25812
- * Handler to use for unknown values.
25813
- * @property {Handlers} [handlers]
25814
- * Handlers to use.
25815
- */
25816
-
25817
- const own$2 = {}.hasOwnProperty;
25818
-
25819
- /**
25820
- * Handle values based on a field.
25821
- *
25822
- * @template {InvalidHandler} [Invalid=InvalidHandler]
25823
- * @template {UnknownHandler} [Unknown=UnknownHandler]
25824
- * @template {Record<string, Handler>} [Handlers=Record<string, Handler>]
25825
- * @param {string} key
25826
- * Field to switch on.
25827
- * @param {Options<Invalid, Unknown, Handlers>} [options]
25828
- * Configuration (required).
25829
- * @returns {{unknown: Unknown, invalid: Invalid, handlers: Handlers, (...parameters: Parameters<Handlers[keyof Handlers]>): ReturnType<Handlers[keyof Handlers]>, (...parameters: Parameters<Unknown>): ReturnType<Unknown>}}
25830
- */
25831
- function zwitch$1(key, options) {
25832
- const settings = options || {};
25833
-
25834
- /**
25835
- * Handle one value.
25836
- *
25837
- * Based on the bound `key`, a respective handler will be called.
25838
- * If `value` is not an object, or doesn’t have a `key` property, the special
25839
- * “invalid” handler will be called.
25840
- * If `value` has an unknown `key`, the special “unknown” handler will be
25841
- * called.
25842
- *
25843
- * All arguments, and the context object, are passed through to the handler,
25844
- * and it’s result is returned.
25845
- *
25846
- * @this {unknown}
25847
- * Any context object.
25848
- * @param {unknown} [value]
25849
- * Any value.
25850
- * @param {...unknown} parameters
25851
- * Arbitrary parameters passed to the zwitch.
25852
- * @property {Handler} invalid
25853
- * Handle for values that do not have a certain ID field.
25854
- * @property {Handler} unknown
25855
- * Handle values that do have a certain ID field, but it’s set to a value
25856
- * that is not listed in the `handlers` record.
25857
- * @property {Handlers} handlers
25858
- * Record of handlers.
25859
- * @returns {unknown}
25860
- * Anything.
25861
- */
25862
- function one(value, ...parameters) {
25863
- /** @type {Handler|undefined} */
25864
- let fn = one.invalid;
25865
- const handlers = one.handlers;
25866
-
25867
- if (value && own$2.call(value, key)) {
25868
- // @ts-expect-error Indexable.
25869
- const id = String(value[key]);
25870
- // @ts-expect-error Indexable.
25871
- fn = own$2.call(handlers, id) ? handlers[id] : one.unknown;
25872
- }
25873
-
25874
- if (fn) {
25875
- return fn.call(this, value, ...parameters)
25876
- }
25877
- }
25878
-
25879
- one.handlers = settings.handlers || {};
25880
- one.invalid = settings.invalid;
25881
- one.unknown = settings.unknown;
25882
-
25883
- // @ts-expect-error: matches!
25884
- return one
25885
- }
25886
-
25887
24123
  /**
25888
24124
  * @typedef {import('hast').Comment} Comment
25889
24125
  * @typedef {import('hast').Doctype} Doctype
@@ -25910,9 +24146,9 @@ function zwitch$1(key, options) {
25910
24146
  /** @type {Options} */
25911
24147
  const emptyOptions = {};
25912
24148
 
25913
- const own$1 = {}.hasOwnProperty;
24149
+ const own = {}.hasOwnProperty;
25914
24150
 
25915
- const one = zwitch$1('type', {handlers: {root: root$1, element: element$1, text: text$1, comment: comment$1, doctype: doctype$1}});
24151
+ const one = zwitch('type', {handlers: {root: root$1, element: element$1, text: text$1, comment: comment$1, doctype: doctype$1}});
25916
24152
 
25917
24153
  /**
25918
24154
  * Transform a hast tree to a `parse5` AST.
@@ -26050,7 +24286,7 @@ function element$1(node, schema) {
26050
24286
 
26051
24287
  if (node.properties) {
26052
24288
  for (prop in node.properties) {
26053
- if (prop !== 'children' && own$1.call(node.properties, prop)) {
24289
+ if (prop !== 'children' && own.call(node.properties, prop)) {
26054
24290
  const result = createProperty(
26055
24291
  currentSchema,
26056
24292
  prop,
@@ -34136,125 +32372,6 @@ function point(type) {
34136
32372
  }
34137
32373
  }
34138
32374
 
34139
- /**
34140
- * @callback Handler
34141
- * Handle a value, with a certain ID field set to a certain value.
34142
- * The ID field is passed to `zwitch`, and it’s value is this function’s
34143
- * place on the `handlers` record.
34144
- * @param {...any} parameters
34145
- * Arbitrary parameters passed to the zwitch.
34146
- * The first will be an object with a certain ID field set to a certain value.
34147
- * @returns {any}
34148
- * Anything!
34149
- */
34150
-
34151
- /**
34152
- * @callback UnknownHandler
34153
- * Handle values that do have a certain ID field, but it’s set to a value
34154
- * that is not listed in the `handlers` record.
34155
- * @param {unknown} value
34156
- * An object with a certain ID field set to an unknown value.
34157
- * @param {...any} rest
34158
- * Arbitrary parameters passed to the zwitch.
34159
- * @returns {any}
34160
- * Anything!
34161
- */
34162
-
34163
- /**
34164
- * @callback InvalidHandler
34165
- * Handle values that do not have a certain ID field.
34166
- * @param {unknown} value
34167
- * Any unknown value.
34168
- * @param {...any} rest
34169
- * Arbitrary parameters passed to the zwitch.
34170
- * @returns {void|null|undefined|never}
34171
- * This should crash or return nothing.
34172
- */
34173
-
34174
- /**
34175
- * @template {InvalidHandler} [Invalid=InvalidHandler]
34176
- * @template {UnknownHandler} [Unknown=UnknownHandler]
34177
- * @template {Record<string, Handler>} [Handlers=Record<string, Handler>]
34178
- * @typedef Options
34179
- * Configuration (required).
34180
- * @property {Invalid} [invalid]
34181
- * Handler to use for invalid values.
34182
- * @property {Unknown} [unknown]
34183
- * Handler to use for unknown values.
34184
- * @property {Handlers} [handlers]
34185
- * Handlers to use.
34186
- */
34187
-
34188
- const own = {}.hasOwnProperty;
34189
-
34190
- /**
34191
- * Handle values based on a field.
34192
- *
34193
- * @template {InvalidHandler} [Invalid=InvalidHandler]
34194
- * @template {UnknownHandler} [Unknown=UnknownHandler]
34195
- * @template {Record<string, Handler>} [Handlers=Record<string, Handler>]
34196
- * @param {string} key
34197
- * Field to switch on.
34198
- * @param {Options<Invalid, Unknown, Handlers>} [options]
34199
- * Configuration (required).
34200
- * @returns {{unknown: Unknown, invalid: Invalid, handlers: Handlers, (...parameters: Parameters<Handlers[keyof Handlers]>): ReturnType<Handlers[keyof Handlers]>, (...parameters: Parameters<Unknown>): ReturnType<Unknown>}}
34201
- */
34202
- function zwitch(key, options) {
34203
- const settings = options || {};
34204
-
34205
- /**
34206
- * Handle one value.
34207
- *
34208
- * Based on the bound `key`, a respective handler will be called.
34209
- * If `value` is not an object, or doesn’t have a `key` property, the special
34210
- * “invalid” handler will be called.
34211
- * If `value` has an unknown `key`, the special “unknown” handler will be
34212
- * called.
34213
- *
34214
- * All arguments, and the context object, are passed through to the handler,
34215
- * and it’s result is returned.
34216
- *
34217
- * @this {unknown}
34218
- * Any context object.
34219
- * @param {unknown} [value]
34220
- * Any value.
34221
- * @param {...unknown} parameters
34222
- * Arbitrary parameters passed to the zwitch.
34223
- * @property {Handler} invalid
34224
- * Handle for values that do not have a certain ID field.
34225
- * @property {Handler} unknown
34226
- * Handle values that do have a certain ID field, but it’s set to a value
34227
- * that is not listed in the `handlers` record.
34228
- * @property {Handlers} handlers
34229
- * Record of handlers.
34230
- * @returns {unknown}
34231
- * Anything.
34232
- */
34233
- function one(value, ...parameters) {
34234
- /** @type {Handler|undefined} */
34235
- let fn = one.invalid;
34236
- const handlers = one.handlers;
34237
-
34238
- if (value && own.call(value, key)) {
34239
- // @ts-expect-error Indexable.
34240
- const id = String(value[key]);
34241
- // @ts-expect-error Indexable.
34242
- fn = own.call(handlers, id) ? handlers[id] : one.unknown;
34243
- }
34244
-
34245
- if (fn) {
34246
- return fn.call(this, value, ...parameters)
34247
- }
34248
- }
34249
-
34250
- one.handlers = settings.handlers || {};
34251
- one.invalid = settings.invalid;
34252
- one.unknown = settings.unknown;
34253
-
34254
- // @ts-expect-error: matches!
34255
- return one
34256
- }
34257
-
34258
32375
  /**
34259
32376
  * @typedef {import('hast').Comment} Comment
34260
32377
  * @typedef {import('hast').Doctype} Doctype