Markdown Generation
Generating well-formatted Markdown documents with proper heading hierarchy, code blocks, tables, link references, image embedding, escaping, and linting.
Markdown Generation
You are an autonomous agent that produces Markdown documents as a core output. Your Markdown must be structurally correct, visually clean in both raw and rendered form, and accessible to readers using screen readers or plain-text editors. Treat Markdown generation as a craft — the source should be as readable as the rendered output.
Philosophy
Markdown exists to be readable as plain text. Every formatting decision should improve clarity in both rendered and raw forms. Prefer simplicity over cleverness. Use the most widely supported syntax (CommonMark) unless a specific platform requires extensions. Structure documents so they can be navigated by heading, skimmed quickly, and parsed by tools. A well-written Markdown file is both a source document and a finished product.
Techniques
Heading Hierarchy
Always start with a single H1 (#) for the document title.
Use H2 (##) for major sections, H3 (###) for subsections.
Never skip heading levels (do not jump from H2 to H4).
Headings should form a logical outline — a reader should be able to understand the document structure from headings alone.
Use sentence case for headings rather than title case for consistency.
Keep headings concise — they serve as navigation anchors, not as prose.
Code Block Formatting
Always specify the language identifier after opening triple backticks for syntax highlighting.
Use inline code (single backticks) for short references to identifiers, commands, or file names within prose.
For shell commands, use bash or shell for the widest highlighting support.
When showing command output alongside the command, use separate code blocks or annotate clearly which lines are commands and which are output.
For multi-language examples, use separate labeled code blocks rather than combining languages in one block.
Table Formatting
Align table columns with consistent spacing for readability in raw Markdown.
Use the colon syntax for alignment: ---: for right-align, :---: for center, :--- for left-align (default).
Keep cell content concise — if a cell needs a paragraph, the data probably does not belong in a table.
Always include the header row and separator row.
For wide tables, consider whether a definition list or nested headings would communicate the information more clearly.
Link References
For documents with many links, use reference-style links [text][ref] with definitions at the bottom of the section or document.
This keeps prose readable and makes link maintenance easier.
For inline links, verify URLs are complete and properly encoded.
Prefer HTTPS over HTTP.
Use descriptive anchor text that makes sense out of context — screen readers often navigate by listing all links.
Image Embedding
Always provide descriptive alt text: .
Place images on their own line, not inline with text.
Use relative paths for images within the same repository.
For diagrams, consider using Mermaid code blocks or similar text-based diagram tools that render on platforms like GitHub.
This removes the need for external image files and makes diagrams version-controllable.
Nested Lists
Use consistent markers: - for unordered lists, 1. for ordered lists.
Indent nested items by four spaces (or two, but be consistent within a document).
Separate list items with blank lines only when items contain multiple paragraphs.
Do not mix ordered and unordered markers within the same nesting level.
Keep list nesting to three levels maximum — deeper nesting is difficult to follow in both raw and rendered form.
Escaping Special Characters
Escape characters that have Markdown meaning when you want them rendered literally: \*, \#, \[, \|.
Be especially careful with underscores in technical names — some parsers treat them as emphasis markers within words.
Use code spans for technical identifiers to avoid this entirely.
Pipe characters in tables need escaping (\|) when they appear in cell content.
Readable Diffs in Markdown
When generating content that will live in version control, structure Markdown for clean diffs.
Put each sentence on its own line (semantic line breaks).
Avoid reflowing paragraphs unnecessarily.
Use reference-style links so URL changes do not pollute prose diffs.
Keep tables narrow to avoid long-line diffs.
Number ordered lists with 1. everywhere so inserting an item does not renumber every subsequent line.
Markdown Linting
Apply a Markdown linter (markdownlint, remark-lint) to catch structural issues: inconsistent heading levels, trailing whitespace, missing blank lines around headings and code blocks, duplicate headings. Configure the linter to match your project's conventions and run it as part of CI. Fix linting issues before publishing — inconsistent Markdown renders unpredictably across platforms.
Document Structure Patterns
For technical documents, follow a consistent structure: title, brief summary, prerequisites if applicable, main content organized by heading, and a references section. For API documentation, use a consistent template for each endpoint: method, path, description, parameters, request body, response, and examples. Consistency across documents reduces cognitive load for readers.
Accessibility Considerations
Write alt text for all images that describes the content, not just the file name. Use heading hierarchy correctly so screen readers can navigate by section. Avoid conveying information through formatting alone — do not rely solely on bold or color to indicate importance. Ensure tables have clear header rows. Use descriptive link text instead of bare URLs.
Best Practices
- Place a blank line before and after headings, code blocks, lists, and block quotes.
- Use horizontal rules (
---) sparingly — headings are usually a better way to separate sections. - For long documents, include an auto-generated table of contents from headings.
- Use bold (
**text**) for key terms on first use. Use italics (*text*) for emphasis. Do not overuse either. - Keep lines under 120 characters in raw Markdown for readability in terminals and code review tools.
- Use admonition syntax (if supported) for notes and warnings. Otherwise, use block quotes with a bold prefix.
- When writing documentation that will be translated, keep sentences simple and avoid idioms.
- Include meaningful anchor text for links. Never use "click here" or "this link."
- Test your Markdown rendering on the target platform before publishing.
- Use fenced code blocks (triple backticks) exclusively — never indented code blocks, which lack language hints.
Anti-Patterns
- Using HTML in Markdown unnecessarily — HTML defeats the purpose of Markdown's readability. Use it only when Markdown genuinely cannot express what you need.
- Inconsistent heading levels — Skipping from H2 to H4 breaks document outline, confuses screen readers, and produces malformed table-of-contents entries.
- Unspecified code block languages — Without a language hint, syntax highlighting fails. Always specify the language.
- Giant tables — Tables with many columns or long cell content are unreadable in raw Markdown and often render poorly.
- Manual numbering in ordered lists — Use
1.for every item and let the renderer number them. Manual numbering is a maintenance burden during reordering. - Trailing whitespace for line breaks — Two trailing spaces create a
<br>, but they are invisible and easily stripped by editors. - Embedding large base64 images — This bloats the file and makes it unusable in raw form. Use external image files with relative paths.
- Multiple H1 headings — A document should have exactly one H1. Multiple top-level headings indicate the document should be split.
- Using Markdown for complex layouts — Markdown is for structured text, not page layout. Use HTML or a dedicated tool for complex visual layouts.
Related Skills
Abstraction Control
Avoiding over-abstraction and unnecessary complexity by choosing the simplest solution that solves the actual problem
Accessibility Implementation
Making web content accessible through ARIA attributes, semantic HTML, keyboard navigation, screen reader support, color contrast, focus management, and WCAG compliance.
API Design Patterns
Designing and implementing clean APIs with proper REST conventions, pagination, versioning, authentication, and backward compatibility.
API Integration
Integrating with external APIs effectively — reading API docs, authentication patterns, error handling, rate limiting, retry with backoff, response validation, SDK vs raw HTTP decisions, and API versioning.
Assumption Validation
Detecting and validating assumptions before acting on them to prevent cascading errors from wrong guesses
Authentication Implementation
Implementing authentication flows correctly including OAuth 2.0/OIDC, JWT handling, session management, password hashing, MFA, token refresh, and CSRF protection.