Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scripts/md-exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ blah
EOF
```

A heredoc body may itself contain a line starting with ` ``` ` (e.g. a
heredoc that writes out markdown) without being mistaken for the end of
the code block:
```sh {empty_output}
$ cat > /tmp/md-exec-fence.txt << 'EOF'
before
```
after
EOF
```

---

## Global Directives
Expand Down
9 changes: 7 additions & 2 deletions scripts/md-exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ def parse(self):

stripped = line.strip()

# Detect Code Snippets
if stripped.startswith("```"):
# Detect Code Snippets. Skip fence detection while inside an
# open heredoc body -- the heredoc content may legitimately
# contain a line starting with ``` (e.g. a heredoc that writes
# out markdown), and treating it as a fence boundary would cut
# the code block short mid-heredoc, leaving the shell command
# truncated and the heredoc unterminated.
if stripped.startswith("```") and heredoc_delimiter is None:
if in_block:
# End of block: save pending test
if current_cmd:
Expand Down