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

Automatically get Anchor link #395

Closed
RensTillmann opened this issue Feb 22, 2018 · 5 comments
Closed

Automatically get Anchor link #395

RensTillmann opened this issue Feb 22, 2018 · 5 comments

Comments

@RensTillmann
Copy link

I was wondering if it would be possible to automatically retrieve the correct anchor link like this:

- [My Title](?)
# My Title

Or maybe leave blank like so:

- [My Title]()   < script should generate (#my-title) automatically

Instead of having to do like this:

- [My Title](#my-title)
# My Title

If this is possible I couldn't find how to do it, but if it's not possible maybe it's a good suggestion to add in future? Thanks 👍

@QingWei-Li QingWei-Li added this to the 4.7.0 milestone Feb 23, 2018
@QingWei-Li QingWei-Li removed this from the 4.7.0 milestone Jun 29, 2018
@trusktr
Copy link
Member

trusktr commented Jun 21, 2020

I'm not sure what's being asked here. @RensTillmann Can you explain a little more? @jhildenbiddle @anikethsaha any ideas?

@anikethsaha anikethsaha added the wait for information something is not clear, waiting for the author of the issue/pr label Jun 21, 2020
@jhildenbiddle
Copy link
Member

@RensTillmann --

Can you elaborate on how you would use this feature? I understand the basic idea of what you're asking for, but I'm unsure if you want this behavior in the sidebar, the main navigation, to content area, or anywhere in the site.

@RensTillmann
Copy link
Author

RensTillmann commented Jun 23, 2020

Hi, @trusktr @jhildenbiddle @anikethsaha I asked about this back in February 2018 (time goes too fast), back then I had not much understanding (nor used it) of what "Markdown" really was. Now I do, this question/feature request might actually not be so much related to Docsify at all, but more to the Markdown language itself. However I do not know how Docsify works under the hood, and if it might actually be capable of solving this issue on it's own.
In any case I will try to explain what I am still looking for as of today, because currently it's still something that I find very annoying (as in, I still use Docsify a lot along with Markdown language itself).

Let's assume we got the following markdown document which in this case is a simple FAQ:

# FAQ

**Commonly asked questions:**

- [This is my example question?](#this-is-my-example-question)
- [Another question here?](#another-question-here)
- etc.

## This is my example question?

Answer here...

## Another question here?

Another answer here...


As per my understanding the part (#this-is-my-example-question) makes sure that the question jumps to the right answer by clicking on it (creates an anchor link). This becomes quite a pain in the *** when dealing with tons of anchors. If you'd make a typo in the "URL/Anchor" the link will not jump to the right Heading (question). You'd have to confirm that the link is working properly manually.

My question would be: is there an automatic way to "generate" the anchor link based on the title itself?

Something like this:

# FAQ

**Commonly asked questions:**

- [This is my example question?](?)
- [Another question here?](?)
- etc.

## This is my example question?

Answer here...

## Another question here?

Another answer here...

where (?) would automatically determine the anchor link based on its title so that ? translates to: #this-is-my-example-question. The question symbol could be something else of course, as long as it's compatible/possible. For instance it could be (*) or (#?) or (#*) for that matter.

I hope this explains it better :)
Perhaps there is already a way to do this within the Markdown language that isn't to my knowledge yet. And if not, then perhaps this question/feature request shouldn't be asked here either if such functionality can't be integrated via Docsify.

@jhildenbiddle I understand the basic idea of what you're asking for, but I'm unsure if you want this behavior in the sidebar, the main navigation, to content area, or anywhere in the site. Just in the content area itself.

Thanks!

@jhildenbiddle jhildenbiddle added feature request and removed wait for information something is not clear, waiting for the author of the issue/pr labels Jun 26, 2020
@jhildenbiddle
Copy link
Member

Thanks for the quick feedback, @RensTillmann!

is there an automatic way to "generate" the anchor link based on the title itself?

Yes, but it is unlikely that this is something we would add to docsify.

One of the major selling points of markdown is portability. It's the reason why the same README.md file can be rendered in multiple places (like github.com or npmjs.com) and look completely different. In order for this to work, markdown processors have to abide by rules that determine how markdown should be rendered. There's a basic syntax that everyone supports, then a few extended syntax options that may or may not be supported by your markdown renderer.

The problem with implementing new/custom rendering behaviors into docsify like the one you're describing is that they negatively impact the portability of your markdown files. Instead of writing markdown that works everywhere, you're now writing markdown that works only with docsify.

For example, if you wrote the following markdown:

[My Anchor Link 1]
[My Anchor Link 2](?)

We could add functionality to docsify that treated this as if it were the following:

[My Anchor Link 1](#my-anchor-link-1)
[My Anchor Link 2](#my-anchor-link-2)

And render the following HTML in docsify:

<a href="#my-anchor-link-1">My Anchor Link 1</a>
<a href="#my-anchor-link-2">My Anchor Link 2</a>

But if you rendered that same markdown outside of docsify (for example, on GitHub) here's how it would render:

[My Anchor Link 1]
<a href="?">My Anchor Link 2</a>

To be fair, docsify has a few of these "docsify only" markdown features (like our doc helpers), but the maintainers are revisiting these to determine if we can offer docsify-specific markdown options that don't negatively affect document portability (see #413 for details).

The good news is that the functionality you're asking for could be implemented using a docsify plugin. This is exactly what the plugin system was designed for: to allow others to extend docsify's functionality beyond the core docsify experience.

Hope this helps explain things a bit.

@RensTillmann
Copy link
Author

RensTillmann commented Jun 26, 2020

Thanks for the detailed reply. I totally agree that portability is and should be the priority. I guess I will just stick with the method I am using right (may I ever need to switch to a different processor). After reading the issue (#413) you shared, I noticed that there is a way to make a "Collapse/Accordion" section. I think that this could help me a lot in some cases where I have to put a lengthy FAQ. More details here: https://gist.github.com/pierrejoubert73/902cc94d79424356a8d20be2b382e1ab. The only downside is that you can't anchor to any of the inner content, e.g a heading. You would have to add an id attribute on either the details or summary tag in order to accomplish this. But this is still a much better alternative in my opinion when dealing with a long FAQ. 👍

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

No branches or pull requests

5 participants