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

Double empty lines between headers and list #54

Open
piranna opened this issue Feb 2, 2020 · 5 comments
Open

Double empty lines between headers and list #54

piranna opened this issue Feb 2, 2020 · 5 comments

Comments

@piranna
Copy link

piranna commented Feb 2, 2020

When setting a list just after a header, there are two empty lines between them, separating them too much, when there should be just a single one. Seems it's due to the fact headers add an newline after them and lists add a newline before them, so when joining the fragments this result in three consecutive newlines. I think it would be better no block add a newline before or after them, and instead the joining add the two ones to create the empty line. This failing test checks it:

    test.it("should add a single newline between headers and ordered lists", function(cb) {
        test.expect(json2md([
            {
                h1: "Heading 1"
            },
            {
                ol: [
                    "item 1", "item 2"
                ]
            }
        ])).toBe("# Heading 1\n\n 1. item 1\n 2. item 2\n");
        cb();
    });
@nfantone
Copy link

nfantone commented Apr 7, 2022

This is actually true for all headings, on top of any element.

json2md([{ "h2": "Title" }, { "p": "Paragraph" }])
// '## Title\n\n\nParagraph\n'

@piranna
Copy link
Author

piranna commented Apr 7, 2022

I think ideal solution should be that nobody adds newlines except on final step: blocks.join('\n\n').

@nfantone
Copy link

nfantone commented Apr 7, 2022

Probably, yeah. To be honest, I have resorted to applying remark as a final step to the output. It takes care of those multiple empty blank lines + auto-fixes and checks many other configurable rules.

@piranna
Copy link
Author

piranna commented Apr 7, 2022

Interesting aproach :-) Although it could be better if we can have it clean beforehand :-D

@bsommardahl
Copy link

I'm having an issue with this as well, except that I need to be able to add multiple "blocks" as single lines and I don't want the extra lines between them. I would have used p but it has an empty line after it in the output. I could use a line block without any empty lines added.

To me, ideally, each converter would define its own formatting including any trailing new lines. Then, the final step would be just blocks.join('\n'). And with that, I could add my own line converter and possibly even contribute one.

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

No branches or pull requests

3 participants