Documents & OCRPractical guides

Fix Markdown preview layout: headings, list indentation and code fences

Markdown looks like plain text, but a space or unclosed code fence can change the structure of an entire document. Locate the source syntax first, then inspect the destination renderer. This guide follows a complete short note from source to preview and delivery rather than repeatedly adjusting the appearance of a screenshot.

code editor displaying react source code
Illustrative photo: Juanjo Jaramillo · Unsplash License

The practical answer

Start with a small sample that correctly renders headings, lists and fenced code, then restore real content section by section. This preview places rendered HTML in an iframe without script permission. It does not publish a webpage, export a PDF or guarantee matching layout on other platforms.

Check structure before visual styling

The CommonMark 0.31.2 specification defines basic structures including headings, lists and fenced code. A destination may add extensions and its own styles. “Correct here” and “correct on the target platform” require separate checks. This entry uses a Markdown parser to produce HTML for an isolated preview.

Save the original text before editing, change one thing and preview again. For study notes with references, preserve the chapter, page and version locator. Converting a document to Markdown should not remove its evidence trail.

A complete sample with three structures

This original note is an editorial example rather than a summary of external research. It has first- and second-level headings, two list items and a literal code block. The quoted identifier 0012 is example text. Copy the complete sample, including the closing fence, so the reference remains outside the code block.

  1. Open the Markdown preview, paste the sample into the original-text area and start processing.
  2. Check that Review notes is a first-level heading, Evidence is second-level and the two items form a list rather than ordinary dash-prefixed paragraphs.
  3. Confirm that item_id and status remain in a code block, 0012 retains its leading zeros and the final reference is outside the block.
  4. Replace one section with your real text, preserving blank lines and paired fences. Expand gradually. After changing the input, process again; an older preview does not verify the new text.

Original Markdown to paste into the tool

# Review notes

## Evidence

- Keep the source locator.
- Check the exported document.

```text
item_id: "0012"
status: pending
```

[CommonMark specification](https://spec.commonmark.org/0.31.2/)
This text checks markers, blank lines and literal code. It is not a command to execute.

Trace a symptom back to its source characters

Source checks for common layout failures
SymptomCheck firstObserve after fixing
The rest becomes codeA missing closing fenceLater paragraphs return to ordinary text
A heading still shows #Spacing after the marker; an enclosing code blockThe intended heading level appears
List content becomes codeIndentation accidentally forming codeCorrect item nesting and ownership
A link stays literalWhether it remains inside a code fenceA link outside code is recognized

For uncertain nesting, reduce the document to one item and its continuation. Restore additional levels only after that works, keeping other variables stable.

Source, rendered HTML and destination are different deliverables

Copying the result copies rendered HTML, rather than reconstructing Markdown source. Save the original text when you intend to edit Markdown later. Copy HTML only when you need it and check it in the destination. This entry does not host a website or publish a PDF.

A code block preserves literal example text; it does not establish that JSON, a formula or a command is valid. For CSV and JSON content, use the quote, newline and identifier checks to verify the data itself. Attractive formatting cannot replace parsing or a relevant test.

Save according to the intended use

Continue writing

Keep original Markdown, source references and the document version.

Publish on a platform

Check destination extensions and its link and image handling.

Provide a code example

Preserve literal text, then verify it with the relevant parser or test.

A sandbox does not make external images local

The iframe has an empty sandbox attribute and does not permit scripts. It may still request externally referenced images. Previewing is therefore not equivalent to offline use, and image requests can reach an outside service. Start with an image-free sample and handle sensitive material according to your organization’s rules.

Raw HTML, links, extension tables and destination platforms can receive different treatment. Unknown HTML is unnecessary for diagnosing ordinary layout failures. Do not assume a structure visible here will survive publishing. Factual accuracy, permissions and image provenance need their own review.

Replace “looks good” with explicit acceptance

Check before delivery

  • Heading levels match the intended sections; no fence consumes later text.
  • List ownership, literal code and identifiers are complete.
  • References retain locators and image-request boundaries are understood.
  • The source is saved and the complete document is checked on the destination platform.

Common questions

Why does a newline not create another paragraph?

An ordinary newline does not necessarily create a separate paragraph. Use blank lines for paragraphs and check the destination rules for a hard line break.

Why does copying the result give HTML?

The entry renders Markdown to HTML and copies that output. Save original Markdown for editing; review copied HTML where it will be used.

Can this directly publish a webpage or PDF?

This entry provides a sandboxed preview without hosting or PDF export. Publishing or printing requires a separate check of complete content, links and pagination.

Further reading & sources

Put the guide into practice

Open the relevant tool, preview the result and check your exported file.

Newer articles on this topic

Continue with a newer article that refers to this guide or explainer.

Related articles