/project-toolkit:fix-markdown-fencesfrom project-toolkit
Scans and repairs malformed markdown code fence closings, fixing closing fences with language identifiers and unclosed blocks.
Ships in project-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Scan and repair malformed closing fences in markdown files. Closing fences must never contain language identifiers.
| Trigger Phrase | Operation |
|---|---|
fix markdown fences | Scan and repair malformed fence closings |
repair code block closings | Fix closing fences with language identifiers |
markdown rendering broken | Diagnose and fix fence issues |
code blocks bleeding into content | Fix unclosed or malformed fences |
validate markdown code blocks | Check all fences for correctness |
| Symptom | Cause | Fix |
|---|---|---|
| Code block bleeds into text | Closing fence has language identifier | Insert a bare closing fence above it; the line then opens the next block |
| Nested blocks render wrong | Missing closing fence before new opening | Insert closing fence |
| Content cut off at end of file | Unclosed code block | Append closing fence |
Use this skill when:
```python instead of ```)Use manual editing instead when:
Do not walk the file by hand. Fence tracking is a state machine, and
fix_fences.py runs it.
FILE:LINE: KIND: TEXT, up to 200 lines, then says how many it left out (write
--max-lines 0 inside the locator for all, or narrow the path). It exits 1 when it finds any.( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/fix-markdown-fences/scripts/fix_fences.py FILE_OR_DIR; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
Read the report. Two kinds appear:
malformed_closing: a closing fence carries a language identifier, so
the block bleeds into the following prose.unclosed_block: the file ends with a block still open.Decide, then write. Repair is best-effort on an ambiguous file. When a defect cluster sits inside documentation that shows fenced markdown, the author usually wanted a wider container fence (four backticks around a three-backtick example), not the closing fence the repair inserts. Widen the container by hand in that case. Otherwise:
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/fix-markdown-fences/scripts/fix_fences.py FILE_OR_DIR --write; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
git diff and
confirm only fence lines moved.Detects and repairs malformed fence closings. Reporting is the default;
--write is required to modify a file.
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/fix-markdown-fences/scripts/fix_fences.py PATH [PATH ...]; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/fix-markdown-fences/scripts/fix_fences.py PATH --write; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/fix-markdown-fences/scripts/fix_fences.py PATH --json; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
Options: --write repairs in place, --json emits machine-readable output,
--pattern sets the glob for directory scans (default *.md), --max-lines
bounds the text listing (default 200, 0 lists all; --json is never cut). Paths default
to the current directory. .git, node_modules, .venv, venv, and __pycache__
are skipped.
Fence matching follows CommonMark, which is what keeps the tool from damaging documentation:
* * * matches the bullet grammar, and a list may interrupt a paragraph only
when the item is non-empty and, if ordered, starts at 1 (leading zeros do not
change that start). That last veto is scoped to the item the paragraph lives
in: a marker indented below the content column closes the item, the paragraph
closes with it, and the marker is then judged at the outer level where no
paragraph is open. A link reference definition ([foo]: /url) is its own
block and leaves no paragraph open, so a list may start after one; but a
definition cannot interrupt a paragraph that is already open, its
destination and title must be complete ([foo]: <broken is prose), its
destination balances parentheses at any depth and may escape either
angle delimiter while a title may escape its own and may run across
lines until that delimiter arrives, a continuation belongs to the same
leaf block and so keeps its meaning at any indent, and
either the destination or a bare title may sit on the following line, and
a blank line, a fenced block, a list marker or an indented code block
cancels a definition still waiting for one, while a line that does
continue one is a lazy continuation and does not close the item holding
it. A label of only whitespace is not a definition at all. A blank line
directly after an empty marker closes the item, and a paragraph
continuation line may dedent without closing it.
Getting any of these wrong moves the content column, which moves what counts
as a fence.- - a opens two items. A block also ends when the item holding
it ends, with no closing marker, so a line that dedents below it closes it.
Without either rule the tool kept a block open past its real end, and
--write appended a closing fence to documents already well formed.markdown-it-py is
installed, --write refuses a file whose repair comes out unclosed (see
"Write guard"), which stops the shapes below whose input was balanced and
whose repair leaves a fence open. It does not stop a repair that the
reference parser still reads as balanced. Where it is not installed those
shapes are written as described. A raw HTML block swallows a following
fence, so a fence inside one is read as a fence here and as HTML by
CommonMark. --write refuses that file with no extra package (see "Write
guard"): measured across all seven CommonMark HTML block types, opener
terminated and unterminated, 20 of 20 shapes are refused. The check reads
HTML blocks at column zero to three. A block inside a list item or a
blockquote is not seen, so a fence inside one is still written to. It also
refuses a file where a start condition 7 tag such as <span> follows
paragraph text, which CommonMark does not read as a block. A refused write
costs a manual edit. A blockquote prefix is never stripped,
and that costs two different things. A fence inside > is invisible, which is a miss: six
shapes diverge and --write changes none. A blockquote INTERRUPTING a
paragraph is worse: CommonMark ends the paragraph and lazily continues the
quote, so a following 2. opens a list, while we keep the paragraph open
and the repair function appends a closer to a balanced document. Five of
twelve measured shapes do that. Where markdown-it-py is installed,
--write refuses all five and writes none (see "Write guard"); without it
the five are written. A backslash in a link destination escapes whatever
follows it, where CommonMark escapes only ASCII punctuation, so an escaped
space and an escaped tab are read wrongly: 62 of 64 shapes agree. The spec
rule was measured before being believed and is worse, 34 of 64 with 30
--write corruptions, so the permissive rule stays. The escaped-TAB half is
destructive on its own account, because tabs are expanded to four-column
stops before the grammar sees them, so what the permissive rule eats depends
on the label's length: nine of eleven single-line label lengths turn a
balanced document into an unclosed one, and the two that do not are the two
that land on a tab stop. Escaped space and the next-line destination path
corrupt none of eleven. Where markdown-it-py is installed, --write
refuses all nine and writes none (see "Write guard"); without it the nine
are written. And a setext ===
underline directly under a list item, followed by a lazy continuation and
then an indented fence, leaves that fence unseen. The repair function is
DESTRUCTIVE here, and it was recorded as a miss on a measurement that did not
hold: over nine shapes, seven are rewritten and six go in balanced and come
out unclosed. The smallest is five lines, - item / === / lazy /
two-space fence / out, where the list item ending closes the fence for
CommonMark and the repair appends a second one at top level. Where
markdown-it-py is installed, --write refuses all six of those files and
writes none (see "Write guard"); the seventh rewritten shape is a genuinely
unclosed file and is repaired correctly. Without the package the six are
written. --- under
the same item already agrees. The scanners' agreement with a CommonMark
reference is measured by the fuzz baselines in the repository's test suite.Files are read and written as bytes, so CRLF and CR endings survive, a UTF-8
BOM survives, and every separator str.splitlines would swallow (U+000B,
U+000C, U+001C, U+001D, U+001E, U+0085, U+2028, U+2029) stays put. Each line keeps its own terminator, so
a mixed-ending file is not normalized. Repair is idempotent.
Exit codes (ADR-035):
0 no defects found, or --write repaired every defect it found1 report mode found at least one defect; nothing was written. With
--write, at least one file was refused (see "Write guard"); nothing was
written for it2 a requested path does not exist, or a file could not be read or written--write runs two checks before it replaces a file. Either one refuses it: the
file is not written, it is listed on a Refused line with the reason, the
refused key under --json names it and refusal_reasons says why, and the
run exits 1. Other files in the same run are still repaired. When a file is
refused, read the report and fix the fences by hand.
A fence inside a raw HTML block. CommonMark reads the fence as HTML, so the document is complete, while the scanner reads a fence and would append a closer. The edit lands on a well-formed file. The scanner does not model HTML blocks, so a file with a fence-looking line inside one is refused. This check needs no extra package. Fences inside a fenced block are skipped, so HTML shown as an example does not count, and an HTML block that a blank line or its own end marker closes before the fence does not count either. A block inside a list item or a blockquote is not seen.
A repair that leaves a fence open. A repair must never turn a balanced file
into an unclosed one. The worst case is a mistaken closer next to a raw HTML
block: the repair inserts a closing fence above the info-string fence, then
appends another at the end of the file, and the appended one is a fresh opener
that nothing closes. A tracked file did exactly that. So --write checks the
repaired text against markdown-it-py. A file that was balanced and would come
out unclosed is refused. A file that was already unclosed is never refused,
since repair cannot make it worse by that measure.
markdown-it-py is optional because this skill is vendored into trees that
carry no third-party packages. Without it this second check is skipped, stderr
says so, and the HTML check still runs. Report mode never needs either.
Kept so a reader can audit the script, not so the agent can run it by hand.
Track fence state while scanning line by line:
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/fix-markdown-fences/scripts/fix_fences.py PATH; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
echo "exit=$?" # 0 = clean, 1 = defects found, 2 = bad input
git diff shows only fence lines added, no content modifications.--write.| Avoid | Why | Instead |
|---|---|---|
| Manually searching for bad fences | Error-prone in large files, and the agent cannot track fence length by eye | Run fix_fences.py |
| Simulating the state machine in-context | The script already does it, exactly and for free | Read the script's report |
Running --write across a whole repo unreviewed | A repair inside nested documentation is often the wrong fix | Report first, review, then write per path |
| Copying opening fence line to close a block | Creates the exact bug this skill fixes | Close with the opener's character, no info string, at least the opener's length |
| Fixing fences without tracking block state | Misidentifies nested vs sequential blocks | Run fix_fences.py, which tracks it |
When generating markdown with code blocks:
The shipped script does this for you; fix_fences.py is the
implementation, and the Reference section above is the algorithm it runs. An
earlier revision of this file inlined a copy of that parser here under
"Implementation: Python (Recommended)". It was the pre-CommonMark version,
which had no fence-length rule and so corrupted any document showing a
three-backtick example inside a four-backtick container. It is gone rather
than fixed: a second copy of a parser drifts from the one that ships.
# Find files with potential issues
# Single quotes throughout: a backtick inside DOUBLE quotes opens command
# substitution, and this line used to fail `bash -n` for that reason.
grep -rEn --include="*.md" -- '```\w+' . | grep -vE '^[^:]*:[0-9]*:[[:space:]]*```\w+[[:space:]]*$'
An earlier revision also inlined a PowerShell rewriter here. It is gone for
the same reason, and measurement is why rather than symmetry: run on a CRLF
file it rewrote every ending to LF, which the Edge Cases list below
explicitly promises it does not do, and a ~~~python block left unclosed
was invisible to it because it matched backticks only. The shipped script
closes that tilde block and preserves the CRLF. A copy that drifts this far
while sitting under the same heading is worse than no example.
\n, \r\n and \r are preserved per line, as is a UTF-8 BOM and the presence or absence of a trailing newlineWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (rjmurillo/ai-agents) — no native marketplace selected
npx claudepluginhub p/rjmurillo-copilot-cli-agents-src-copilot-cli104 skills in this plugin
/adr-generatorCreate comprehensive Architectural Decision Records (ADRs). Researches the destination directory to detect existing template conventions, gathers context, determines next ADR number, generates the ADR, validates completeness, and saves. Supports multiple ADR formats (MADR, Nygard, Alexandrian, project canonical). Use when documenting technical decisions, creating new ADR files, or capturing rationale so future readers can revisit a choice. Use when you say "write an ADR", "document this decision", "document these design choices", "record why we chose this", "capture the rationale", or "for future maintainers", or when creating an ADR-like markdown file under docs/decisions/, docs/adr/, docs/architecture/, architecture/decisions/, or .project-toolkit/architecture/. Do NOT use to debate or review an existing ADR (use adr-review)./adr-reviewMulti-agent debate orchestration for Architecture Decision Records. Automatically triggers on ADR create/edit/delete. Coordinates architect, critic, independent-thinker, security, analyst, and high-level-advisor agents in structured debate rounds until consensus. Use when you say "review this ADR", when an ADR is created/edited/deleted, or when reviewing, accepting, or updating a decision file under .project-toolkit/architecture/, docs/architecture/, docs/decisions/, docs/adr/, or architecture/decisions/, including intent like "review this decision record" or "check this rationale for future maintainers". Do NOT use to author a new ADR (use adr-generator)./agent-harness-referenceField reference for Claude Code and GitHub Copilot CLI hook contracts. Covers hook locations, events, matchers, payloads, decisions, exit codes, timeouts, plugin roots, and cloud limits with official URLs and versioned probes. Use for `harness contract`, `copilot cli hook behavior`, `hook payload format`, `stale plugin root`, `Errno 2 _dispatch.py`, or before changing cross-harness hooks. Do NOT use to run the porting campaign (in the ai-agents repository, use `ai-agents-portability-campaign`)./ai-agents-external-claimsVerify external, vendor, and third-party claims (numbers, attributions, structure) against authoritative primary sources before they land in a repo artifact or external deliverable. Covers stake-holding sources, round-number tells, citation-chain drift, and the walk-the-gate-or-file-conservative discipline. Use when you say `verify an external claim`, `check a vendor number`, `is this stat real`, `validate a third-party citation`. Do NOT use for running an experiment (use `ai-agents-research-methodology` in the ai-agents repository) or command-injection scanning (use `security-scan`)./analysis-provenanceIdentify code ownership before modifying validators or linters. Checks file headers for provenance indicators, reviews documentation, and determines provenance as UPSTREAM, LOCAL, VENDOR, or UNKNOWN. Prevents accidental modification of upstream tools./analyzeSystematic multi-step codebase analysis producing prioritized findings with file-line evidence. Covers architecture reviews, security assessments, and code quality evaluations through guided exploration, investigation planning, and synthesis. Use when you say "analyze this codebase", "run security assessment", "architecture review of this system", "find code smells", or "review code quality" across multiple files. Do NOT use for single-file maintainability scoring (use code-qualities-assessment) or CWE-78 injection pattern scanning (use security-scan).Other plugins' skills for the same job