fix-markdown-fences
Repair malformed markdown code fence closings. Use when markdown files have closing fences with language identifiers or when generating markdown with code blocks to ensure proper fence closure.
- License 许可
- MIT
- 最近更新
- 2026-03-11
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- fix-markdown-fences
- model
- claude-haiku-4-5
- agents
- [ "implementer", "qa" ]
- license
- MIT
- metadata
- { "version": "1.1.0", "timelessness": "9/10" }
- description
- Repair malformed markdown code fence closings. Use when markdown files have closing fences with language identifiers or when generating markdown with code blocks to ensure proper fence closure.
02 资源文件 6
- 脚本fix_fences.ts3.4 KB
- 许可证LICENSE1.0 KB
- 参考文档references/workflow.md1.3 KB
- 脚本scripts/fetch_trader_snapshot.py6.2 KB
- 参考文档SOURCE.md364 B
- 参考文档TRUST.auto.yaml2.0 KB
03 SKILL.md 正文
Fix Markdown Code Fence Closings
Scan and repair malformed closing fences in markdown files. Closing fences must never contain language identifiers.
Triggers
| 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 |
Quick Reference
| Symptom | Cause | Fix |
|---|---|---|
| Code block bleeds into text | Closing fence has language identifier | Remove identifier from closing fence |
| 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 |
When to Use
Use this skill when:
- Markdown code blocks render incorrectly or bleed into surrounding content
- Closing fences have language identifiers (e.g.,
```pythoninstead of```) - Validating markdown documentation before committing
Use manual editing instead when:
- The issue is indentation or content inside the code block (not the fences)
- You need to change the language identifier on opening fences
Process
Track fence state while scanning line by line:
- Detect opening fence: Line matches the opening pattern below outside a block. Record indent level and enter "inside block" state.
- Detect malformed closing fence: While inside a block, line matches the malformed closing pattern below. Insert a proper closing fence before this line.
- Detect valid closing fence: Line matches the valid closing pattern below. Exit "inside block" state.
Regex patterns:
^\s*```[\w+-]+
^\s*```[\w+-]+\s*$
^\s*```\s*$
- [ ] No closing fences contain language identifiers
- [ ] Markdown renders correctly in preview
- [ ]
git diffshows only fence-closing changes, no content modifications
Anti-Patterns
| Avoid | Why | Instead |
|---|---|---|
| Manually searching for bad fences | Error-prone in large files | Use the algorithm or grep pattern |
| Copying opening fence line to close a block | Creates the exact bug this skill fixes | Always use plain ``` for closing |
| Fixing fences without tracking block state | Misidentifies nested vs sequential blocks | Use the stateful line-by-line algorithm |
Prevention
When generating markdown with code blocks:
- Always use plain ``` for closing fences
- Never copy the opening fence line to close
- Track block state when programmatically generating markdown
<details> <summary><strong>Implementation: TypeScript (Recommended)</strong></summary>
const OPENING_PATTERN = /^(\s*)```(\w+)/;
const CLOSING_PATTERN = /^(\s*)```\s*$/;
function repairMarkdownFences(content: string): string {
const lines = content.split(/\r?\n/);
const result: string[] = [];
let inCodeBlock = false;
let codeBlockIndent = "";
for (const line of lines) {
const openingMatch = line.match(OPENING_PATTERN);
const closingMatch = line.match(CLOSING_PATTERN);
if (openingMatch) {
if (inCodeBlock) {
result.push(codeBlockIndent + "```");
}
result.push(line);
codeBlockIndent = openingMatch[1];
inCodeBlock = true;
} else if (closingMatch) {
result.push(line);
inCodeBlock = false;
codeBlockIndent = "";
} else {
result.push(line);
}
}
if (inCodeBlock) {
result.push(codeBlockIndent + "```");
}
return result.join("\n");
}
</details>
<details> <summary><strong>Implementation: Bash (Quick Check)</strong></summary>
# Find files with potential issues
grep -rEn --include="*.md" -- '```\w+' . | grep -vE "^[^:]*:[0-9]*:[[:space:]]*```\w+[[:space:]]*$"
</details>
<details> <summary><strong>Edge Cases Handled</strong></summary>
- Nested indentation: Preserves indent level from opening fence
- Multiple consecutive blocks: Each block tracked independently
- File ending inside block: Automatically closes unclosed blocks
- Mixed line endings: Accepts both
\nand\r\nas input (normalizes output to\n)
</details>
04 同仓库更多 Skills
validation-authority
Treat upstream validators as authoritative. Align local config to them. Use when validation fails unexpectedly, before modifying validator behavior, or when tempted to change upstream tool code.
using-brain-memory
Guidance for using Brain semantic memory effectively. Applies Zettelkasten atomic note principles with observations and relations. Use when deciding whether to query or create notes, structuring note content, or understanding the semantic knowledge graph.
threat-modeling
Structured security analysis using OWASP Four-Question Framework and STRIDE methodology. Generates threat matrices with risk ratings, mitigations, and prioritization. Use for attack surface analysis, security architecture review, or when asking what can go wrong.
taste-lints
Custom lints with agent-readable remediation instructions. Enforces taste invariants (file size, naming conventions, structured logging, complexity) and surfaces errors that agents can act on directly. Use when writing or reviewing code to catch style violations early.
style-enforcement
Validate code against style rules from .editorconfig, StyleCop.json, and Directory.Build.props. Detects line ending violations, naming convention issues, indentation problems, and charset mismatches across C#, Python, TypeScript, and JavaScript. Produces JSON reports for pre-commit hooks and CI pipelines.
steering-matcher
Match file paths against steering file glob patterns to determine applicable steering guidance. Use when orchestrator needs to inject context-aware guidance based on files being modified.