facelessuser / MarkdownPreview

Markdown preview and build plugin for Sublime Text https://facelessuser.github.io/MarkdownPreview/
Other
405 stars 53 forks source link

Why Markdown Preview needs two " Enter" to get a newline? #102

Closed JingwangLi closed 4 years ago

JingwangLi commented 4 years ago

I think Markdown Preview is wonderful, but there is a problem: It needs two " Enter" to get a newline. I have used several rendering engines, like the hexo, reveal.js, Typora and so on. They all need one "Enter". I think typing two "Enter" every time when you need to get a newline is two annoying, just like this: image

I wondering that's a bug or on purpose?

facelessuser commented 4 years ago

This is just how the Markdown spec is defined, which I did not create:. If you want to insert a <br> tag in a paragraph, you can use two trailing spaces. https://daringfireball.net/projects/markdown/syntax#p.

You can also enable https://python-markdown.github.io/extensions/nl2br/ to allow single newlines to register as a <br> within a block element. (block elements -- paragraphs, etc. -- still have to be separated by two newlines.

You can also use https://facelessuser.github.io/pymdown-extensions/extensions/escapeall/#options -- if configured properly -- which will allow an escaped line ending to be converted to a newline if preferred.

@gir-bot remove S: triage @gir-bot add T: support

JingwangLi commented 4 years ago

Thanks for your suggestions! I'll try it later.

facelessuser commented 4 years ago

As there is no actionable item for us, I'll close this issue..

JingwangLi commented 4 years ago

As there is no actionable item for us, I'll close this issue..

May I add the EscapeAll to Markdown Preview to add the option(two spaces or just enter)?

facelessuser commented 4 years ago

Yes, the EscapeAll extension is available for use in Markdown Preview. Just enable the related option in the extension.

JingwangLi commented 4 years ago

I thought I need to PR formerly because I found nothing about the EscapeAll in the Markdown Preview default settings. After seeing your reply, I downloaded the source codes of Markdown Preview and found EscapeAll in the "mkdocs.yml", and "hardbreak" and "nbsp" in that file are both true. Are they already enabled? I'm confused. So what's the meaning about " enable the related option in the extension"? I've checked the dependencies of Markdown Preview in the \Sublime Text 3\Packages, but I think there is nothing that I can configure. Do you means that I should override some codes of Markdown Preview in Sublime Text?

facelessuser commented 4 years ago

Yes, I use EscapeAll in my documentation, but I only enable some GitHub-ish feel stuff by default in Markdown Preview. I let the user override and set things the way they want it. EscapeAll is available, but I do not force it on anyone.

JingwangLi commented 4 years ago

I think it will be more convenient(instead of overriding some codes which maybe a little complex for some newcomers like me) if the option is included in default seting. Can I PR to add this option in default setting(even though I haven't figure out it now but I think I can)?

facelessuser commented 4 years ago

It's very nonstandard, so I don't really want to enable by default. It's not something a user expects. There are a lot of things that specific users may want or not want. I cannot please then all. So generally, I enable things to feel GitHub-ish which a lot of people are familiar with, but not much more.

JingwangLi commented 4 years ago

Ok, I understood it. Thank you vary much.

JingwangLi commented 4 years ago

Sorry to bother you again. But I guess you probably misunderstand me. What I am saying is putting the option in the default setting(but setting it false because two spaces would be the choice of a lot of people) instead of enabling it and also provide a convenient choice for others.

facelessuser commented 4 years ago

Adding the extension enables the extension, maybe not the newline feature, but the extension still gets enabled. I don't want to enable the extension by default. It is not functionality that would normally be expected. I personally use it, but the behavior may surprise others.

JingwangLi commented 4 years ago

I already overrode MarkdownPreview.sublime-settings(added "pymdownx.escapeall",) and changed \Sublime Text 3\Packages\pymdownx\st3\pymdownx\escapeall.py(set 'hardbreak' as true),but it still needs two spaces to get a newline. Could you give me some advice? image image

facelessuser commented 4 years ago

I don't understand what you are showing me, but hardbreak should be false by default. You must set hardbreak to True in the config to have it work.

EscapeAll allows you to insert a line break by escaping the newline:

I would like a newline\
here

This allows for a visual token for line breaks in paragraphs instead of invisible double spaces. If you simply want to use a single enter, you must use https://python-markdown.github.io/extensions/nl2br/. You can read its documentation for more info.

JingwangLi commented 4 years ago

Thanks a lot! I thought I can use a enter to get a newline by EscapeAll which is a wrong understanding, so I tried to change other files to make it work(didn't realize it already works...). And I thought you can't add some settings to user setting that aren't included in the default setting... Now I knew it only needs to put the extension in the user setting. Everything is perfect now, thanks again!

arunabhcode commented 1 year ago

Shouldn't the correct fix be changing github_mode to gfm from markdown inside settings?

arunabhcode commented 1 year ago

Yep that seems to have worked. Thanks for the software! :-)