AGENT SKILL

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
所属仓库
loriensleafs/brain
最近更新
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

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., ```python instead 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:

  1. Detect opening fence: Line matches the opening pattern below outside a block. Record indent level and enter "inside block" state.
  2. Detect malformed closing fence: While inside a block, line matches the malformed closing pattern below. Insert a proper closing fence before this line.
  3. 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 diff shows 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:

  1. Always use plain ``` for closing fences
  2. Never copy the opening fence line to close
  3. 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>

  1. Nested indentation: Preserves indent level from opening fence
  2. Multiple consecutive blocks: Each block tracked independently
  3. File ending inside block: Automatically closes unclosed blocks
  4. Mixed line endings: Accepts both \n and \r\n as input (normalizes output to \n)

</details>

04 同仓库更多 Skills

loriensleafs
loriensleafs/brain

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.

★ 0
loriensleafs
loriensleafs/brain

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.

★ 0
loriensleafs
loriensleafs/brain

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.

★ 0
loriensleafs
loriensleafs/brain

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.

Skill与智能体开发
★ 0
loriensleafs
loriensleafs/brain

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.

★ 0
loriensleafs
loriensleafs/brain

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.

★ 0