Skip to content

Fenced code indented 1–3 spaces is parsed as prose in preview and HTML export #1

Closed

Description

@BinaryOutlook

Fenced blocks with one to three leading spaces are parsed as prose in the visual editor and HTML export preparation. The failure occurs with an omitted language, a recognized language, plaintext, and an unknown language.

Validated on main at d50e1fd1ad080fadf416098a582fe0a277d1ad43 (package version 0.2.1), 2026-09-16 UTC. Environment: macOS 26.5.2, arm64.

Reproduction

Open this synthetic Markdown in visual preview, or enter it in source mode and switch to preview. Each fence and content line below begins with three ASCII spaces:

   ```
   alpha
   beta
   ```

Expected: one unhighlighted code block containing alpha and beta on separate lines. CommonMark permits indented fences and an optional info string.

Observed: zero code blocks; the backticks and body become ordinary paragraphs. Adding a language does not fix this. Removing the three leading spaces creates the expected block.

Leading spaces Languages tested Code blocks in preview
0 omitted, java, plaintext, unknown 1
1, 2, or 3 same four cases 0

HTML export preparation reproduces the same distinction. Another consequence is that math-looking text inside a missed fence can be interpreted as math instead of literal code. The command text is not generally deleted; its code-block structure is lost.

Cause and suggested scope

The fence matcher only accepts column-one fences. The existing plain-text highlighting fallback works.

Recognize valid leading spaces and track opening indentation so that only that indentation is removed from content. Preserve deeper indentation, tabs, blank lines, fence-length/type rules, copy behavior, and math/Mermaid handling. Avoid unrestricted whitespace trimming. List containment needs separate attention; recognizing an indented fence alone does not restore the editor's existing list-continuation behavior.

Validation boundary

Reproduced in Chromium using the production webview generator, styles, scripts, and source-mode handler. VS Code messaging/clipboard boundaries were mocked; this was not an installed-extension run. The failure persists with all vendor JavaScript disabled, while column-one code still renders. No JavaScript exceptions occurred in those controls. This report uses synthetic content only.

Activity

  1. added
    bug
    on Sep 16, 2026
  2. added a commit that references this issue on Sep 17, 2026
    74bd061
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions