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

Support html anchors #1

Closed
tkruse opened this issue Sep 29, 2015 · 8 comments
Closed

Support html anchors #1

tkruse opened this issue Sep 29, 2015 · 8 comments
Labels
🙋 no/question This does not need any changes

Comments

@tkruse
Copy link

tkruse commented Sep 29, 2015

Hi,

I beleve this only valdate simple header links, not html anchor links, right?
http://stackoverflow.com/questions/6695439/how-do-you-create-link-to-a-named-anchor-in-multimarkdown

Example:

./node_modules/.bin/mdast -u mdast-slug -u mdast-validate-links example.md
When commenting, please note [the introduction](#S-introduction)

# <a name="S-introduction"></a> In: Introduction

Text


example.md
  1:30-1:65  warning  Link to unknown heading: `S-introduction`

⚠ 1 warning
@wooorm
Copy link
Member

wooorm commented Sep 29, 2015

Yup, it doesn’t. It supports github, npm, and other “heading” auto id’s.

mdast doesn’t parse HTML (markdown doesn’t care if HTML is in real, valid, &c.). HTML can be a mess: in fact, the point of mdast is to not only think about compiling to HTML, but also support other systems (e.g., man pages or react), which all simply discard HTML.

To add this, I recommend creating something that parses HTML nodes and adds the first found name attribute to node.htmlAtributes.id (that’s what mdast-validate-links looks for). In addition, there should be a tiny change here, from , 'heading' to '' to make validate-links work for non-headers too.

It’s not really on (the top of) my TODO list, but wooorm/hast might be of interest if you’d like to integrate.

@tkruse
Copy link
Author

tkruse commented Sep 29, 2015

Well, this is not about parsing html, but about parsing markdown the <a name="foo"></a> tags that can be found using regexes are really part of markdown I think, because markdown does not provide another way to define anchors without defining a header, as far as I know. So if validate-links could parse just these tags, that would be a great help to Markdown authors.

@wooorm
Copy link
Member

wooorm commented Sep 29, 2015

I don’t think it’s mdast-validate-links which should parse HTML, just like I don’t think it’s mdast-validate-links job to detect slugs (that’s mdast-slug). That should be another module, which I’m currently not willing to write (sorry).

It is mdast-validate-links’s place to ensure other modules can interact with it, by exposing node.data.id or node.data.htmlAtributes.id; that’s why this issue is still open.

The fact that markdown doesn’t expose anchors means HTML anchors are no portable (and probably not safe) to other formats. This is part of why I’m not that interested in working on this.

Also, regarding “just parse these tags”, how about <a name="foo"> (unclosed), <a name="foo"></a><a name="bar"></a> (multiple), or thousands of HTML characters?

I can provide help if you’d be interested in building this though.

@tkruse
Copy link
Author

tkruse commented Sep 29, 2015

I don't know what the word "slug" means, but maybe indeed I mean that mdast-slug should parse those tags in markdown. Indeed parsing the possible anchor variations can be horrible (so maybe regex is not a good approach).

I am not sure whether html anchors are generally not portable to other formats, this really depends on any given tools willingness to handle html anchors (I need to check pandoc anyway). If everbody uses them in their markdown, tools will follow.

@wooorm
Copy link
Member

wooorm commented Sep 29, 2015

Slug.

A more simple approach would be to only support a single HTML element, with content set to the empty string, with one attribute, namely name: E.g., <span name="foo"></span> or <a name="base"></a>.

But again, I’m not going to create it. I can help you with setting up a plugin/utility though!

@tkruse
Copy link
Author

tkruse commented Sep 29, 2015

ok, wish I had the time, but have not. Closing as invalid.

@tkruse tkruse closed this as completed Sep 29, 2015
@wooorm
Copy link
Member

wooorm commented Sep 29, 2015

For now I’m reopening, just to reminded that this plugin should support non-headings, htmlAttributes.name, and I’ll add a section on possible future improvements where I describe this idea.

Thanks for the idea! 👍

@igor-tsiglyar
Copy link

FYI markdownlint supports links to anchor. It won't validate links to other files, however, but there is a plugin for that that recently has been updated to also support anchor links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes
Development

No branches or pull requests

3 participants