Topic: https://brettterpstra.com/2014/07/01/github-toc-service/
hide preview

What's next? verify your email address for reply notifications!

kidpixo 10y, 261d ago

Hi, another great idea :-D I was working on something similar, but just piping the html through simple combination of grep+sed+awk to extract the id from all the header.
I just test your script, but I found a small bug:
the spaces in header are converted to hypen, but the markdown engine in nvalt (or the multimarkdown from macports I use) just delete the spaces.
It results in wrong href in the table of contents!
See an example at this gist.
EDIT
Just changing line 99 from

link = title.gsub(/[^ a-z]/i,'').gsub(/ +/,"-").downcase


to

link = title.gsub(/[^ a-z]/i,'').gsub(/ +/,"").downcase


does the trick for me.

remark link
hide preview

What's next? verify your email address for reply notifications!

kidpixo 10y, 261d ago

Any plan to integrate something like that in nvalt? For long structurated docs it will be really a plus!

remark link parent
hide preview

What's next? verify your email address for reply notifications!

ttscoff 10y, 261d ago

Not really planning many new features for nvALT. Reading in Marked is way better than nvALT can aspire to, and there's a keyboard shortcut in nvALT now for opening the current file in Marked. You can also just drag your notes folder full of text files to Marked, and it will always preview the one you're currently editing.

hide preview

What's next? verify your email address for reply notifications!

ttscoff 10y, 261d ago

Not a bug. That's the format that GitHub uses, and I specifically designed this to make life easier when using the main GitHub site and not the wiki or gh-pages.

On my local machine I have other solutions, most of them automatic. Marked for example, generates both a popup and embeddable TOC for my Markdown reading. http://marked2app.com

nvALT, on the other hand, doesn't have a built in solution, but you can inject JavaScript into the template to do it.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

kidpixo 10y, 261d ago

I see. I really like nvalt becaue I can write and see in the same program (I already have Marked, but I moslty live in nvalt).

Uhm so, I have to write a small JavaScript to do the same stuff as your script, that's a solution. thanks!

remark link parent
hide preview

What's next? verify your email address for reply notifications!

ttscoff 10y, 261d ago

There are a dozen plugins that will do it for you. Just plug the CDN version of jQuery into the template.html file in ~/Library/Application Support/nvALT and add any necessary css to the custom.css file in there.

There's a token you can use when referencing any additional JS files in that folder: {%support%}. That will create an absolute reference to the Application Support path for you.

<script src="file://{%support%}/highlight.pack.js"></script>

remark link parent

load more (1 remarks)
hide preview

What's next? verify your email address for reply notifications!

kidpixo 10y, 261d ago

Thanks for the hints, my nvalt template at github already has jquery.
I'm adapting this code, seems promising. If there is a #toc id in the documents, it appensd a contents list it on the fly.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

kidpixo 10y, 261d ago

Ok, I do added a small javascript fragment in my my nvalt template at github.
Essentially, if you create an element with id='toc' the script attach to it all the document header with indentation proportional to the actual index to document base inde differenca : the base index is h2 tipically, but it could vary.

Thanks for the help!

hide preview

What's next? verify your email address for reply notifications!