cwjohan / markdown-to-html

Command-line utility to convert Github Flavored Markdown to HTML.
MIT License
236 stars 86 forks source link

ID creation? #9

Open vol7ron opened 7 years ago

vol7ron commented 7 years ago

Creates IDs on headers. This is a no-no. If your document reuses a header, that's bad HTML:

# Product Descriptions (Benefits vs Costs)
## Foo
Some description about Foo.
### Benefits
### Costs
## Bar
Some description about Bar.
### Benefits <-- uses an already created ID
### Costs <-- uses an already created ID

Product Descriptions (Benefits vs Costs)

Foo

Some description about Foo.

Benefits

Costs

Bar

Some description about Bar.

Benefits

Costs

cwjohan commented 7 years ago

Thank you, vol7ron. I didn't know that, though I have been using HTML for more than 30 years! It makes sense that one shouldn't knowingly do that. Though it violates the HTML spec and one cannot predict how javascript searching for the ID in any particular browser will behave, I assume it causes no actual practical problem for readers of the rendered HTML since all browsers render it as expected, though it likely would fail any HTML validation checks.

On Wed, Oct 19, 2016 at 6:51 AM, vol7ron notifications@github.com wrote:

Creates IDs on headers. This is a no-no. If your document reuses a header, that's bad HTML:

Product Descriptions (Benefits vs Costs)

Foo

Some description about Foo.

Benefits

Costs

Bar

Some description about Bar.

Benefits <-- uses an already created ID

Costs <-- uses an already created ID

Product Descriptions (Benefits vs Costs) Foo

Some description about Foo. Benefits Costs Bar

Some description about Bar. Benefits Costs

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cwjohan/markdown-to-html/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AH5q3FFkDmkBSUDqtjl39DedytjTQto3ks5q1iBcgaJpZM4Ka_wf .

vol7ron commented 7 years ago

The premise is that, like a database record's primary key, an ID is a unique identifier. If it occurs more than once in the document it is no longer unique. Instead it should be added as a class, or used with data-* attributes.

The page may render correctly, but that's browser-dependent. It would fail validation, but also JavaScript operations that utilize the IDs. For instance, let's use jQuery for simplicity, $('#code').css('border', '1px solid')

The JS above would only apply a border to one of the id="code" elements on the page. So, I would recommend adding it as a class: md-<id value>

On Oct 19, 2016, at 6:25 PM, Craig Johannsen notifications@github.com wrote:

Thank you, vol7ron. I didn't know that, though I have been using HTML for more than 30 years! It makes sense that one shouldn't knowingly do that. Though it violates the HTML spec and one cannot predict how javascript searching for the ID in any particular browser will behave, I assume it causes no actual practical problem for readers of the rendered HTML since all browsers render it as expected, though it likely would fail any HTML validation checks.

On Wed, Oct 19, 2016 at 6:51 AM, vol7ron notifications@github.com wrote:

Creates IDs on headers. This is a no-no. If your document reuses a header, that's bad HTML:

Product Descriptions (Benefits vs Costs)

Foo

Some description about Foo.

Benefits

Costs

Bar

Some description about Bar.

Benefits <-- uses an already created ID

Costs <-- uses an already created ID

Product Descriptions (Benefits vs Costs) Foo

Some description about Foo. Benefits Costs Bar

Some description about Bar. Benefits Costs

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cwjohan/markdown-to-html/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AH5q3FFkDmkBSUDqtjl39DedytjTQto3ks5q1iBcgaJpZM4Ka_wf .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

cwjohan commented 7 years ago

I'm thinking to get rid of the ID attribute entirely from the generated HTML header tags. Does anyone think that would be a bad idea? It's a fairly easy change to make.

ifullgaz commented 7 years ago

Hi, sorry for bumping an old thread but I think the problem can be resolved easily by using a globally incrementing ID for the headers instead of a semantically "readable" ID. Can this be done?

cwjohan commented 7 years ago

I'll have to check if any code of mine creates those headers. Mostly, I'm reusing other people's code for the HTML generation, though it may be possible in my code to override header code generation.

On Mon, Feb 20, 2017 at 7:20 AM, ifullgaz notifications@github.com wrote:

Hi, sorry for bumping an old thread but I think the problem can be resolved easily by using a globally incrementing ID for the headers instead of a semantically "readable" ID. Can this be done?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cwjohan/markdown-to-html/issues/9#issuecomment-281106107, or mute the thread https://github.com/notifications/unsubscribe-auth/AH5q3Hrkf6IV0HxXZo7S-gdRXqdlYKS_ks5rea9OgaJpZM4Ka_wf .