Skip to content

Back ticks in titles (incorrectly?) converted to hypens #510

Closed

Description

@bduncanj

Smashing library, much thanks!

I may be abusing markdown a little, but I'm using code back ticks in my titles:

## Messages
### `system-alarm-start`
### `system-alarm-end`

This however produces HTML in which the backtick is replaced with a hyphen in the id attribute of the resulting header element:

<h2 id="messages">Messages</h2>
<h3 id="-system-alarm-start-"><code>system-alarm-start</code></h3>
<h3 id="-system-alarm-end-"><code>system-alarm-end</code></h3>

The problem is that I'm using marked-toc to convert this into the following markdown TOC (and then HTML via marked) which of course is now incompatible as that package just ignores the back ticks in the headers:

* [Messages](#messages)
  * [`system-alarm-start`](#system-alarm-start)
  * [`system-alarm-end`](#system-alarm-end)

... and finally ...

<ul>
<li><a href="#messages">Messages</a><ul>
<li><a href="#system-alarm-start"><code>system-alarm-start</code></a></li>
<li><a href="#system-alarm-end"><code>system-alarm-end</code></a></li>
</ul>
</li>
</ul>

Activity

  1. Feder1co5oave commented on Nov 16, 2014

    @Feder1co5oave
    Contributor

    I, too, rely heavily on hashes.

    The naive solution is to override the heading renderer and generate ids in the same way marked-toc does.

    See related issues #432 #450. The problem extends far beyond leading/trailing slashes.
    I think I proposed a reasonable solution in #456. Feel free to merge it. Notice that you can then override the heading renderer and possibly use uslug to generate id attributes.

  2. F1LT3R commented on Mar 10, 2015

    @F1LT3R

    +1 to fixing this out of the box

  3. franciscop commented on Jul 22, 2017

    @franciscop

    +1. I'd go a bit further and say that leading/trailing hyphens should be removed as well:

    # Hello!
    # How to fix X?
    <h1 id="hello-">Hello!</h1>
    <h1 id="how-to-fix-x-">How to fix X?</h1>
  4. joshbruce commented on Dec 25, 2017

    @joshbruce
    Member
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions