Skip to content

Conversation

@ejscunha
Copy link
Contributor

@ejscunha ejscunha commented Sep 11, 2025

Don't add double new line after a inline tag mixed with text.

Summary by Sourcery

Fix spacing logic between HTML elements by replacing hard-coded newlines with context-aware spacing, add supporting tests, and update fixtures

Bug Fixes:

  • Prevent double new lines after inline HTML tags when mixed with text

Enhancements:

  • Introduce get_spacing_between_elements to choose space or newline based on element type

Tests:

  • Add unit tests for emphasis, strong, and span tags followed by text to verify inline spacing

Chores:

  • Update markdown fixture to remove extra blank lines around superscript tag

Don't add double new line after a inline tag mixed with text.
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 11, 2025

Reviewer's Guide

Implement context-sensitive element spacing to avoid unnecessary double newlines after inline tags, introduce helper to differentiate block vs inline tags, and update tests and fixtures to validate inline tag behavior.

Class diagram for updated Html2Markdown.Converter spacing logic

classDiagram
    class Html2Markdown.Converter {
        +process_children_to_iolist(children, opts)
        +process_node_to_iolist(node, opts)
        +process_ordered_list_item_to_iolist(other, index, opts)
        +process_children_with_context(children, opts, context)
        -get_spacing_between_elements(node)
    }
    class ElementTypes {
        +block_element?(tag)
    }
    Html2Markdown.Converter --> ElementTypes: uses
    Html2Markdown.Converter : get_spacing_between_elements(node)
    Html2Markdown.Converter : process_children_to_iolist(children, opts)
    Html2Markdown.Converter : process_node_to_iolist(node, opts)
    Html2Markdown.Converter : process_ordered_list_item_to_iolist(other, index, opts)
    Html2Markdown.Converter : process_children_with_context(children, opts, context)
    ElementTypes : block_element?(tag)
Loading

Flow diagram for spacing decision between elements

flowchart TD
    A["process_children_to_iolist"] --> B["get_spacing_between_elements(node)"]
    B --> C{Is tag a block element?}
    C -- Yes --> D["Spacing: '\n\n'"]
    C -- No --> E["Spacing: ' '"]
Loading

File-Level Changes

Change Details Files
Context-sensitive spacing between HTML elements
  • Replace fixed double newline with dynamic spacing call
  • Add get_spacing_between_elements/1 helper to detect block versus inline tags
  • Integrate helper into element concatenation logic
lib/html2markdown/converter.ex
Add tests for inline tag behavior
  • Add emphasis tag spacing test
  • Add strong tag spacing test
  • Add span tag spacing test
test/html2markdown_test.exs
Adjust fixture formatting for superscript inline tag
  • Remove extra blank lines around tag
  • Ensure correct trailing space after inline tag
test/support/fixtures/elixir.md

Possibly linked issues

  • convert links to absolute url #1: The PR fixes the reported breaking change by preventing double newlines after inline HTML tags like emphasis and strong when converting to Markdown.
  • #123: The PR introduces a new spacing function to correctly add newlines between block elements and spaces for inline, fixing the issue's reported extra newlines between paragraphs.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ejscunha ejscunha mentioned this pull request Sep 11, 2025
@cpursley cpursley merged commit 9382dc5 into agoodway:main Sep 12, 2025
9 checks passed
@cpursley
Copy link
Collaborator

Thank you @ejscunha !!!

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.

2 participants