Skip to content

fix: unify export content across formats (title, soft breaks, comments)#61

Merged
rogerdigital merged 1 commit into
mainfrom
fix/export-content-consistency
Jun 24, 2026
Merged

fix: unify export content across formats (title, soft breaks, comments)#61
rogerdigital merged 1 commit into
mainfrom
fix/export-content-consistency

Conversation

@rogerdigital

Copy link
Copy Markdown
Owner

Problem

Exported content diverged from the source in ways that differed across the four formats. Investigation (filename vs content) found the filenames are already consistent (all formats write the same outputFilePath from ExportRunner). The issues are all in content layer:

Fixes

1. Title duplication with body's first H1

When a document started with a level-1 heading, every format prepended its own title (# / <h1> / Title style) on top of that heading still present in the body → duplicate title.

Fix: DocumentAssembler now extracts a leading # Heading as the document title and removes it from the body (extractLeadingH1). When there's no leading H1, the filename-derived title is used unchanged. Affects all formats uniformly.

Before After
# filename + # original heading (duplicate) # original heading (no duplicate)
# filename (no H1 in body) # filename (unchanged)

2. Markdown embed empty alt text

LinkRewriter.formatEmbed emitted ![](path) with empty alt for the markdown-bundle profile. Obsidian (and many viewers) don't render images with empty alt, so images were invisible.

Fix: Now uses the link text as alt (![image.png](path)), matching the docx/html/pdf branches.

3. docx soft line breaks became separate paragraphs

parseMarkdownToParagraphs split on every \n, so adjacent non-blank lines (Obsidian soft breaks within one paragraph) each became their own <w:p> with large paragraph spacing.

Fix: Consecutive plain-text lines are now aggregated into one paragraph, separated by <w:br/>, matching how Obsidian renders them.

4. docx rendered source-path comments as literal text

<!-- source: path --> lines appeared as visible body text in docx.

Fix: HTML comment lines are skipped during paragraph parsing.

Not changed

  • Image size (![[img.png|258]]): the |width Obsidian syntax is stripped upstream in LinkRewriter for all formats. Standard Markdown cannot express it; preserving it would require HTML <img width> in markdown-bundle, which is out of scope.

Tests

164 pass (added extractLeadingH1, soft-break aggregation, comment-skipping coverage).

Three content inconsistencies between export formats, all causing output
to diverge from the source:

1. Title duplication with body's first H1
   When a document started with a level-1 heading, each format prepended
   its own title (# / <h1> / Title style) on top of the heading still in
   the body, producing a duplicate. DocumentAssembler now extracts a
   leading H1 as the document title and removes it from the body
   (extractLeadingH1); when there is no leading H1 the filename-derived
   title is used unchanged.

2. Markdown embed empty alt text
   LinkRewriter.formatEmbed emitted ![](path) with empty alt for the
   markdown-bundle profile, which Obsidian and many viewers do not
   render as an image. Now uses the link text as alt, matching the
   docx/html/pdf branches.

3. docx soft line breaks became separate paragraphs
   parseMarkdownToParagraphs split on every newline, so adjacent
   non-blank lines (Obsidian soft breaks in one paragraph) each became
   their own <w:p> with large spacing. Consecutive plain-text lines are
   now aggregated into one paragraph separated by <w:br/>.

4. docx rendered source-path comments as literal text
   <!-- source: ... --> lines appeared as visible body text in docx.
   HTML comment lines are now skipped during paragraph parsing.

Tests: 164 pass (added extractLeadingH1, soft-break aggregation, and
comment-skipping coverage).
@rogerdigital rogerdigital merged commit 8f5ac80 into main Jun 24, 2026
1 check passed
@rogerdigital rogerdigital deleted the fix/export-content-consistency branch June 24, 2026 15:41
@rogerdigital rogerdigital mentioned this pull request Jun 25, 2026
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