@xyd-js/content 0.0.0-build

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 (97) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/ISSUES.md +1 -0
  3. package/LICENSE +21 -0
  4. package/README.md +3 -0
  5. package/TODO.md +2 -0
  6. package/dist/index.d.ts +28 -0
  7. package/dist/index.js +1625 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/md.d.ts +72 -0
  10. package/dist/md.js +23508 -0
  11. package/dist/md.js.map +1 -0
  12. package/dist/mdToc-NBBxMJ4l.d.ts +12 -0
  13. package/dist/vite.d.ts +1066 -0
  14. package/dist/vite.js +20156 -0
  15. package/dist/vite.js.map +1 -0
  16. package/package.json +67 -0
  17. package/packages/md/index.ts +25 -0
  18. package/packages/md/plugins/component-directives/index.ts +3 -0
  19. package/packages/md/plugins/component-directives/mdComponentDirective.ts +577 -0
  20. package/packages/md/plugins/component-directives/types.ts +1 -0
  21. package/packages/md/plugins/component-directives/utils.ts +27 -0
  22. package/packages/md/plugins/composer/__fixtures__/1.single-example/input.md +7 -0
  23. package/packages/md/plugins/composer/__fixtures__/1.single-example/output.json +63 -0
  24. package/packages/md/plugins/composer/__fixtures__/2.single-example-with-name/input.md +7 -0
  25. package/packages/md/plugins/composer/__fixtures__/2.single-example-with-name/output.json +63 -0
  26. package/packages/md/plugins/composer/__fixtures__/3.multiple-examples/input.md +15 -0
  27. package/packages/md/plugins/composer/__fixtures__/3.multiple-examples/output.json +122 -0
  28. package/packages/md/plugins/composer/__fixtures__/4.example-groups/input.md +23 -0
  29. package/packages/md/plugins/composer/__fixtures__/4.example-groups/output.json +184 -0
  30. package/packages/md/plugins/composer/__tests__/mdComposer.test.ts +41 -0
  31. package/packages/md/plugins/composer/__tests__/testHelpers.ts +48 -0
  32. package/packages/md/plugins/composer/index.ts +1 -0
  33. package/packages/md/plugins/composer/mdComposer.ts +146 -0
  34. package/packages/md/plugins/developer-writing/index.ts +3 -0
  35. package/packages/md/plugins/developer-writing/mdCodeRehype.ts +81 -0
  36. package/packages/md/plugins/functions/__fixtures__/external.ts +4 -0
  37. package/packages/md/plugins/functions/__fixtures__/test-include.md +31 -0
  38. package/packages/md/plugins/functions/__fixtures__/test.js +11 -0
  39. package/packages/md/plugins/functions/__fixtures__/test.py +9 -0
  40. package/packages/md/plugins/functions/__fixtures__/test.ts +18 -0
  41. package/packages/md/plugins/functions/__tests__/mdFunctionImportCode.test.ts +314 -0
  42. package/packages/md/plugins/functions/__tests__/mdFunctionInclude.test.ts +44 -0
  43. package/packages/md/plugins/functions/__tests__/parseFunctionCall.test.ts +70 -0
  44. package/packages/md/plugins/functions/__tests__/testHelpers.ts +95 -0
  45. package/packages/md/plugins/functions/index.ts +15 -0
  46. package/packages/md/plugins/functions/mdFunctionChangelog.ts +135 -0
  47. package/packages/md/plugins/functions/mdFunctionImportCode.ts +92 -0
  48. package/packages/md/plugins/functions/mdFunctionInclude.ts +119 -0
  49. package/packages/md/plugins/functions/mdFunctionUniform.ts +79 -0
  50. package/packages/md/plugins/functions/types.ts +9 -0
  51. package/packages/md/plugins/functions/uniformProcessor.ts +349 -0
  52. package/packages/md/plugins/functions/utils.ts +457 -0
  53. package/packages/md/plugins/index.ts +125 -0
  54. package/packages/md/plugins/mdCode.ts +16 -0
  55. package/packages/md/plugins/mdHeadingId.ts +47 -0
  56. package/packages/md/plugins/mdImage.test.ts +59 -0
  57. package/packages/md/plugins/mdImage.ts +55 -0
  58. package/packages/md/plugins/mdImageRehype.ts +13 -0
  59. package/packages/md/plugins/mdPage.ts +35 -0
  60. package/packages/md/plugins/mdThemeSettings.ts +34 -0
  61. package/packages/md/plugins/mdToc.ts +229 -0
  62. package/packages/md/plugins/meta/index.ts +1 -0
  63. package/packages/md/plugins/meta/mdMeta.ts +198 -0
  64. package/packages/md/plugins/output-variables/__fixtures__/1.simple/input.md +22 -0
  65. package/packages/md/plugins/output-variables/__fixtures__/1.simple/output.json +191 -0
  66. package/packages/md/plugins/output-variables/__fixtures__/2.multiple-vars/input.md +21 -0
  67. package/packages/md/plugins/output-variables/__fixtures__/2.multiple-vars/output.json +127 -0
  68. package/packages/md/plugins/output-variables/__tests__/index.test.ts +28 -0
  69. package/packages/md/plugins/output-variables/__tests__/testHelpers.ts +36 -0
  70. package/packages/md/plugins/output-variables/index.ts +1 -0
  71. package/packages/md/plugins/output-variables/lib/const.ts +4 -0
  72. package/packages/md/plugins/output-variables/lib/factoryAttributes.ts +350 -0
  73. package/packages/md/plugins/output-variables/lib/factoryLabel.ts +135 -0
  74. package/packages/md/plugins/output-variables/lib/factoryName.ts +59 -0
  75. package/packages/md/plugins/output-variables/lib/index.ts +21 -0
  76. package/packages/md/plugins/output-variables/lib/outputVarsContainer.ts +328 -0
  77. package/packages/md/plugins/output-variables/lib/util.ts +494 -0
  78. package/packages/md/plugins/output-variables/remarkOutputVars.ts +22 -0
  79. package/packages/md/plugins/recmaOverrideComponents.ts +74 -0
  80. package/packages/md/plugins/rehypeHeading.ts +58 -0
  81. package/packages/md/plugins/types.ts +15 -0
  82. package/packages/md/plugins/utils/componentLike.ts +76 -0
  83. package/packages/md/plugins/utils/index.ts +2 -0
  84. package/packages/md/plugins/utils/injectCodeMeta.ts +59 -0
  85. package/packages/md/plugins/utils/mdParameters.test.ts +114 -0
  86. package/packages/md/plugins/utils/mdParameters.ts +249 -0
  87. package/packages/md/plugins/utils/mdastTypes.ts +42 -0
  88. package/packages/md/search/index.ts +257 -0
  89. package/packages/md/search/types.ts +36 -0
  90. package/packages/vite/index.ts +20 -0
  91. package/src/fs.ts +81 -0
  92. package/src/index.ts +7 -0
  93. package/src/navigation.ts +147 -0
  94. package/src/types.ts +8 -0
  95. package/tsconfig.json +49 -0
  96. package/tsup.config.ts +32 -0
  97. package/vitest.config.ts +17 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * @import {Construct, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
3
+ */
4
+
5
+ import { ok as assert } from 'devlop'
6
+ import { factorySpace } from 'micromark-factory-space'
7
+ import { markdownLineEnding } from 'micromark-util-character'
8
+ import { codes, constants, types } from 'micromark-util-symbol'
9
+
10
+ import { factoryAttributes } from './factoryAttributes'
11
+ import { factoryLabel } from './factoryLabel'
12
+ import { factoryName } from './factoryName'
13
+
14
+ import { PRIMARY_SYMBOL } from './const'
15
+
16
+ /** @type {Construct} */
17
+ export const outputVarsContainer = {
18
+ tokenize: tokenizeOutputVarsContainer,
19
+ concrete: true
20
+ }
21
+
22
+
23
+ const label = { tokenize: tokenizeLabel, partial: true }
24
+ const attributes = { tokenize: tokenizeAttributes, partial: true }
25
+ const nonLazyLine = { tokenize: tokenizeNonLazyLine, partial: true }
26
+
27
+ /**
28
+ * @this {TokenizeContext}
29
+ * @type {Tokenizer}
30
+ */
31
+ function tokenizeOutputVarsContainer(effects, ok, nok) {
32
+ const self = this
33
+ let size = 0
34
+ const tail = self.events[self.events.length - 1]
35
+ const initialSize =
36
+ tail && tail[1].type === types.linePrefix
37
+ ? tail[2].sliceSerialize(tail[1], true).length
38
+ : 0
39
+ let sizeOpen = 0
40
+ /** @type {Token} */
41
+ let previous
42
+
43
+ return start
44
+
45
+ /** @type {State} */
46
+ function start(code) {
47
+ assert(code === PRIMARY_SYMBOL, 'expected `>`')
48
+ effects.enter('outputVarContainer')
49
+ effects.enter('outputVarContainerFence')
50
+ effects.enter('outputVarContainerSequence')
51
+ return sequenceOpen(code)
52
+ }
53
+
54
+ /** @type {State} */
55
+ function sequenceOpen(code) {
56
+ if (code === PRIMARY_SYMBOL) {
57
+ effects.consume(code)
58
+ sizeOpen++
59
+ return sequenceOpen
60
+ }
61
+
62
+ if (sizeOpen < constants.codeFencedSequenceSizeMin) {
63
+ return nok(code)
64
+ }
65
+
66
+ effects.exit('outputVarContainerSequence')
67
+ return factoryName.call(
68
+ self,
69
+ effects,
70
+ afterName,
71
+ nok,
72
+ 'outputVarContainerName'
73
+ )(code)
74
+ }
75
+
76
+ /** @type {State} */
77
+ function afterName(code) {
78
+ return code === codes.leftSquareBracket
79
+ ? effects.attempt(label, afterLabel, afterLabel)(code)
80
+ : afterLabel(code)
81
+ }
82
+
83
+ /** @type {State} */
84
+ function afterLabel(code) {
85
+ return code === codes.leftCurlyBrace
86
+ ? effects.attempt(attributes, afterAttributes, afterAttributes)(code)
87
+ : afterAttributes(code)
88
+ }
89
+
90
+ /** @type {State} */
91
+ function afterAttributes(code) {
92
+ return factorySpace(effects, openAfter, types.whitespace)(code)
93
+ }
94
+
95
+ /** @type {State} */
96
+ function openAfter(code) {
97
+ effects.exit('outputVarContainerFence')
98
+
99
+ if (code === codes.eof) {
100
+ return after(code)
101
+ }
102
+
103
+ if (markdownLineEnding(code)) {
104
+ if (self.interrupt) {
105
+ return ok(code)
106
+ }
107
+
108
+ return effects.attempt(nonLazyLine, contentStart, after)(code)
109
+ }
110
+
111
+ return nok(code)
112
+ }
113
+
114
+ /** @type {State} */
115
+ function contentStart(code) {
116
+ if (code === codes.eof) {
117
+ return after(code)
118
+ }
119
+
120
+ if (markdownLineEnding(code)) {
121
+ return effects.check(
122
+ nonLazyLine,
123
+ emptyContentNonLazyLineAfter,
124
+ after
125
+ )(code)
126
+ }
127
+
128
+ effects.enter('outputVarContainerContent')
129
+ return lineStart(code)
130
+ }
131
+
132
+ /** @type {State} */
133
+ function lineStart(code) {
134
+ return effects.attempt(
135
+ { tokenize: tokenizeClosingFence, partial: true },
136
+ afterContent,
137
+ initialSize
138
+ ? factorySpace(effects, chunkStart, types.linePrefix, initialSize + 1)
139
+ : chunkStart
140
+ )(code)
141
+ }
142
+
143
+ /** @type {State} */
144
+ function chunkStart(code) {
145
+ if (code === codes.eof) {
146
+ return afterContent(code)
147
+ }
148
+
149
+ if (markdownLineEnding(code)) {
150
+ return effects.check(nonLazyLine, chunkNonLazyStart, afterContent)(code)
151
+ }
152
+
153
+ return chunkNonLazyStart(code)
154
+ }
155
+
156
+ /** @type {State} */
157
+ function contentContinue(code) {
158
+ if (code === codes.eof) {
159
+ const t = effects.exit(types.chunkDocument)
160
+ self.parser.lazy[t.start.line] = false
161
+ return afterContent(code)
162
+ }
163
+
164
+ if (markdownLineEnding(code)) {
165
+ return effects.check(nonLazyLine, nonLazyLineAfter, lineAfter)(code)
166
+ }
167
+
168
+ effects.consume(code)
169
+ return contentContinue
170
+ }
171
+
172
+ /** @type {State} */
173
+ function chunkNonLazyStart(code) {
174
+ const token = effects.enter(types.chunkDocument, {
175
+ contentType: constants.contentTypeDocument,
176
+ previous
177
+ })
178
+ if (previous) previous.next = token
179
+ previous = token
180
+ return contentContinue(code)
181
+ }
182
+
183
+ /** @type {State} */
184
+ function emptyContentNonLazyLineAfter(code) {
185
+ effects.enter('outputVarContainerContent')
186
+ return lineStart(code)
187
+ }
188
+
189
+ /** @type {State} */
190
+ function nonLazyLineAfter(code) {
191
+ effects.consume(code)
192
+ const t = effects.exit(types.chunkDocument)
193
+ self.parser.lazy[t.start.line] = false
194
+ return lineStart
195
+ }
196
+
197
+ /** @type {State} */
198
+ function lineAfter(code) {
199
+ const t = effects.exit(types.chunkDocument)
200
+ self.parser.lazy[t.start.line] = false
201
+ return afterContent(code)
202
+ }
203
+
204
+ /** @type {State} */
205
+ function afterContent(code) {
206
+ effects.exit('outputVarContainerContent')
207
+ return after(code)
208
+ }
209
+
210
+ /** @type {State} */
211
+ function after(code) {
212
+ effects.exit('outputVarContainer')
213
+ return ok(code)
214
+ }
215
+
216
+ /**
217
+ * @this {TokenizeContext}
218
+ * @type {Tokenizer}
219
+ */
220
+ function tokenizeClosingFence(effects, ok, nok) {
221
+ let size = 0
222
+ assert(self.parser.constructs.disable.null, 'expected `disable.null`')
223
+ return factorySpace(
224
+ effects,
225
+ closingPrefixAfter,
226
+ types.linePrefix,
227
+ self.parser.constructs.disable.null.includes('codeIndented')
228
+ ? undefined
229
+ : constants.tabSize
230
+ )
231
+
232
+ /** @type {State} */
233
+ function closingPrefixAfter(code) {
234
+ effects.enter('outputVarContainerFence')
235
+ effects.enter('outputVarContainerSequence')
236
+ return closingSequence(code)
237
+ }
238
+
239
+ /** @type {State} */
240
+ function closingSequence(code) {
241
+ if (code === PRIMARY_SYMBOL) {
242
+ effects.consume(code)
243
+ size++
244
+ return closingSequence
245
+ }
246
+
247
+ if (size < sizeOpen) return nok(code)
248
+ effects.exit('outputVarContainerSequence')
249
+ return factorySpace(effects, closingSequenceEnd, types.whitespace)(code)
250
+ }
251
+
252
+ /** @type {State} */
253
+ function closingSequenceEnd(code) {
254
+ if (code === codes.eof || markdownLineEnding(code)) {
255
+ effects.exit('outputVarContainerFence')
256
+ return ok(code)
257
+ }
258
+
259
+ return nok(code)
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * @this {TokenizeContext}
266
+ * @type {Tokenizer}
267
+ */
268
+ function tokenizeLabel(effects, ok, nok) {
269
+ // Always a `[`
270
+ return factoryLabel(
271
+ effects,
272
+ ok,
273
+ nok,
274
+ 'outputVarContainerLabel',
275
+ 'outputVarContainerLabelMarker',
276
+ 'outputVarContainerLabelString',
277
+ true
278
+ )
279
+ }
280
+
281
+ /**
282
+ * @this {TokenizeContext}
283
+ * @type {Tokenizer}
284
+ */
285
+ function tokenizeAttributes(effects, ok, nok) {
286
+ // Always a `{`
287
+ return factoryAttributes(
288
+ effects,
289
+ ok,
290
+ nok,
291
+ 'outputVarContainerAttributes',
292
+ 'outputVarContainerAttributesMarker',
293
+ 'outputVarContainerAttribute',
294
+ 'outputVarContainerAttributeId',
295
+ 'outputVarContainerAttributeClass',
296
+ 'outputVarContainerAttributeName',
297
+ 'outputVarContainerAttributeInitializerMarker',
298
+ 'outputVarContainerAttributeValueLiteral',
299
+ 'outputVarContainerAttributeValue',
300
+ 'outputVarContainerAttributeValueMarker',
301
+ 'outputVarContainerAttributeValueData',
302
+ true
303
+ )
304
+ }
305
+
306
+ /**
307
+ * @this {TokenizeContext}
308
+ * @type {Tokenizer}
309
+ */
310
+ function tokenizeNonLazyLine(effects, ok, nok) {
311
+ const self = this
312
+
313
+ return start
314
+
315
+ /** @type {State} */
316
+ function start(code) {
317
+ assert(markdownLineEnding(code), 'expected eol')
318
+ effects.enter(types.lineEnding)
319
+ effects.consume(code)
320
+ effects.exit(types.lineEnding)
321
+ return lineStart
322
+ }
323
+
324
+ /** @type {State} */
325
+ function lineStart(code) {
326
+ return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
327
+ }
328
+ }