Skip to content

fix(mirror): keep decorating blocks after a math block - #13742

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/mirror-math-block-decoration
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/mirror-math-block-decoration

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

After a math block, the Markdown mirror writes every later block of the page without its task status and tags.

Example: a page with a math block followed by a task after tagged #Next mirrors as

- $$
  E = mc^2
  $$
- after

instead of - TODO after #Next.

Cause

frontend.worker.markdown-mirror/decorate-rendered-content walks the rendered lines and matches each block line to the next block (rendered-line-matches-block?) to add its status marker and tags. A code block is matched by its fence (```) and the lines inside the fence are skipped. A math block is matched by its first title line (E = mc^2), but its rendered first line is - $$, so it never matches; every later block is compared with the math block's info and none of them is decorated. A line inside a math block starting with - would also be taken for a block.

Fix

A block's line info carries its fence: ``` for a code block, $$ for a math block (by display type or tag). A fenced block is matched by its fence, and the lines up to the closing fence are skipped, the same for both.

Test

page-mirror-decorates-blocks-after-a-math-block-test in frontend.worker.markdown-mirror-test: a math block whose formula has a - x line, then a task with a tag. Fails on master (the task loses TODO and #Next), passes with the fix. The other mirror tests pass.

Found by fuzzing the Markdown mirror through the Markdown importer.

The line matcher compared a math block's first title line with its rendered first line, which is the $$ fence, so it never matched and every later block lost its status marker and tags. A math block is matched by its fence, like a code block, and the lines inside the fence are skipped.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Closing: this patches one symptom of a design problem, logseq/db-test#1442 (a block's body is a Markdown string sharing one grammar with every text format). The bug is listed there; the fix is the design, not this patch.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 17, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 20, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
@yuxi-liu-wired
yuxi-liu-wired deleted the fix/mirror-math-block-decoration branch October 21, 2026 18:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 23, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 26, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 27, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 28, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 29, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 29, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 1, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 2, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 4, 2026
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
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.

1 participant