Roam: Fix table conversion and code block formatting#506
Open
cristip73 wants to merge 2 commits intoobsidianmd:masterfrom
Open
Roam: Fix table conversion and code block formatting#506cristip73 wants to merge 2 commits intoobsidianmd:masterfrom
cristip73 wants to merge 2 commits intoobsidianmd:masterfrom
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>
Contributor
|
This PR duplicates a commit from #505. Please remove that commit from this PR so they can be reviewed and merged independently. |
tgrosinger
reviewed
Mar 13, 2026
|
|
||
| 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'); |
Contributor
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') |
Contributor
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']; |
Contributor
There was a problem hiding this comment.
I'm confused why this is needed. Why are these tags being removed?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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