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