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

Adding multiple titles/headers with the same content produces invalid markup. #82

Closed
nicovalencia opened this issue Jan 8, 2014 · 6 comments
Assignees

Comments

@nicovalencia
Copy link

Creating a title/header adds the content of the header to the header markup tag's id attribute.

For example:

# foobar
# foobar

produces:

<h1 id="foobar">foobar</h1>
<h1 id="foobar">foobar</h1>

If setting an id attribute is necessary for #hash linking, it should keep track of duplicates appending a unique identifier. e.g. foobar-1, foobar-2, etc or a timestamp foobar-1389214127156, foobar-1389214127157, etc.

If setting an id attribute is unnecessary, this functionality should be removed altogether.

@nicovalencia
Copy link
Author

I'm working on this issue after noticing ids were being added during a bug fix for Ghost.

@nicovalencia
Copy link
Author

In addition to incrementing a unique identifier for ids, we should also prefix the id with a namespace. Allowing users who leverage this library as a content editing system opens the door for them to inadvertently match existing style rules based on the header id/content. (Exactly what's happening in Ghost)

I'm proposing a format similar to the following:

## helloworld
## helloworld
## helloworld
<h2 id="section-helloworld">helloworld</h2>
<h2 id="section-helloworld-1">helloworld</h2>
<h2 id="section-helloworld-2">helloworld</h2>

nicovalencia added a commit to nicovalencia/showdown that referenced this issue Jan 8, 2014
…header ids.

closes showdownjs#82
- Modified header id function to prepend `section` to each id
- Modified header id function to track duplicate count and append a unique numerical-id
@nicovalencia
Copy link
Author

A side-note for this fix/hack:

Users really shouldn't be creating duplicate headers to begin with. Personally, I feel like the library should warn when this happens and not allow for duplicates or any other invalid/non-semantic markup. This would bring an entirely new purpose (markup validation) into the responsibilities of this library, so we should definitely spin off a new thread to deal with that if necessary -- I just wanted to note the underlying issue here.

@tivie tivie self-assigned this Jan 6, 2015
@pdeschen
Copy link
Contributor

@nicovalencia I think duplicate headers should be allowed and is all fine. What if I have something like

# Chapter 1

## Introduction
...

# Chapter 2

## Introduction
...

Now you're idea about using a suffix counter is an interesting workaround. As an addition: would it make sense to add the original section title as a class (for invariable styling)?

@tivie
Copy link
Member

tivie commented Jan 24, 2015

Once we merge the v2 branch, c367a4b will close this. @nicovalencia contribution should be mentioned though, somewhere appropriate.

@nicovalencia
Copy link
Author

Makes sense to me -- thank you @tivie!

🍰

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

Successfully merging a pull request may close this issue.

3 participants