# Escape Markdown punctuation without damaging examples

Canonical: https://githtml.com/guides/markdown-escape-literal-formatting
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Escape punctuation only where Markdown is interpreting it as formatting you do not intend. Use inline code for short literal tokens and fenced blocks for complete examples. Avoid escaping the entire document: the right fix depends on whether the character appears in prose, a link, a table, or a code example.

## Locate the parser context before adding backslashes

Asterisks around a product name, brackets in a placeholder, and a leading number followed by a period can all be intentional text. The same character can also be structural syntax. Find the smallest example that reproduces the unwanted formatting and identify its context. Is it ordinary prose, the beginning of a line, a table cell, or already inside code? Do not copy an escape technique from one context into every other context. Start with a scratch sentence and the target renderer. This prevents a simple literal-character problem from becoming a document full of distracting backslashes and broken links.

## Choose the representation that fits the reader's task

Use a targeted backslash escape when the punctuation is part of ordinary prose. Use inline code when the reader needs the exact token, such as a filename or pattern. Use a fenced block when preserving a complete source example matters. The sample shows the same asterisked word as prose and as a literal token. Avoid typographic substitutions that only resemble the original characters: a reader copying a regular expression or command needs the real syntax. If a placeholder uses angle brackets, explain whether those brackets are literal or must be replaced, rather than relying on appearance to communicate that distinction.

````markdown
The literal label is \*preview\*.

The exact token is `*preview*`.
````

## Check what survives rendering and copying

Preview the corrected paragraph and copy the relevant text into a plain-text buffer. Confirm both that unintended emphasis is gone and that the intended characters remain. Then run the project's formatter and repeat the comparison. Watch for a fix that works in GitHub but changes under an exporter with different extensions enabled. Keep escapes local and documented when they are surprising. A reviewer should understand why a backslash exists without having to reverse engineer the whole page. If several paragraphs need complex escaping, reconsider the presentation: a dedicated example with an explanatory caption may communicate the same information more clearly.

1. Reduce the failure to one sentence and identify whether the punctuation is prose or a literal token.
2. Use the smallest targeted escape and verify the copied result, not just the preview.
3. Recheck after formatting and conversion, especially when another parser consumes the same source.
4. Keep a before-and-after fixture for unusual syntax so future cleanup does not remove an intentional escape.

## Sources and further reading

- [CommonMark specification](https://spec.commonmark.org/0.31.2/)
- [GitHub Docs: Basic writing and formatting syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)

## Related guides

- [Write Markdown footnotes that stay connected to their claims](https://githtml.com/guides/markdown-footnote-reference-maintenance)
- [Understand Markdown front matter before copying a document](https://githtml.com/guides/markdown-frontmatter-versus-body)
- [Put a literal backtick inside Markdown inline code](https://githtml.com/guides/markdown-inline-code-containing-backticks)
- [Markdown line breaks: choose a new line or a new paragraph](https://githtml.com/guides/markdown-line-breaks-versus-paragraphs)

Editorial approach: https://githtml.com/guides/about
