Skip to content

fix: Obsidian table paste crash and glued-prose stray row (#16)#17

Merged
martin-papy merged 4 commits into
developfrom
bugfix-16-table-paste-crash
Jun 5, 2026
Merged

fix: Obsidian table paste crash and glued-prose stray row (#16)#17
martin-papy merged 4 commits into
developfrom
bugfix-16-table-paste-crash

Conversation

@martin-papy

@martin-papy martin-papy commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Fixes #16.

Pasting an Obsidian table into a Foundry journal threw TypeError: Cannot read properties of null and, separately, glued a following note line into the table as a stray cell. Two distinct root causes, two commits.

1. The crash — insert.js

convert() produced valid HTML; the exception came from ProseMirror's slice fitter in insertHtml. Foundry classifies any table with a <thead> (every GFM table from marked) as an isolating "complex" table. When the parsed slice is [isolating table, paragraph] — a table followed by a paragraph — fitting the open slice end past the isolating boundary dereferences null and throws.

insertHtml now tries the open-slice replaceSelection first (open ends let pasted inline content merge with surrounding text — the nicer result for most pastes) and, only on a fitter crash, falls back to parsing a full document and inserting fully-closed content via replaceWith. Building a transform doesn't mutate state — only dispatch does — so the try/catch is safe.

Reproduced and verified against the real prosemirror-tables fitter driven by Foundry v13's actual table schema: every currently-working case keeps the original slice path; only the crashing cases take the fallback.

2. Stray row — obsidian.js

GFM and marked absorb a pipe-less line directly after table rows as a trailing single-cell row, so *Digested from LoDP pg. 39.* placed right under the table became a stray <td>. Obsidian and Typora end the table there instead.

New isolateTables() in the Obsidian layer inserts a blank line between a table's last row and a following non-blank, pipe-less line so it parses as its own block. Wired into convert() after stripWikiLinks (wikilink pipes are already gone) and gated by the existing obsidian option.

Tests

  • New tests/insert.test.js (first unit test for insert.js): happy-path + Cannot Parse Error When Pasting from Obsidian #16 regression for the fitter-crash fallback.
  • 6 isolateTables unit tests + 1 convert integration test asserting the note renders as <p>, not <td>.
  • Full suite: 108/108 passing, lint clean.

Test plan

  • npm test green (108 tests)
  • eslint clean on changed files
  • Issue Cannot Parse Error When Pasting from Obsidian #16 markdown converts with no crash and no stray row (verified end-to-end)
  • Manual smoke test: paste the issue's table into a v13 Journal page editor

🤖 Generated with Claude Code

martin-papy and others added 2 commits June 5, 2026 07:29
Pasting an Obsidian table followed by a paragraph threw
"TypeError: Cannot read properties of null" from ProseMirror's slice
fitter. Foundry treats any table with a <thead> (every GFM table from
marked) as an isolating "complex" table; fitting an open slice of
[isolating table, paragraph] past the isolating boundary dereferences
null.

insertHtml now tries the open-slice replaceSelection first (preserving
inline-merge behavior) and, only on a fitter crash, falls back to
parsing a full document and inserting fully-closed content via
replaceWith. Building the transform does not mutate state, so the
try/catch is safe.

Adds tests/insert.test.js (first unit test for insert.js) with a
happy-path and an issue #16 regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
GFM and marked absorb a pipe-less line directly after table rows as a
trailing single-cell row, so a note like "*Digested from ...*" placed
right under a table became a stray table cell. Obsidian and Typora end
the table at that line instead.

Add isolateTables() to the Obsidian layer: when a table's last row is
immediately followed by a non-blank, pipe-less line, insert a blank line
so it parses as its own block. Wired into convert() after stripWikiLinks
(so wikilink pipes are already gone) and gated by the existing obsidian
option.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@martin-papy, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 32 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7dc86661-db62-4d0a-99c1-b2e86450288b

📥 Commits

Reviewing files that changed from the base of the PR and between ac042b8 and acdba29.

⛔ Files ignored due to path filters (4)
  • CHANGELOG.md is excluded by !**/*.md and included by **/*
  • tests/convert.test.js is excluded by !**/tests/** and included by **/*
  • tests/insert.test.js is excluded by !**/tests/** and included by **/*
  • tests/obsidian.test.js is excluded by !**/tests/** and included by **/*
📒 Files selected for processing (3)
  • scripts/convert.js
  • scripts/insert.js
  • scripts/obsidian.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix-16-table-paste-crash

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

martin-papy and others added 2 commits June 5, 2026 07:36
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@martin-papy martin-papy linked an issue Jun 5, 2026 that may be closed by this pull request
@martin-papy martin-papy merged commit 2525675 into develop Jun 5, 2026
3 checks passed
@martin-papy martin-papy deleted the bugfix-16-table-paste-crash branch June 5, 2026 00:43
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.

Cannot Parse Error When Pasting from Obsidian

1 participant