Skip to content

Markdown viewer: support <sub>/<sup> subscript and superscript #13734

Open

Description

@fbartho

Pre-submit Checks

Describe the solution you'd like?

Warp's Markdown Viewer should render <sub> and <sup> with a vertical baseline offset (and typically reduced font size), matching the standard subscript/superscript treatment. Markdown has no native syntax for either, so raw HTML is the only way authors express them.

Expected behavior: <sub>2</sub> renders as a subscripted "2"; <sup>1</sup> renders as a superscripted "1", both visually offset from the surrounding baseline text.

Is your feature request related to a problem? Please describe.

Subscript shows up in chemical formulas and variable notation; superscript shows up constantly for footnote markers and exponents. Both are common enough in technical docs that their absence is noticeable.

Concretely, today in Warp's Markdown Viewer (verified on this build):

Screenshot showing that sub/sup elements render as raw code

The raw <sub>/<sup> tags and their contents render as plain literal text at baseline, with no vertical offset.

Additional context

Test case:

# `<sub>`/`<sup>`

Should render: a chemical formula with a properly subscripted number, and a footnote-style superscript marker. Currently: expect the raw tags and their contents to render as plain literal text at baseline, with no vertical offset.

Water is H<sub>2</sub>O, and carbon dioxide is CO<sub>2</sub>.

This claim needs a citation<sup>1</sup>.

<sup>1</sup> Source: internal benchmark, 2026.

Code pointers. As far as I can tell:

  • Neither tag appears in PHRASING_ELEMENT_TAGS (crates/markdown_parser/src/html_parser.rs), and the paste-path styling match arm no-ops on unknown tags — there's an adjacent TODO in that same match arm noting more phrasing styling is needed generally, so this gap looks known rather than deliberately excluded.
  • Neither tag has any handling in markdown_parser.rs either.
  • This one looks like more than a parser tweak: FormattedTextStyles (the shared style struct in crates/markdown_parser/src/lib.rs) has no vertical-offset/baseline-shift/font-scale field at all, so supporting <sub>/<sup> needs a small content-model addition before the parser and renderer have anything to plug into.

Related: this splits out one tag from #13652 (bulk raw-HTML-subset request). Sibling issues from the same split: #13721 (<img> sizing), #13725 (anchor links), #13726 (raw HTML tables), #10259 (<details>/<summary> — pre-existing request), #13732 (<br>), #13733 (<kbd>), #13735 (align on <p>/<div>), #13736 (<picture>/<source>)

Operating system (OS)

macOS

How important is this feature to you?

3

Warp Internal (ignore) - linear-label:39cc6478-1249-4ee7-950b-c428edfeecd1

No response

Activity

  1. added
    enhancement
    on Jul 14, 2026
  2. warp-for-oss commented on Jul 14, 2026

    @warp-for-oss
    Contributor

    @fbartho

    Here's what I found while triaging this issue:

    This looks like a confirmed Markdown Viewer feature gap rather than a macOS-specific issue. The supplied markdown example should be enough for maintainers to reproduce the current baseline/literal rendering behavior.

    Maintainer details

    I concluded that markdown Viewer does not currently support baseline-shifted rendering for raw HTML / tags, so chemical formula and footnote/exponent notation render as literal baseline text..

    Triage summary

    This is a well-scoped enhancement request for Markdown Viewer raw-HTML inline rendering. The provided test case should reproduce reliably: H<sub>2</sub>O and citation<sup>1</sup> currently have no supported path to become baseline-shifted, smaller inline fragments.

    The likely implementation gap is in the shared markdown/formatted-text pipeline rather than macOS-specific rendering. crates/markdown_parser/src/markdown_parser.rs only recognizes a narrow inline HTML-like special case for underline tags; other raw HTML tags are parsed as literal text. crates/markdown_parser/src/html_parser.rs also omits sub and sup from the phrasing element allowlist and style mapping used by HTML parsing/paste flows. The shared FormattedTextStyles model in crates/markdown_parser/src/lib.rs, plus conversions in crates/editor/src/content/text.rs and rendering in crates/warpui_core/src/elements/gui/formatted_text_element.rs, currently has no baseline-shift/font-scale field for subscript or superscript.

    Duplicate scan: I fetched all open issues and recent closed issues. The only close related issue is recently closed #13652, which this report explicitly splits out from; there were not two or more existing likely duplicates, so this should remain a standalone enhancement.

    This is my automated analysis and may be incorrect. A maintainer will verify the details.

    Powered by Oz

  3. added
    area:editor-notebooks
    repro:high
    triaged
    on Jul 14, 2026
  4. removed their assignment
    on Jul 17, 2026
  5. added
    ready-to-implement
    on Jul 17, 2026
  6. warp-for-oss commented on Jul 17, 2026

    @warp-for-oss
    Contributor

    This issue has been labeled ready-to-implement and is open for contributions involving code changes. If you'd like to tackle it, feel free to open a pull request against this issue. You can also comment @oz-agent on this issue to have the bot draft an implementation PR automatically.

  7. fbartho commented on Jul 19, 2026

    @fbartho
    ContributorAuthor

    Out of scope for the current implementation — documenting the future direction:

    Browsers render nested <sup>/<sub> cumulatively: x<sup>a<sup>b</sup></sup> raises "b"
    higher than "a" (a second baseline shift stacked on the first), and each level of nesting
    gets progressively smaller/higher (or lower) type — matching how nested exponents or
    multi-level subscripts read in math notation. Math markup like this is not uncommon in
    Markdown on GitHub and elsewhere (READMEs, academic/scientific project docs, formula-heavy
    issue threads), so this isn't a hypothetical edge case — it's a real gap, just not the one
    this slice's fix addresses.

    Current behavior (as shipped)

    Any nesting of <sub>/<sup> — same direction (<sup> inside <sup>), opposite direction
    (<sub> inside <sup> or vice versa), or depth ≥ 2 — bails the entire outermost span
    (open tag through close tag, all contents, including nested tags) to plain literal source
    text. Only a single, non-nested <sub> or <sup> renders styled. This was a deliberate
    product ruling: two motivating cases showed that even a "reasonable" degraded rendering
    (flat collapse, or an innermost-wins tie) still produces a plausible-looking but factually
    wrong formula rather than an obviously broken one —

    • 2<sup>3<sup>4</sup></sup> (meant as 2^(3^4)) would flatten to a single superscript
      offset, rendering "34" raised — reading as 2^(34), a different number.
    • 2<sup>3<sub>4</sub></sup> (meant as 2^(3-sub-4)) under innermost-wins would render "4"
      at a full subscript depth measured from "2"'s own baseline, reading as (2³)₄ — again a
      different, wrong expression.

    Showing the whole span as source text avoids ever displaying a formula that looks valid but
    isn't what the author wrote.

    What browsers do

    • Baseline offset compounds additively per nesting level (each level's shift stacks on the
      outer level's shift, rather than replacing it).
    • Font size compounds multiplicatively per nesting level (matching how vertical-align: super/sub combined with the UA stylesheet's font-size reduction stacks under repeated
      nesting).
    • Opposite-direction nesting (<sub> inside <sup> or vice versa) partially cancels rather
      than the inner simply overriding the outer.

    Why deferred

    • Reasonable-markdown principle, applied honestly: the whole-formula bail is a
      deliberate MVP scope choice for THIS slice — it is not a claim that nested math notation
      is rare or unimportant enough to ignore forever. It's the safest thing to ship now (never
      wrong, sometimes plain) while the real fix (below) gets designed properly.
    • Single tri-state attribute in the buffer model: vertical_align (Option<VerticalAlign>
      — None/Sub/Sup) is a flat tri-state throughout the buffer summary, the CoreText
      attribute round-trip, and the paint path. None of these layers have a concept of nesting
      depth or a stack of offsets today. Supporting compounding is a data-model change touching
      every one of those layers, not a tweak to a tie-rule, and shouldn't be scoped into this
      bug-fix pass.

    What the buffer/style model would need

    • Replace Option<VerticalAlign> with a representation that can carry a signed depth (e.g.
      i8, positive for superscript levels, negative for subscript levels, opposite-direction
      nesting partially cancelling) at each of: TextStyle/StyleAndFont (paint input),
      StyledBufferRun.text_styles (render iterator output), StyleSummary (the sum-tree
      summary — the depth-tracking counters already present for subscript_counter/
      superscript_counter are the natural basis for this, since they already count net opens
      minus closes), and the CoreText attribute round-trip (currently a 2-value enum encoding;
      would need to carry a signed integer instead).
    • Paint path (crates/warpui/src/platform/mac/text_layout.rs and the winit-shaper
      equivalent) needs a per-depth baseline-offset and font-scale formula instead of the current
      single fixed offset/scale pair, and needs to verify line-height/clipping still holds at
      multiple nesting levels (the original tech spec flagged single-level clipping as a spike
      risk; multi-level compounds that risk further).
    • The parser-level whole-formula bail (crates/markdown_parser/src/markdown_parser.rs,
      parse_vertical_align/Delimiter::vertical_align_poisoned) would need to be replaced with
      actual depth-tracking at parse time, rather than detecting nesting and refusing to style it.
    • Serializer round-trip (Markdown/HTML export) already emits nested <sub>/<sup> tags
      faithfully at the source level today (the flattening/bail is a rendering-only limitation,
      not a content-model loss) — confirm this remains true once the internal representation
      gains a depth field, so export doesn't regress.

    Related: #13912 (the analogous depth-aware follow-up for nested <kbd>, same rationale and
    deferral shape — every inline style in the current content model is a flat boolean/tri-state,
    and depth-aware nesting would be the first genuinely nesting-aware inline style in the
    pipeline for either feature).

    (If the line-based rendering model is ever reworked to support this kind of cumulative composition, text flowing around aligned block images likely ranks ahead of exponent towers as the first consumer of that rework.)

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

    area:editor-notebooksenhancementready-to-implementrepro:hightriagedwarp:auto-triage-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions