dillinger icon indicating copy to clipboard operation
dillinger copied to clipboard

Moar github compatibility: Header Anchors

Open mmterpstra opened this issue 8 years ago • 6 comments

Question

Can you add header anchors to markdown-it? Because of the github support if it would be nice if you also do it.

Possible solution

This is on of the markdown-it plugins that will allow to add heading anchors to the headers and thus solve the problem. https://www.npmjs.com/package/markdown-it-headinganchor

What you can do with the new support:

### TOC

1. [TOC](#toc)
1. [Question](#question)
1. [Possible solution](#possible-solution)

Renders to :

TOC

  1. TOC
  2. Question
  3. Possible solution

although it does not work on issues it works on other .md files,examples of it working: https://github.com/mmterpstra/DigitalBarcodeReadgroups#integrate-the-barcode-into-reads https://github.com/ndaniel/fusioncatcher/blob/master/doc/manual.md#11---license

mmterpstra avatar Jun 28 '16 08:06 mmterpstra

appears this needs to just add the markdown-it plugin to the build/bundle?

On Tue, Jun 28, 2016 at 4:42 AM, mmterpstra [email protected] wrote:

Question

Can you add header anchors to markdown-it? Because of the github support if it would be nice if you also do it. Possible solution

This is on of the markdown-it plugins that will allow to add heading anchors to the headers and thus solve the problem. https://www.npmjs.com/package/markdown-it-headinganchor

What you can do with the new support:

TOC

  1. TOC1. Question1. Possible solution

Renders to ( works better with longer pages, so i inserted some useless
at the end): TOC

  1. TOC <#m_1696222522750710626_toc>
  2. Question <#m_1696222522750710626_question>
  3. Possible solution <#m_1696222522750710626_possible-solution>

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/joemccann/dillinger/issues/552, or mute the thread https://github.com/notifications/unsubscribe/AAC8aisPwXGoG2EmCo5nGU4TBq4H9LVDks5qQN5rgaJpZM4I_3rK .

joemccann avatar Jun 28 '16 14:06 joemccann

Yes, but a few thing need to be tested.

  • Working achors
  • The achor links work in the preview and do not mess up scrolling
  • Check for reserved things on http://dillinger.io/# ...
  • maybe insert an example in the example doc and test it.(see below)
### Table of contents

1. [Table of contents](#table-of-contents)
2. [Dillinger](#dillinger)
   1.  [Version](#version)
   2. [Tech](#tech)
   3. [Installation](#installation)
   4. [Plugins](#plugins)
   5. [Development](#development)
   6. [Docker](#docker)
   7. [N|Solid and NGINX](#n-solid-and-nginx)
   8. [docker-compose.yml](#docker-compose.yml)
   9. [Todos](#todos)

mmterpstra avatar Jun 28 '16 18:06 mmterpstra

This seems to work fine on Dillinger.io?

joemccann avatar Aug 16 '16 14:08 joemccann

I did not test it because I did not have time/experience to set this up/test this I hoped the community would pick this up.

If you like it you could add this to the site.

mmterpstra avatar Aug 23 '16 10:08 mmterpstra

yeah this doesn't work currently but I'm sure there's some JavaScript wizardry to fix this.

joemccann avatar Sep 06 '16 22:09 joemccann

I ran into this when I used RedCarpet, the Ruby Markdown library. Wasn't so much header anchors, just anchors in general didn't work.

This is essentially what I came up with:

    def link(url, title, text)
      if url.start_with?("id:")
        %(<span id="#{url.split(":").last}">#{text}</span>)
      else
        %(<a href="#{url}" title="#{title}">#{text}</a>)
      end
    end

So with this, I could write:

(in table of contents)
### [Getting Started](#getting_started)

(in actual document)
## [Getting Started](id:getting_started)

And be able to click the first link to drop down to that header in the document.

I realize that's ruby, but it's something. 😄

NOTE: I've been told that in the HTML5 spec, using "id=" like I did can actually break javascript (somehow), and to use "name=" instead. Thing is, that's been deprecated in XHTML.

sneakernets avatar Nov 28 '16 17:11 sneakernets