Roam: Fix table conversion and code block formatting - #506
Conversation
Previously table markers were stripped (commented-out code) and table children rendered as plain bullet lists. This adds proper structural conversion: each row's linear first-child chain becomes table columns, with Roam markup scrubbed, pipes escaped, and uneven rows padded. Also adds CLAUDE.md and gitignores _DOCS/_gpt5_docs local dirs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Multi-line code blocks in Roam blocks (stored with \n in the string field) lost their indentation during import, breaking the bullet hierarchy in Obsidian. Three fixes: - Indent continuation lines of multi-line blocks to align with the bullet content level - Normalize code fences so opening/closing ``` are on separate lines - Strip Roam language tags (```javascript, ```python, etc.) from code fences since they cause rendering issues in list context Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
This PR duplicates a commit from #505. Please remove that commit from this PR so they can be reviewed and merged independently. |
|
|
||
| private async roamMarkupScrubber(graphFolder: string, attachmentsFolder: string, blockText: string, skipDownload: boolean = false): Promise<string> { | ||
| // Strip language tags from code blocks (```javascript\n → ```\n) | ||
| blockText = blockText.replace(codeBlockLangRe, '```\n'); |
There was a problem hiding this comment.
Why are these being stripped? Obsidian supports these.
| const linePrefix = isChild ? indent + '* ' : indent; | ||
| const continuationIndent = isChild ? indent + ' ' : indent; | ||
| const indented = scrubbed.contains('\n') | ||
| ? scrubbed.split('\n').map((line, i) => i === 0 ? line : continuationIndent + line).join('\n') |
There was a problem hiding this comment.
This should avoid prepending whitespace to blank lines. You also don't need to the check for newlines.
const indented = scrubbed
.split('\n')
.map((line, i) => (i === 0 || line === '') ? line : continuationIndent + line)
.join('\n');
|
|
||
| const blockRefRegex = /(?<=\(\()\b(.*?)\b(?=\)\))/g; | ||
| const roamTableRe = /^\{\{(\[\[)?table(\]\])?\}\}$/i; | ||
| const codeBlockLangs = ['clojure', 'css', 'elixir', 'html', 'plain text', 'python', 'ruby', 'swift', 'typescript', 'jsx', 'yaml', 'json', 'json-ld', 'rust', 'r', 'shell', 'php', 'java', 'c#', 'c', 'c\\+\\+', 'objective-c', 'go', 'kotlin', 'sql', 'haskell', 'scala', 'commonlisp', 'solidity', 'julia', 'sparql', 'turtle', 'lua', 'dart', 'latex', 'markdown', 'xml', 'toml', 'vb', 'vbscript', 'javascript']; |
There was a problem hiding this comment.
I'm confused why this is needed. Why are these tags being removed?
|
Closing this - you were right on both counts. The table commit was a duplicate of #505, which has now been rebased and revised there on its own. On the language tags: I stripped them because code blocks were rendering wrong inside bullets, but the cause was Roam exporting the fences glued to the content, not the tags. Obsidian handles ```javascript fine. Removing them fixed the symptom by accident. What is left worth keeping is the fence normalisation and the indentation of continuation lines in a multi-line block, using the version you wrote in the review. That will come back as its own branch once #505 lands, with a recording of Thank you for the time you put into both reviews. |
Summary
Two improvements to the Roam Research JSON importer:
1. Convert
{{[[table]]}}blocks to native Markdown pipe tablesRoam tables were previously left as raw text (the conversion code was commented out). This implements proper structural conversion:
{{[[table]]}}/{{table}}blocks in the JSON tree (not via string replacement)roamMarkupScrubber()for proper link/markup conversionBefore: Tables imported as nested bullet lists (unusable)
After: Clean Markdown pipe tables that render natively in Obsidian
2. Fix code block formatting inside bullet lists
Multi-line code blocks (stored with
\nin Roam's block string) lost their indentation during import, breaking the bullet hierarchy in Obsidian. Everything after an opening```would be swallowed into a single giant code block.Three fixes:
```are always on separate lines (Roam exports them glued to content)javascript,python, etc.) from code fences — Roam uses these internally but they cause rendering issues in Obsidian's list contextBefore: Code blocks break bullet hierarchy, all content below absorbed into code
After: Properly contained code blocks with correct bullet nesting
Test plan
{{[[table]]}}blocks — verify pipe tables render correctlyjavascript,python) have tags strippednpm run buildandnpm run lint— both pass🤖 Generated with Claude Code