Index  Decision Records ISSUE-180: Inline Code Spans Not Recognised

ISSUE-180: Inline Code Spans Not Recognised

1 Status

Date Status
21-05-2026 Proposed
21-05-2026 Accepted
21-05-2026 In-Progress
22-05-2026 Implemented

2 Context

While reviewing the rendered HTML of issue-179-emphasis-flanking-rule, it was observed that text wrapped in single backticks was not rendered as inline code. In the source, the paragraph contained <i>…</i> wrapped in single backticks — intended to display the literal HTML tags. The rendered page instead showed the body italicised and the <i> tags missing, because the backticks were emitted as literal characters and the browser interpreted the <i>…</i> content between them as actual italic markup.

Two facts about the parser explain this:

  1. doc_parser.rb:292 handles fenced code blocks (lines starting with three consecutive backticks) at the line level, but there is no corresponding handling for inline (single-backtick) code spans.
  2. text_line.rb:57 (TextLineParser) registers tokens for *, **, ***, (, ), [, ], ]( — but not for the backtick. Backticks therefore fell into the literal-character branch of the tokenizer and were emitted verbatim into the HTML output, along with anything between them.

This is a real authoring trap: any decision record, requirement, or test step that documents a piece of HTML, an XML tag, or an entity reference would have the inner content silently re-interpreted by the browser.

3 Decision

Add inline code-span support to the text-line tokenizer.

3.1 Tokenisation

Introduce a BacktickToken (whose value is the backtick character itself) registered in TextLineParser#supported_tokens. After the main token-emission loop, run a second pass (fuse_backticks) that walks the token list, pairs consecutive BacktickToken instances, and replaces each opener/content/closer triple with a single InlineCodeToken whose value is the raw content between the backticks. An unmatched BacktickToken (no closer found) is converted to a literal backtick character.

This second pass runs before any emphasis matching in restore, so a code span fully shadows whatever other markers it contains: when the source places *foo* inside a single-backtick code span, the rendered HTML preserves the literal asterisks rather than wrapping foo in <i> tags. The raw content is reconstructed by concatenating the value of each token between the two backticks, which is straightforward because every token in the token stream carries its source-level text in value.

3.2 Rendering

Extend TextLineBuilderContext with a default inline_code(str) method that returns the raw string. The active TextLine subclass overrides it to:

Escaping is performed at the rendering layer, not the parser, to keep concerns separated. The tokenizer stays HTML-agnostic.

3.3 Coverage of existing cases

<i>…</i> between backticks renders as <code>&lt;i&gt;…&lt;/i&gt;</code>. A & B renders as <code>A &amp; B</code>. Asterisks, brackets, and other emphasis markers inside backticks remain literal.

4 Scope

Item Status Start Date Target Date Description
Code Done 21-05-2026 22-05-2026 Add BacktickToken and InlineCodeToken classes in text_line.rb; register the backtick token; add fuse_backticks and next_backtick_index helpers called at the end of tokenize; add InlineCodeToken case in TextLineBuilder#restore; add inline_code to TextLineBuilderContext and TextLine (the latter HTML-escapes via CGI.escapeHTML and wraps in <code> tags); require 'cgi' at the top of the file
Tests Done 21-05-2026 22-05-2026 Seven new unit tests in text_line_spec.rb covering: a basic foo() code span, HTML escaping of < and > inside backticks, ampersand escaping, emphasis markers inside a code span staying literal, two code spans on the same line, an unmatched single backtick rendered as a literal character, and code-span followed by an italic span

5 Out of Scope

6 Consequences

6.1 Positive

6.2 Negative

6.3 Neutral

7 Alternatives Considered

8 Software Versions

Software Version Category Software Version ID
Latest Released Version 0.3.1
Issue Found in Version 0.4.0
Target Release Version 0.4.0

9 References

10 Review Evidences