@markdoc/markdoc 0.5.9 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -3
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +5 -3
- package/dist/index.mjs.map +3 -3
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatter.test.ts +55 -0
- package/src/formatter.ts +5 -5
- package/src/tokenizer/plugins/annotations.test.ts +126 -0
- package/src/tokenizer/plugins/annotations.ts +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/annotations.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAiI9C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,QAM5C"}
|
package/package.json
CHANGED
package/src/formatter.test.ts
CHANGED
|
@@ -833,6 +833,61 @@ ${'`'.repeat(4)}
|
|
|
833
833
|
check(source, expected);
|
|
834
834
|
stable(expected);
|
|
835
835
|
});
|
|
836
|
+
it('lists in blockquotes', () => {
|
|
837
|
+
const source = `
|
|
838
|
+
> Intro:
|
|
839
|
+
>
|
|
840
|
+
> - One
|
|
841
|
+
> - Two
|
|
842
|
+
>
|
|
843
|
+
> 1. First
|
|
844
|
+
> 2. Second
|
|
845
|
+
>
|
|
846
|
+
> After`;
|
|
847
|
+
|
|
848
|
+
const expected = `
|
|
849
|
+
> Intro:
|
|
850
|
+
>
|
|
851
|
+
> - One
|
|
852
|
+
> - Two
|
|
853
|
+
>
|
|
854
|
+
> 1. First
|
|
855
|
+
> 1. Second
|
|
856
|
+
>
|
|
857
|
+
> After
|
|
858
|
+
`;
|
|
859
|
+
|
|
860
|
+
check(source, expected);
|
|
861
|
+
stable(expected);
|
|
862
|
+
});
|
|
863
|
+
it('nested blocks in blockquotes', () => {
|
|
864
|
+
const source = `
|
|
865
|
+
> - One
|
|
866
|
+
> - Nested
|
|
867
|
+
> - Two
|
|
868
|
+
>
|
|
869
|
+
> > Inner
|
|
870
|
+
> > quote
|
|
871
|
+
>
|
|
872
|
+
> \`\`\`js
|
|
873
|
+
> code();
|
|
874
|
+
> \`\`\`
|
|
875
|
+
`;
|
|
876
|
+
|
|
877
|
+
stable(source);
|
|
878
|
+
});
|
|
879
|
+
it('blockquotes with lists inside list items', () => {
|
|
880
|
+
const source = `
|
|
881
|
+
- Item
|
|
882
|
+
|
|
883
|
+
> Quote
|
|
884
|
+
>
|
|
885
|
+
> - One
|
|
886
|
+
> - Two
|
|
887
|
+
`;
|
|
888
|
+
|
|
889
|
+
stable(source);
|
|
890
|
+
});
|
|
836
891
|
it('skips over undefined variables', () => {
|
|
837
892
|
const sourceNode = new Markdoc.Ast.Node(
|
|
838
893
|
'tag',
|
package/src/formatter.ts
CHANGED
|
@@ -231,11 +231,11 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
231
231
|
break;
|
|
232
232
|
}
|
|
233
233
|
case 'blockquote': {
|
|
234
|
-
const prefix = '>' + SPACE;
|
|
235
|
-
|
|
236
|
-
.map((child) => format(child, no).
|
|
237
|
-
.
|
|
238
|
-
|
|
234
|
+
const prefix = NL + indent + '>' + SPACE;
|
|
235
|
+
const inner = n.children
|
|
236
|
+
.map((child) => format(child, { ...no, indent: 0 }).trim())
|
|
237
|
+
.join(NL + NL);
|
|
238
|
+
yield prefix + inner.split(NL).join(prefix) + NL;
|
|
239
239
|
break;
|
|
240
240
|
}
|
|
241
241
|
case 'hr': {
|
|
@@ -167,6 +167,132 @@ describe('MarkdownIt Annotations plugin', function () {
|
|
|
167
167
|
expect(example.length).toEqual(5);
|
|
168
168
|
expect(example[2].children.length).toEqual(1);
|
|
169
169
|
});
|
|
170
|
+
|
|
171
|
+
it('inside a blockquote', function () {
|
|
172
|
+
const example = parse(`
|
|
173
|
+
> {% test #foo .bar
|
|
174
|
+
> baz=1 %}
|
|
175
|
+
> This is a test
|
|
176
|
+
> {% /test %}
|
|
177
|
+
`);
|
|
178
|
+
|
|
179
|
+
expect(example).toDeepEqualSubset([
|
|
180
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
181
|
+
...basicExample,
|
|
182
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
183
|
+
]);
|
|
184
|
+
expect(example[1].map).toDeepEqual([0, 2]);
|
|
185
|
+
expect(example[2].map).toDeepEqual([2, 3]);
|
|
186
|
+
expect(example[5].map).toDeepEqual([3, 4]);
|
|
187
|
+
expect(example.length).toEqual(7);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('followed by content after the blockquote', function () {
|
|
191
|
+
const example = parse(`
|
|
192
|
+
> {% test #foo .bar
|
|
193
|
+
> baz=1 %}
|
|
194
|
+
> This is a test
|
|
195
|
+
> {% /test %}
|
|
196
|
+
After the blockquote
|
|
197
|
+
`);
|
|
198
|
+
|
|
199
|
+
expect(example).toDeepEqualSubset([
|
|
200
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
201
|
+
...basicExample,
|
|
202
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
203
|
+
{ type: 'paragraph_open', tag: 'p', nesting: 1 },
|
|
204
|
+
{
|
|
205
|
+
type: 'inline',
|
|
206
|
+
nesting: 0,
|
|
207
|
+
children: [
|
|
208
|
+
{ type: 'text', nesting: 0, content: 'After the blockquote' },
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
{ type: 'paragraph_close', tag: 'p', nesting: -1 },
|
|
212
|
+
]);
|
|
213
|
+
expect(example[1].map).toDeepEqual([0, 2]);
|
|
214
|
+
expect(example[5].map).toDeepEqual([3, 4]);
|
|
215
|
+
expect(example[7].map).toDeepEqual([4, 5]);
|
|
216
|
+
expect(example.length).toEqual(10);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('inside a list item', function () {
|
|
220
|
+
// Not dedented: list continuation depends on the indentation
|
|
221
|
+
const example = tokenizer.tokenize(`- {% test #foo .bar
|
|
222
|
+
baz=1 %}
|
|
223
|
+
This is a test
|
|
224
|
+
{% /test %}`);
|
|
225
|
+
|
|
226
|
+
expect(example).toDeepEqualSubset([
|
|
227
|
+
{ type: 'bullet_list_open', nesting: 1 },
|
|
228
|
+
{ type: 'list_item_open', nesting: 1 },
|
|
229
|
+
...basicExample,
|
|
230
|
+
{ type: 'list_item_close', nesting: -1 },
|
|
231
|
+
{ type: 'bullet_list_close', nesting: -1 },
|
|
232
|
+
]);
|
|
233
|
+
expect(example[2].map).toDeepEqual([0, 2]);
|
|
234
|
+
expect(example[3].map).toDeepEqual([2, 3]);
|
|
235
|
+
expect(example[6].map).toDeepEqual([3, 4]);
|
|
236
|
+
expect(example.length).toEqual(9);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('inside a list item inside a blockquote', function () {
|
|
240
|
+
const example = tokenizer.tokenize(`> - {% test #foo .bar
|
|
241
|
+
> baz=1 %}
|
|
242
|
+
> This is a test
|
|
243
|
+
> {% /test %}`);
|
|
244
|
+
|
|
245
|
+
expect(example).toDeepEqualSubset([
|
|
246
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
247
|
+
{ type: 'bullet_list_open', nesting: 1 },
|
|
248
|
+
{ type: 'list_item_open', nesting: 1 },
|
|
249
|
+
...basicExample,
|
|
250
|
+
{ type: 'list_item_close', nesting: -1 },
|
|
251
|
+
{ type: 'bullet_list_close', nesting: -1 },
|
|
252
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
253
|
+
]);
|
|
254
|
+
expect(example[3].map).toDeepEqual([0, 2]);
|
|
255
|
+
expect(example[4].map).toDeepEqual([2, 3]);
|
|
256
|
+
expect(example[7].map).toDeepEqual([3, 4]);
|
|
257
|
+
expect(example.length).toEqual(11);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('with a single-line container inside a blockquote', function () {
|
|
262
|
+
const example = parse(`
|
|
263
|
+
> {% test #foo .bar baz=1 %}
|
|
264
|
+
> This is a test
|
|
265
|
+
> {% /test %}
|
|
266
|
+
`);
|
|
267
|
+
|
|
268
|
+
expect(example).toDeepEqualSubset([
|
|
269
|
+
{ type: 'blockquote_open', nesting: 1 },
|
|
270
|
+
{
|
|
271
|
+
type: 'tag_open',
|
|
272
|
+
nesting: 1,
|
|
273
|
+
meta: {
|
|
274
|
+
attributes: [
|
|
275
|
+
{ type: 'attribute', name: 'id', value: 'foo' },
|
|
276
|
+
{ type: 'class', name: 'bar', value: true },
|
|
277
|
+
{ type: 'attribute', name: 'baz', value: 1 },
|
|
278
|
+
],
|
|
279
|
+
tag: 'test',
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{ type: 'paragraph_open', tag: 'p', nesting: 1 },
|
|
283
|
+
{
|
|
284
|
+
type: 'inline',
|
|
285
|
+
nesting: 0,
|
|
286
|
+
children: [{ type: 'text', nesting: 0, content: 'This is a test' }],
|
|
287
|
+
},
|
|
288
|
+
{ type: 'paragraph_close', tag: 'p', nesting: -1 },
|
|
289
|
+
{ type: 'tag_close', nesting: -1, meta: { tag: 'test' } },
|
|
290
|
+
{ type: 'blockquote_close', nesting: -1 },
|
|
291
|
+
]);
|
|
292
|
+
expect(example[1].map).toDeepEqual([0, 1]);
|
|
293
|
+
expect(example[2].map).toDeepEqual([1, 2]);
|
|
294
|
+
expect(example[5].map).toDeepEqual([2, 3]);
|
|
295
|
+
expect(example.length).toEqual(7);
|
|
170
296
|
});
|
|
171
297
|
|
|
172
298
|
describe('inline', function () {
|
|
@@ -65,10 +65,13 @@ function block(
|
|
|
65
65
|
if (!tagEnd || tagEnd < lastPossible - CLOSE.length) return false;
|
|
66
66
|
|
|
67
67
|
const contentStart = start + OPEN.length;
|
|
68
|
-
const content = state.src.slice(contentStart, tagEnd).trim();
|
|
69
68
|
const lines = state.src
|
|
70
69
|
.slice(start, tagEnd + CLOSE.length)
|
|
71
70
|
.split('\n').length;
|
|
71
|
+
const text = state.getLines(startLine, startLine + lines, 0, false);
|
|
72
|
+
const content = text
|
|
73
|
+
.slice(text.indexOf(OPEN) + OPEN.length, findTagEnd(text))
|
|
74
|
+
.trim();
|
|
72
75
|
|
|
73
76
|
if (content[0] === '$') return false;
|
|
74
77
|
|