Skip to content

Commit 71d108a

Browse files
committed
🐛 FIX: Nested field lists incorrectly nesting inside parent containers
Field lists inside list items (or other indented containers) would recursively nest each field inside the previous one, instead of being siblings. The body-indent scanner compared `tShift` against 0, which doesn't account for the parent block's indentation (`blkIndent`). Changed the check to `state.tShift[_line] <= state.blkIndent` so the comparison is relative to the containing block's indent. Fixes executablebooks/MyST-Parser#1108
1 parent b873507 commit 71d108a

2 files changed

Lines changed: 171 additions & 2 deletions

File tree

mdit_py_plugins/field_list/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ def _fieldlist_rule(
164164
while _line < endLine:
165165
# if start_of_content < end_of_content, then non-empty line
166166
if (state.bMarks[_line] + state.tShift[_line]) < state.eMarks[_line]:
167-
if state.tShift[_line] <= 0:
168-
# the line has no indent, so it's the end of the field
167+
if state.tShift[_line] <= state.blkIndent:
168+
# the line is not indented relative to the field marker,
169+
# so it's the end of the field body
169170
break
170171
block_indent = (
171172
state.tShift[_line]

tests/fixtures/field_list.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,171 @@ indented</p>
388388
</dd>
389389
</dl>
390390
.
391+
392+
Multiple fields in list item:
393+
.
394+
- :name1: body1
395+
:name2: body2
396+
:name3: body3
397+
.
398+
<ul>
399+
<li>
400+
<dl class="field-list">
401+
<dt>name1</dt>
402+
<dd>
403+
<p>body1</p>
404+
</dd>
405+
<dt>name2</dt>
406+
<dd>
407+
<p>body2</p>
408+
</dd>
409+
<dt>name3</dt>
410+
<dd>
411+
<p>body3</p>
412+
</dd>
413+
</dl>
414+
</li>
415+
</ul>
416+
.
417+
418+
Multiple fields in list item with body continuation:
419+
.
420+
- :name1: body1
421+
continuation
422+
:name2: body2
423+
.
424+
<ul>
425+
<li>
426+
<dl class="field-list">
427+
<dt>name1</dt>
428+
<dd>
429+
<p>body1
430+
continuation</p>
431+
</dd>
432+
<dt>name2</dt>
433+
<dd>
434+
<p>body2</p>
435+
</dd>
436+
</dl>
437+
</li>
438+
</ul>
439+
.
440+
441+
Multiple fields in list item with multi-paragraph body:
442+
.
443+
- :name1: body1
444+
445+
paragraph 2
446+
:name2: body2
447+
.
448+
<ul>
449+
<li>
450+
<dl class="field-list">
451+
<dt>name1</dt>
452+
<dd>
453+
<p>body1</p>
454+
<p>paragraph 2</p>
455+
</dd>
456+
<dt>name2</dt>
457+
<dd>
458+
<p>body2</p>
459+
</dd>
460+
</dl>
461+
</li>
462+
</ul>
463+
.
464+
465+
Field list in nested list:
466+
.
467+
- item
468+
- :name1: body1
469+
:name2: body2
470+
.
471+
<ul>
472+
<li>item
473+
<ul>
474+
<li>
475+
<dl class="field-list">
476+
<dt>name1</dt>
477+
<dd>
478+
<p>body1</p>
479+
</dd>
480+
<dt>name2</dt>
481+
<dd>
482+
<p>body2</p>
483+
</dd>
484+
</dl>
485+
</li>
486+
</ul>
487+
</li>
488+
</ul>
489+
.
490+
491+
Nested field list (body on next line):
492+
.
493+
:outer:
494+
:inner1: val1
495+
:inner2: val2
496+
.
497+
<dl class="field-list">
498+
<dt>outer</dt>
499+
<dd>
500+
<dl class="field-list">
501+
<dt>inner1</dt>
502+
<dd>
503+
<p>val1</p>
504+
</dd>
505+
<dt>inner2</dt>
506+
<dd>
507+
<p>val2</p>
508+
</dd>
509+
</dl>
510+
</dd>
511+
</dl>
512+
.
513+
514+
Nested field list (inline body):
515+
.
516+
:outer: :inner1: val1
517+
:inner2: val2
518+
.
519+
<dl class="field-list">
520+
<dt>outer</dt>
521+
<dd>
522+
<dl class="field-list">
523+
<dt>inner1</dt>
524+
<dd>
525+
<p>val1</p>
526+
</dd>
527+
<dt>inner2</dt>
528+
<dd>
529+
<p>val2</p>
530+
</dd>
531+
</dl>
532+
</dd>
533+
</dl>
534+
.
535+
536+
Double nested field list:
537+
.
538+
:a:
539+
:b:
540+
:c: val
541+
.
542+
<dl class="field-list">
543+
<dt>a</dt>
544+
<dd>
545+
<dl class="field-list">
546+
<dt>b</dt>
547+
<dd>
548+
<dl class="field-list">
549+
<dt>c</dt>
550+
<dd>
551+
<p>val</p>
552+
</dd>
553+
</dl>
554+
</dd>
555+
</dl>
556+
</dd>
557+
</dl>
558+
.

0 commit comments

Comments
 (0)