From 21999b9f3523bce2459ef9ac1bc4ac5805994bc3 Mon Sep 17 00:00:00 2001 From: BathreeNode <101283333+batuhankocyigit@users.noreply.github.com> Date: Wed, 12 Aug 2026 11:34:15 +0300 Subject: [PATCH] Add files via upload --- scripts/md-exec.md | 11 +++++++++++ scripts/md-exec.py | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/md-exec.md b/scripts/md-exec.md index b1c75f03..13ecf984 100644 --- a/scripts/md-exec.md +++ b/scripts/md-exec.md @@ -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 diff --git a/scripts/md-exec.py b/scripts/md-exec.py index 749c1449..de78588a 100644 --- a/scripts/md-exec.py +++ b/scripts/md-exec.py @@ -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: