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

Hashtags in the beginning are rendered as headings #201

Closed
jorilallo opened this issue Jul 19, 2013 · 21 comments
Closed

Hashtags in the beginning are rendered as headings #201

jorilallo opened this issue Jul 19, 2013 · 21 comments

Comments

@jorilallo
Copy link

I ran into a problem while testing hashtags:

marked("#hashtag test\n test")

renders as

<h1>hashtag test</h1>
<p> test</p>

while the expected output is

<p>#hashtag test</p>
<p> test</p>
@Mithgol
Copy link
Contributor

Mithgol commented Jul 19, 2013

That's the expected behaviour, because the # character marks a heading.

Work around by using \# instead of a simple #.

Also note that a single \n won't get you a new paragraph. Use two \n for that.

@jorilallo
Copy link
Author

@Mithgol according to Markdown documentation there needs to be a space character after the #, not combined. Also GitHub doesn't render that as a heading.

Edit: for the example I was using GFM's newline support so it renders to paragraphs

@jorilallo
Copy link
Author

So I think the correct regular expression should be

heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/,

Here's an example render with GitHub's Markdown. Source:

#header
# header1
#  header1

Result:

#header

header1

header1

jorilallo added a commit to jorilallo/marked that referenced this issue Jul 19, 2013
@Mithgol
Copy link
Contributor

Mithgol commented Jul 19, 2013

Good argument. I am convinced.

@tarqd
Copy link

tarqd commented Aug 1, 2013

I'd like to see this merged, +1

@chjj
Copy link
Member

chjj commented Aug 2, 2013

$ echo '#foo' | markdown.pl
<h1>foo</h1>

Not sure this qualifies as a fix. It violates markdown.pl behavior.

@tarqd
Copy link

tarqd commented Aug 2, 2013

Ah well if markdown.pl behaves that way I'd just leave it. You can always escape it anyway

@jorilallo
Copy link
Author

@chjj @ilsken Just for the sake of arguments, has anyone ever really used markdown.pl? I would stick with the documentation (which states "# heading") and common sense but that's just me. Having #hashtags and @mentions is pretty common with services.

@Mithgol
Copy link
Contributor

Mithgol commented Aug 2, 2013

Being backwards compatible with markdown.pl is important.

However, it seems like the GFM mode could imitate GitHub flavoured Markdown better if it took the whitespace in consideration after the # character.

@jorilallo
Copy link
Author

+1 for GFM

Jori Lallo

+1 (415) 728 5773
@jorilallo (http://twitter.com/jorilallo)

http://kippt.com

On Friday, August 2, 2013 at 12:05 PM, Mithgol wrote:

Being backwards compatible with markdown.pl (http://markdown.pl) is important.
However, it seems like the GFM mode could imitate GitHub flavoured Markdown better if it took the whitespace in consideration after the # character.


Reply to this email directly or view it on GitHub (#201 (comment)).

@elennaro
Copy link

elennaro commented Oct 11, 2014

+1 for GFM
Having hashtags is good!
Also if GFM does this way when I enable GFM I expect same behaviour.
At least can anyone give me a hint: how to apply it 4 my needs easily, please?

@Mithgol
Copy link
Contributor

Mithgol commented Oct 12, 2014

@elennaro It's as easy as manually applying the patch jorilallo/marked@09c26a8. It replaces only one character in the source code (* → +) and thus it couldn't be any easier.

@elennaro
Copy link

Oh, thank you @Mithgol really simple and beautifull!

@ledsun
Copy link
Contributor

ledsun commented Nov 17, 2014

+1 for GFM

@silkimen
Copy link

silkimen commented Feb 2, 2015

+1 GFM

@chjj
Copy link
Member

chjj commented May 8, 2015

Fixed.

@chjj chjj closed this as completed May 8, 2015
@xaka
Copy link

xaka commented Aug 6, 2015

I know it's been a while, but for the future reference I want to point out that this change should have never landed as a patch (0.3.2 -> 0.3.3), but at least as a minor (0.3.2 -> 0.4.0) because it's backward incompatible from customer's perspective, who don't care about whitespace because it's been allowed for a long time and now it breaks existing badly formatted markdowns. No complains whatsoever. Just suggestions 😉

@Stephen-Mc
Copy link

Very unhappy at this change, it broke all our documentation by no longer rendering the headings correctly. Would love to see it reverted, as breaking existing docs just to be able to render hashtags without an escape character does not strike me as the right set of priorities.

Thankfully most of our docs are parsed for conversion to HTML, and are still rendered correctly on our websites, but I have 100 or so pages that are not parsed this way and now need to be updated with the new heading style.

@zcyzcy88
Copy link

zcyzcy88 commented Oct 11, 2017

How about <h1> require space, and <h2>~<h6> don't require space?
When they type # without space, it often means hashtag, not <h1>.


Example:

Text Text Text Text Text Text Text Text.
#tag1 #tag2

Now render as:

Text Text Text Text Text Text Text Text.

tag1 #tag2

Expect:

Text Text Text Text Text Text Text Text.
#tag1 #tag2

@Stephen-Mc
Copy link

That would be even more confusing than the current state of affairs.

deathaxe added a commit to deathaxe/sublime-packages that referenced this issue May 13, 2021
This commit enforces at least one whitespace after a hashtag to match
a token as atx heading.

see: markedjs/marked#201
wbond pushed a commit to sublimehq/Packages that referenced this issue Jun 19, 2021
* [Markdown] Fix ATX heading

This commit enforces at least one whitespace after a hashtag to match
a token as atx heading.

see: markedjs/marked#201

* [Markdown] Fix atx header variable comment
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Jul 25, 2021
This commit enforces at least one whitespace after a hashtag to match
a token as atx heading.

see: markedjs/marked#201
mitranim pushed a commit to mitranim/Packages that referenced this issue Mar 25, 2022
* [Markdown] Fix ATX heading

This commit enforces at least one whitespace after a hashtag to match
a token as atx heading.

see: markedjs/marked#201

* [Markdown] Fix atx header variable comment
@Grey2k
Copy link

Grey2k commented Sep 6, 2023

#hashtag# test

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