Skip to content

fix(cells): render inline code spans in cell text - #7

Open
yoava wants to merge 2 commits into
a269ch:release/0.1.2from
yoava:fix/cell-code-spans
Open

yoava wants to merge 2 commits into
a269ch:release/0.1.2from
yoava:fix/cell-code-spans

Conversation

@yoava

@yoava yoava commented Oct 18, 2026

Copy link
Copy Markdown

Problem

Inline code in a table cell is lost:

  • Reading view / Live Preview tables: Obsidian renders `code` as <code>, and the cell's textContent drops the backticks. The cell parser only recognizes links, so the code shows as plain text.
  • Editing such a cell writes it back without the backticks, removing the code formatting from the note.
  • ```table blocks: cells come from the raw Markdown, so the backticks show literally.

Fix

  • link-renderer.ts parses CommonMark code spans (backtick runs of matching length, escaped backticks, one space stripped from each side, line endings as spaces). A link that starts first keeps any code span inside its label.
  • toPlainText flattens code to its text, so reconcileRows matches the source cell and keeps its backticks.
  • Sort, filter, column type inference, Kanban grouping and number display read the text without backticks, so `Done` groups with Done and `42` still counts as a number.
  • Code renders as <span class="ms-cell-code">, styled with Obsidian's inline-code variables.

Open question: span vs code

The grid is built inside a markdown post processor, so post processors that run later (Dataview at order 100, for example) process its elements. A real <code> would let Dataview inline queries (= ..., $= ...) and Meta Bind inputs run on cell text. Before this change they never ran, because the code was lost. The span keeps that behavior and looks the same. If you'd rather match native tables, switching to <code> is a one-line change in renderTextWithLinks.

Tests

npx vitest run: 348 passed. New cases cover code-span parsing, links with code in the label, stripCodeSpans, source reconciliation in the post processor, and code-aware sort and filter.

🤖 Generated with Claude Code

Cells lost inline code: the renderer flattens a code span to its text, and
the cell parser only knew links, so a note's `code` showed as plain text and
an edited cell wrote it back without backticks. The parser now reads
CommonMark code spans (a link that starts first keeps them in its label),
the source cell is preferred because its flattened form matches, and sort,
filter, type inference and Kanban grouping read the flattened text.

Code renders as a styled span rather than a code element, so plugins that
act on inline code (Dataview queries, Meta Bind inputs) never run on cell
text, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@a269ch
a269ch changed the base branch from main to release/0.1.2 October 19, 2026 23:14
@a269ch a269ch added the bug Something isn't working label Oct 20, 2026
@a269ch

a269ch commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Hi @yoava! Thank you very much for contributing to TableBase and for improving inline code rendering in table cells. I am very glad that you decided to help make the project better.

Your contribution is greatly appreciated. I will leave the detailed contribution-format requirements in your other PR so we do not duplicate the same information here.

Comment thread src/core/table-state.ts
const rawHeader = table.headers[c] || "";
const columnCells = table.rows.map((r) => r.cells[c] || "");
// Types are read from the text a cell shows, so "`42`" is a number.
const columnCells = table.rows.map((r) => stripCodeSpans(r.cells[c] || ""));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the inline code work. Could we also normalize the value used by the type-specific renderers? This line strips code spans for type inference, but checkbox/date/select/multi-select rendering still receives the original raw value. For example, `[x]`, `2026-01-01`, or `Done` can be classified correctly while isCellChecked, date parsing, or tag parsing still sees the backticks.

Please consider using the normalized value for display parsing while retaining the original Markdown value for editing and persistence. Regression tests for these typed columns would help protect this behavior.

@a269ch a269ch self-assigned this Oct 22, 2026
@a269ch
a269ch force-pushed the release/0.1.2 branch 2 times, most recently from fc93874 to 9542798 Compare October 22, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants