Skip to content

Exponential-time parsing for non-closed fenced divs #9635

Closed
@heatherleaf

Description

@heatherleaf

Pandoc version?

3.1.12.3

Explain the problem

If you accidentally forget to close a fenced div, the parser becomes extremely slow. Here's a minmal example:

#!/bin/bash

base="
# Here's an example
::: tag
This is a fenced div that's not closed.
"

echo > test.md
for ((i=1;i<=100;i++)); do 
    echo "$base" >> test.md
    echo -n "# $i:    "
    /usr/bin/time pandoc --metadata title="title" -o test.html test.md
done

On my computer I get this:

...
# 10:            0,14 real         0,13 user         0,00 sys
# 11:            0,28 real         0,27 user         0,00 sys
# 12:            0,53 real         0,52 user         0,00 sys
# 13:            1,07 real         1,05 user         0,00 sys
# 14:            2,08 real         2,06 user         0,00 sys
# 15:            4,15 real         4,13 user         0,01 sys
# 16:            8,31 real         8,28 user         0,01 sys
# 17:           16,66 real        16,61 user         0,02 sys
# 18:           33,37 real        33,28 user         0,03 sys
# 19:           68,65 real        68,49 user         0,07 sys
...

Solution suggestion

Any of these two should be fine:

  • When you reach a new section title: auto-close the fenced div, or report an error, or a warning
  • When you reach the end of the markdown file and there are still open fenced divs: auto-close, or report error/warning

Yes, sometimes you want section titles within a fenced div, but many times not. So perhaps a new cmd-line option where you can say how to handle nested fenced divs / sections. Perhaps a maximum nesting depth?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions