Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(console): print <br /> when having a newline #3701

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

ematipico
Copy link
Member

Summary

The HTML emitted by our adapter was causing a parsing error when used inside MDX files.

It turns out that MDX doesn't like \n\n inside HTML. I think it's a reasonable parsing error.

This PR fixes the issue by changing \n to a <br />. While <br> should be accepted, MDX doesn't like it, so it's safer to use <br /> instead.

This PR changes the existing adapter and renames it. Unfortunately, I tried to use a new adapter but that required more work, so I decided to update the existing one.

Test Plan

I added new tests to avoid possible regressions. Once merged, I will send a PR to the website to fix everything.

@ematipico ematipico requested review from a team August 23, 2024 10:48
@github-actions github-actions bot added the A-CLI Area: CLI label Aug 23, 2024
@ematipico
Copy link
Member Author

I am going to merge this, since I need this fix in the website repository. Let me know if there are any concerns, I will follow up

@ematipico ematipico merged commit 5bbe19b into main Aug 23, 2024
13 checks passed
@ematipico ematipico deleted the fix/html-renderer-newlines branch August 23, 2024 11:06
@chansuke
Copy link
Member

I've read the code and I believe adding some test cases would be beneficial

  1. adding tests for more escape characters, such as '&', '<', and '>':

  2. testing multiple new lines like below

#[test]
fn test_multiple_newlines() {
    let mut buf = Vec::new();
    let mut writer = super::HTML(&mut buf);
    let mut formatter = Formatter::new(&mut writer);
    formatter
        .write_markup(markup! {
            "Line1\nLine2\rLine3\n\rLine4"
        })
        .unwrap();
    assert_eq!(String::from_utf8(buf).unwrap(), "Line1<br />Line2<br />Line3<br /><br />Line4");
}

@ematipico
If this approach looks good to you, I’d be happy to submit a PR.

ematipico added a commit that referenced this pull request Aug 23, 2024
@Conaclos Conaclos added the A-Changelog Area: changelog label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-CLI Area: CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants