• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate a TOC in markdown file

markdown-toc

Build Status Coverage Status MELPA Stable MELPA SWH

Table of Contents

A simple mode to create TOC in a well-formed markdown file.

Note that the TOC is well-formed if the markdown is (cf. #15).

Use

Create

Inside a markdown file, the first time, place yourself where you want to insert the TOC:

M-x markdown-toc-generate-toc

This will compute the TOC and insert it at current position.

You can also execute: M-x markdown-toc-generate-or-refresh-toc to either gnerate a TOC when none exists or refresh the currently existing one.

Here is one possible output:

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
**Table of Contents**

- [Use](#use)
    - [Create](#create)
    - [Update](#update)
    - [Create elsewhere](#create-elsewhere)
- [Install](#install)
    - [emacs package repository](#emacs-package-repository)
        - [Setup](#setup)
            - [melpa stable](#melpa-stable)
            - [melpa](#melpa)
            - [marmalade](#marmalade)
        - [Install](#install)
    - [emacs-lisp file](#emacs-lisp-file)
- [Inspiration](#inspiration)

User toc manipulation

If the user would want to enhance the generated toc, (s)he could use the following function markdown-toc-user-toc-structure-manipulation-fn:

It expects as argument the toc-structure markdown-toc uses to generate the toc. The remaining code expects a similar structure.

Example:

'((0 . "some markdown page title")
  (0 . "main title")
  (1 . "Sources")
  (2 . "Marmalade (recommended)")
  (2 . "Melpa-stable")
  (2 . "Melpa (~snapshot)")
  (1 . "Install")
  (2 . "Load org-trello")
  (2 . "Alternative")
  (3 . "Git")
  (3 . "Tar")
  (0 . "another title")
  (1 . "with")
  (1 . "some")
  (1 . "heading"))

So for example, as asked in #16, one could drop the first element:

(custom-set-variables '(markdown-toc-user-toc-structure-manipulation-fn 'cdr))

Or drop all h1 titles... or whatever:

(require 'dash)
(custom-set-variables '(markdown-toc-user-toc-structure-manipulation-fn
  (lambda (toc-structure)
  (-filter (lambda (l) (let ((index (car l)))
                    (<= 1 index)))
           toc-structure)))

Update

To update the existing TOC, simply execute: M-x markdown-toc-refresh-toc

This will update the current TOC.

Create elsewhere

To create another updated TOC elsewhere, execute M-x markdown-toc-generate-toc again, this will remove the old TOC and insert the updated one from where you stand.

Remove

To remove a TOC, execute M-x markdown-toc-delete-toc.

Customize

Currently, you can customize the following:

  • markdown-toc-header-toc-start
  • markdown-toc-header-toc-title
  • markdown-toc-header-toc-end
  • markdown-toc-indentation-space

Customize them as following format:

(custom-set-variables
 '(markdown-toc-header-toc-start "<!-- customized start-->")
 '(markdown-toc-header-toc-title "**customized title**")
 '(markdown-toc-header-toc-end "<!-- customized end -->")
 '(markdown-toc-indentation-space 4))

Minor mode

markdown-toc-mode provides a minor mode with the following default binding:

(setq markdown-toc-mode-map
      (let ((map (make-sparse-keymap)))
        (define-key map (kbd "C-c m .") 'markdown-toc-follow-link-at-point)
        (define-key map (kbd "C-c m t") 'markdown-toc-generate-or-refresh-toc)
        (define-key map (kbd "C-c m d") 'markdown-toc-delete-toc)
        (define-key map (kbd "C-c m v") 'markdown-toc-version)
        map))

To (de)activate this in an org file: /M-x markdown-toc-mode/

You can also use emacs to setup your own bindings.

Install

emacs package repository

You need to add melpa or melpa-stable package repository before installing it.

Setup

melpa stable

(require 'package)
(add-to-list 'package-archives '("melpa-stable" .
                                 "http://melpa-stable.milkbox.net/packages/"))
(package-initialize)

Then hit M-x eval-buffer to evaluate the buffer's contents.

melpa

(require 'package)
(add-to-list 'package-archives '("melpa" .
                                 "http://melpa.milkbox.net/packages/"))
(package-initialize)

Then hit M-x eval-buffer to evaluate the buffer's contents.

Install

M-x package-install RET markdown-toc RET

emacs-lisp file

Retrieve the markdown-toc.el https://github.com/ardumont/markdown-toc/releases.

Then hit M-x package-install-file RET markdown-toc.el RET

Inspiration

https://github.com/thlorenz/doctoc

The problem I had with doctoc is the installation process. I do not want to install the node tools just for this.

More Repositories

1

org2jekyll

Blogging with org-mode and jekyll without alien yaml headers.
Emacs Lisp
71
star
2

emacs-live-packs

My emacs-live packs the git submodule way.
Emacs Lisp
38
star
3

org

My org-mode files, sources for my blog articles, emails, and other notes.
C
22
star
4

arduino-lab

Mess around with arduino from the comfort of the repl
Clojure
11
star
5

haskell-lab

Hacking Haskell
Haskell
10
star
6

vinyasa

Give your clojure workflow more flow
Clojure
8
star
7

install-packages-pack

emacs-live pack to help in installing emacs packages
Emacs Lisp
7
star
8

emacs-celery

a minor mode to draw stats from celery and more?
Emacs Lisp
3
star
9

docker-lab

Learn some docker love
Shell
3
star
10

clojure-pack

emacs-live pack for clojure
Emacs Lisp
2
star
11

blog-pack

emacs-live blog pack to rapidly post org-mode as wordpress article
Emacs Lisp
2
star
12

prelude-packs

Emacs Lisp
2
star
13

haskell-pack

emacs-live pack packaging haskell setup
Emacs Lisp
1
star
14

js-pack

Emacs Lisp
1
star
15

trello-lab

fool around with trello api
Clojure
1
star
16

clojurescript-pack

emacs-live pack for clojurescript
Emacs Lisp
1
star
17

irc-pack

Emacs Lisp
1
star
18

sh

some shell bin and other configuration files for unix or linux box
Shell
1
star
19

my-joy-of-clojure-lab

Clojure
1
star
20

euler-lab

Resolve the problems from http://projecteuler.net/index.php?section=problems
Clojure
1
star
21

4clojure-lab

4clojure experimentations lab
Clojure
1
star
22

clj-gae

clojure on AppEngine - test
Clojure
1
star
23

lisp-pack

emacs-live pack for lisp
Emacs Lisp
1
star
24

mail-pack

pack for setuping email accounts in emacs through a simple authinfo.gpg
Emacs Lisp
1
star
25

modeline-pack

tweak the emacs modeline pack
Emacs Lisp
1
star
26

.xmonad

personal .xmonad rebuildable
Haskell
1
star
27

emacs-creds

A small lib to parse creds file
Emacs Lisp
1
star
28

ardumont.github.io

Source code for ardumont.github.io
HTML
1
star