Skip to content

Emphasis with underscore #1010

Closed
Closed

Description

@aduh95

Expectation

CommonMark Playground link

<h1>Hello</h1>
<p>Here is some emphasis: <em>Hello_World</em>!</p>
<p>Done.</p>

Result

<h1 id="hello">Hello</h1>
<p>Here is some emphasis: _Hello<em>World</em>!</p>
<p>Done.</p>

What was attempted

# Hello

Here is some emphasis: _Hello_World_!

Done.

I've found an example in the CommonMark spec describing this very behavior.

Activity

  1. added
    L1 - broken
    on Jan 12, 2018
  2. Feder1co5oave commented on Jan 12, 2018

    @Feder1co5oave
    Contributor

    Thanks for reporting this, it looks like it is really broken. I'm not keen on changing the em regex since it changed quite a lot of times in the past and it looks really awful now.
    Moreover, that commonmark spec for emphasis really is hell!
    I think the usual approach to make emphasis work with underscores in it is to use stars as delimiters, instead:

    $ bin/marked
    # Hello!
    
    Here is some emphasis: *Hello_World*!
    
    Done.
    <h1 id="hello-">Hello!</h1>
    <p>Here is some emphasis: <em>Hello_World</em>!</p>
    <p>Done.</p>

    Hope this helps.
    Still, this is broken.

  3. aduh95 commented on Jan 12, 2018

    @aduh95
    ContributorAuthor

    Thank you for your help. I am aware of this workaround, but my team uses Prettier formatter for our documents. It is a great tool to have an unified syntax, unfortunately it is a pain in the neck for this particular issue, because it automatically replaces the star delimiters with underscores.

  4. joshbruce commented on Jan 12, 2018

    @joshbruce
    Member

    Interesting. Just to make sure I'm understanding, without getting too into the weeds: Prettier essentially "transpiles," for lack of a better term, asterisks into underscores. Then that's the result you are displaying?

    I guess I'm trying to see the flow of data, from a user perspectvie, at a high-level:

    User -> Markdown -> Marked -> Prettier -> display

    ??

  5. aduh95 commented on Jan 13, 2018

    @aduh95
    ContributorAuthor

    Yes, pretty much, you can observe it on their playground. Every time we save a file on our editor, Prettier "transpiles" the file (adding spaces into tables to make them look like actual tables, replacing asterisks into underscores for emphasis, etc.) which then is used by Marked for displaying.

    The flow of data is more like that:

    User -> Markdown -> Prettier -> Marked -> display

  6. added
    L2 - annoying
    and removed
    L1 - broken
    L2 - annoying
    on Jan 13, 2018
  7. joshbruce commented on Jan 13, 2018

    @joshbruce
    Member

    @aduh95: Gotcha, I'm going to convert this to annoying for now because it's more of an integration issue (for this specific case), and trust @Feder1co5oave when he says it's still broken. Thanks.

    (As you can tell by the changes in the ticket types, I had an internal battle on where exactly to put it.) :)

  8. UziTech commented on Dec 5, 2018

    @UziTech
    Member

    looks like this is fixed in the latest version. demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L2 - annoyingparser: CommonMark

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions