Problem/Motivation

The Markdown output produced by ContentFirstBuilder had several rendering issues affecting real-world Drupal content:

  • Closing <div> and other stripped block elements caused adjacent text nodes to concatenate with no separator (e.g. FooBar instead of two separate lines).
  • ATX headings (# Heading) did not always start on their own line, breaking parsers that require a preceding blank line.
  • Blockquote markers (> ) did not always start on their own line for the same reason.
  • Whitespace text nodes inside <blockquote> produced spurious empty lines at the start of the block.
  • Images inside <picture> / <div> nesting accumulated leading/trailing spaces after strip_tags(), resulting in broken image tokens like ![Alt](url) .
  • html_entity_decode() was applied before strip_tags(), which decoded entities in <pre><code> blocks (e.g. <div><div>) and then stripped the decoded tags, corrupting code block content.

Proposed resolution

ContentFirstBuilder preprocessing pipeline:

  1. Collapse layout whitespace between block-level tags only when a newline is present, so inline spacing (e.g. </strong> <em>) is preserved.
  2. Replace closing tags of stripped block elements (div, section, article, etc.) with a newline before strip_tags() to prevent text concatenation.
  3. Remove html_entity_decode()HtmlConverter uses DOMDocument internally which decodes entities naturally. Applying it beforehand corrupts code blocks.
  4. After strip_tags(), normalize whitespace around media elements (<img>, <embed>) to fix stray spaces left by stripped container tags.

RenderedContent Markdown fixes:

  1. Ensure ATX headings always start on their own line.
  2. Ensure blockquote markers always start on their own line (handles both zero-newline and single-newline cases; scoped to avoid false positives).
  3. Remove spurious empty lines at the very start of a blockquote block.

Test coverage added:

  • RenderedContentTest: heading rendering, blockquote placement (6 parameterized cases including false-positive guards), multi-paragraph blockquotes, picture element passthrough, nested lists, full landing page integration.
  • HtmlTagTransformerTest: 20 tests covering transformSelfClosingTags() and transformPairedTags() (attributes, case insensitivity, multiple occurrences, unlisted tags, empty input).

Remaining tasks

Review and merge.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gedur created an issue. See original summary.

gedur’s picture

Issue summary: View changes
gedur’s picture

Issue summary: View changes
gedur’s picture

Issue summary: View changes
gedur’s picture

Issue summary: View changes

gedur’s picture

Status: Active » Needs work

  • gedur committed ac86b5db on 2.x
    Issue #3588910: Fix Markdown output issues and add unit test coverage
    
gedur’s picture

Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.