fix: render latex-only block refs instead of empty chips by tiensonqin · Pull Request #13157 · logseq/logseq · GitHub
Skip to content

fix: render latex-only block refs instead of empty chips - #13157

Open
tiensonqin wants to merge 2 commits into
masterfrom
logseq/fix-latex-only-block-ref-9b5a
Open

fix: render latex-only block refs instead of empty chips#13157
tiensonqin wants to merge 2 commits into
masterfrom
logseq/fix-latex-only-block-ref-9b5a

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes empty [[ ]] chips when a DB graph references a block whose entire content is display LaTeX.

Related: logseq/db-test#1137

Same failure class as the closed stale db-test#687; this does not merge into #687.

What changed

A DB [[uuid]] page-ref chip renders block-title from heading ast-title only. Standalone $$…$$ parses as Displayed_Math in ast-body, so the chip had no title while :block/title was still non-blank — brackets rendered around nothing. Converted Math-blocks hit the same chip via [:div.math-block] inside inline a.page-ref.

The chip now renders the formula inline for:

  • unconverted latex-only titles ($$ x^2 + y^2 = z^2 $$)
  • Math-block display-type titles

Mixed-title blocks such as Pythagoras: $$ x^2 + y^2 = z^2 $$ still use the heading title.

Tests

  • frontend.format.block-test — latex-only vs mixed-title parse-title-and-body / formula extraction
  • frontend.components.block.page-ref-math-test — page-ref chips for latex-only, Math-block, and mixed-title control
  • Also green: frontend.handler.db-based.editor-test, frontend.components.block.breadcrumb-model-test, frontend.handler.paste-test
Ran 13 tests containing 50 assertions.
0 failures, 0 errors.

Page-ref chips now include the formula

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

DB page-ref chips only map heading ast-title, so a $$...$$ block
(or a Math-block display-type) drew empty [[]]. Show the formula
inline in the chip and keep mixed-title latex titles unchanged.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new page-ref math extraction currently walks the entire AST via tree-seq on the render path, which is avoidable and may regress performance when many page-ref chips render blocks with empty titles but large bodies (e.g. code blocks).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes DB-mode block-reference page-ref chips rendering as empty [[ ]] when the referenced block’s title is entirely display LaTeX (or a converted Math-block), by rendering the formula inline instead of relying solely on ast-title.

Changes:

  • Add displayed-math-formula helper to extract formulas from standalone $$…$$ titles.
  • Update block-title/page-ref rendering to show inline KaTeX for latex-only titles and :math display-type blocks.
  • Add targeted CLJS tests plus page-ref-specific CSS tweaks to ensure inline rendering behaves correctly.
File summaries
File Description
src/main/frontend/format/block.cljs Adds a helper to extract the inner formula from standalone display-math titles.
src/main/frontend/components/block.cljs Renders inline formula content for page-ref chips when the normal title AST is empty (latex-only / math-block cases).
src/main/frontend/components/block.css Adjusts .page-ref math/KaTeX styles so inline formula chips don’t render as full-width blocks.
src/test/frontend/format/block_test.cljs Adds unit tests for parsing/extracting latex-only vs mixed titles.
src/test/frontend/components/block/page_ref_math_test.cljs Adds rendering tests ensuring page-ref chips include formulas and don’t produce empty [[ ]].
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +2405 to +2411
Trim Displayed_Math body text in parse assertions and use referred
format.block helpers so kondo stays clean.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants