jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.68k stars 3.39k forks source link

Suggestion: Add --wrap=justify #2779

Closed sophie-h closed 8 years ago

sophie-h commented 8 years ago

I am using pandoc to pretty print markdown. Adding justification would make it even prettier.

jgm commented 8 years ago

I think justification in fixed-width fonts is too ugly to make it worth adding. (And adding it would add a lot of complexity.)

jgm commented 7 years ago

+++ v1kn [Jan 07 17 00:22 ]:

can text alignment be done through templates? I tried adding text-align: justify; to the paragraph section of a CSS file I call with -c flag, but the text isn't justified in a browser

Hm, this should work, and I've often done this. Maybe there's a small problem with the way you're doing it?

v1kn commented 7 years ago

@jgm Thank You for responding, even though I deleted my comment (because I was commenting on a similar things in a different issue)

Is is entirely possible there's a problem with how I'm doing it, so here's the rundown:

If You can point me in the right direction I would appreciate it

jgm commented 7 years ago

I tried with your css file and it worked (justified paragraphs). So I'm not sure what to suggest. Take a look at the generated html file and make sure it contains a reference to your CSS. Do any of the CSS properties work? Is it possible your browser is not finding the CSS file (you could confirm this by using a browser debugger).

jgm commented 7 years ago

There's a stray '2' in the h1 stanza of your CSS, maybe this is confusing the browser?

+++ John MacFarlane [Jan 07 17 12:57 ]:

I tried with your css file and it worked (justified paragraphs). So I'm not sure what to suggest. Take a look at the generated html file and make sure it contains a reference to your CSS. Do any of the CSS properties work? Is it possible your browser is not finding the CSS file (you could confirm this by using a browser debugger).

v1kn commented 7 years ago

@jgm maybe, but I think I found what may be the culprit - I use vim, and I use hard wrapping at 80 characters. I now tried soft wrapping and text is justified.

Do You have an idea how to deal with justifying hard-wrapped text? I tried justifying it in vim, but the additional spaces get ignored during conversion

edit
the browser recognizes CSS template, as everything else looks as it should

v1kn commented 7 years ago

since I don't have these files published (and I am using someone else's article as a testbed), I can only offer screenshots:

source text in vim, first paragraph soft-wrapped, the rest hard-wrapped

html file in fiefox

v1kn commented 7 years ago

I can reproducibly confirm what is causing this: markdown_github as an input format

As soon as I switched from it to standard markdown, everything is now justified.

Should I open an issue for this?

jgm commented 7 years ago

The problem is undoubtedly that markdown_github includes the hard_line_breaks extension, which causes each newline to turn into a <br> tag in HTML. (That will mess up justification.)

This is how GitHub's markdown works in comments (though not in README and other long form content).

To turn it off, use:

-f markdown_github-hard_line_breaks

+++ v1kn [Jan 07 17 04:50 ]:

I can reproducibly confirm what is causing this: markdown_github as an input format

As soon as I switched from it to standard markdown, everything is now justified.

Should I open an issue for this?

— You are receiving this because you were mentioned. Reply to this email directly, [1]view it on GitHub, or [2]mute the thread.

References

  1. https://github.com/jgm/pandoc/issues/2779#issuecomment-271082014
  2. https://github.com/notifications/unsubscribe-auth/AAAL5DJwvbgHT5jfMuWsgMhNAn19oDZ_ks5rP4ocgaJpZM4HusMN
v1kn commented 7 years ago

yes this is the solution I came to yesterday. However, since lack of hard_line_breaks changes how some parts of my documents will look like (I did not follow strict markdown's rules on double space at the end of the line to introduce hard line break), I opted to instead use escaped_line_breaks.

Using pandoc -f markdown_github-hard_line_breaks+escaped_line_breaks does not work as expected though (escaped_line_breaks extension is ignored). Usually, I would start disabling other extensions to see what the culprit is, but as You can see from my comment on issue #583 regarding \LaTeX, even when I disabled all the extensions defined in markdown_github, the issue still persisted.

So as a solution, I now use -f markdown, and am adding all the extensions from github variant to it, except hard_line_breaks

Thank You for Your assistance.

jgm commented 7 years ago

+++ v1kn [Jan 07 17 16:10 ]:

Using pandoc -f markdown_github-hard_line_breaks+escaped_line_breaks does not work as expected though (escaped_line_breaks extension is ignored).

Why don't you opne a new issue on this, with an example to reproduce.

v1kn commented 7 years ago

No problem.