Giter Site home page Giter Site logo

naokazuterada / markdowntoc Goto Github PK

View Code? Open in Web Editor NEW
300.0 10.0 48.0 57.34 MB

SublimeText3 plugin which generate a table of contents (TOC) in a markdown document.

Home Page: https://packagecontrol.io/packages/MarkdownTOC

License: MIT License

Python 100.00%
toc-generator markdown sublime-text-3 python

markdowntoc's Introduction

MarkdownTOC

Demo animation of the toc generation

MarkdownTOC

Sublime Text 3 plugin for generating a Table of Contents (TOC) in a Markdown document.

Linux and macOS Build Status Windows Build Status codecov Package Control Gitter chat


Note: v3.0.0 has breaking changes. See Upgrade Guide for more detail.


Table of Contents

Click to open TOC

Quick Start

  1. Install the MarkdownTOC plugin
  2. Open your Markdown file
  3. Place the cursor at the position where you want to insert the TOC
  4. Pick from menu: Tools > MarkdownTOC > Insert TOC
  5. And the TOC is inserted in the Markdown document
  6. Save the document and you are done

Now you can go on and edit your document further or you can customize you TOC, please read on.

Features

The MarkdownTOC plugin is rich on features and customization, useful for both work on a single Markdown document or if you have several Markdown documents that require special TOC generation.

Insertion of TOC based on headings in Markdown document

When you have completed the installation of the plugin, you can insert an automatically generated TOC based on your Markdown headings. See the Quick Start to get going or the Usage section for details on how to utilize customization and configuration.

For the following sample Markdown document:

# Heading 0

Headings before MarkdownTOC tags will be ignored.

◀ place the cursor here and generate the TOC

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

The MarkdownTOC plugin will out of the box generate:

# Heading 0

Headings before MarkdownTOC tags will be ignored.

<!-- MarkdownTOC -->

- Heading 1
  - Heading 2

<!-- /MarkdownTOC -->

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

As you can read from the sample above:

  1. Headings above the MarkdownTOC tag section are ignored, only the rest of the document is considered in scope

Automatic refresh of TOC when Markdown document is saved

If we edit the Markdown document some more and add an additional heading:

## Heading 3

When we save the document, the TOC is automatically updated.

<!-- MarkdownTOC -->

- Heading 1
  - Heading 2
  - Heading 3

<!-- /MarkdownTOC -->

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

## Heading 3
Lorem ipsum... (the added text)

Same goes for deleted headings, these are cleared out.

Updating the TOC can also be accomplished without saving by picking from the menu: Tools > MarkdownTOC > Update TOC

Supported file extensions

Make sure your file's extension is in the following list.

.md .markdown .mdown .mdwn .mkdn .mkd .mark

Customizing generation of TOC using attributes

<!-- MarkdownTOC autolink="true" -->

- [Heading 1](#heading-1)
  - [Heading 2](#heading-2)
  - [Heading 3](#heading-3)

<!-- /MarkdownTOC -->

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

## Heading 3
Lorem ipsum... (the added text)
  1. TOC tags can overwrite default attributes using local settings and influence the rendering of the TOC. See: Configuration on how to set your own defaults for the plugin
  2. Headings can be automatically linked (see: auto link)
  3. Headings can have anchors automatically linked (see: Auto anchoring when heading has anchor defined)

The default behaviour could also be described as:

<!-- MarkdownTOC levels="1,2,3,4,5,6" autolink="false" bracket="round" autoanchor="false" style="unordered" indent="\t" -->

Please see: Github Configuration for a guideline to configuring MarkdownTOC for Github use.

Auto anchoring when heading has anchor defined

You can add an HTML anchor (<a name="xxx"></a>) before your heading automatically.

# Heading with anchor [with-anchor]

The TOC generation can be specified to respect this and a TOC element of the following format is generated:

- [Heading with anchor](#with-anchor)

Please note that the default for the attribute: autoanchor is false.You can add an HTML anchor (<a name="xxx"></a>) before the heading automatically.

<!-- MarkdownTOC autolink="true" autoanchor="true" -->

- [Changelog](#changelog)
- [Glossary](#glossary)
- [API Specification](#api-specification)

<!-- /MarkdownTOC -->

<a name="changelog"></a>
# Changelog
Lorem ipsum...

<a name="glossary"></a>
# Glossary
Lorem ipsum...

<a name="api-specification"></a>
# API Specification
Lorem ipsum...

Please note that the default for autolink is false defined by the attribute defaults.autoanchor. See also: How to remove anchors added by MarkdownTOC.

Auto linking for clickable TOC

The plugin can be specified to auto link heading so you get a TOC with clickable hyperlink elements.

The following sample document:

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

## Heading 3
Lorem ipsum...

With autolink set to true will render the following:

<!-- MarkdownTOC autolink="true" -->

- [Heading 1](#heading-1)
  - [Heading 2](#heading-2)
  - [Heading 3](#heading-3)
  - [Heading 4](#heading-4)
- [Heading with anchor](#with-anchor)

<!-- /MarkdownTOC -->

The auto link markup style can be one of:

Please note that the default for autolink is false defined by the attribute defaults.autolink.

<!-- MarkdownTOC autolink="false" -->

- MarkdownTOC Plugin for Sublime Text
  - Feature
  - Feature
  - Feature

<!-- /MarkdownTOC -->
<!-- MarkdownTOC autolink="true" -->

- [MarkdownTOC Plugin for Sublime Text](#markdowntoc-plugin-for-sublime-text)
  - [Feature](#feature)
  - [Feature](#feature-1)
  - [Feature](#feature-2)

<!-- /MarkdownTOC -->

round: according to Github style.

<!-- MarkdownTOC bracket="round" -->

- [Heading](#heading)

<!-- /MarkdownTOC -->

square: according to "Markdown standard reference-style links".

<!-- MarkdownTOC bracket="square" -->

- [Heading][heading]

<!-- /MarkdownTOC -->

Please note that the default for bracket is round defined by the attribute defaults.bracket.

Lowercasing in ids

By default the plugin lowercases ASCII based alphabets only (a to z) for auto links.

<!-- MarkdownTOC autolink="true" -->

- [ПРИМЕР EXAMPLE][ПРИМЕР-example]

<!-- /MarkdownTOC -->

# ПРИМЕР EXAMPLE

This is same as setting lowercase attribute to only_ascii.

<!-- MarkdownTOC autolink="true" lowercase="only_ascii" -->

- [ПРИМЕР EXAMPLE][ПРИМЕР-example]

<!-- /MarkdownTOC -->

# ПРИМЕР EXAMPLE
Preserve case

You can disable the lowercasing capability by setting the lowecase attribute to false.

<!-- MarkdownTOC autolink="true" lowercase="false" -->

- [One Two Three][One-Two-Three]

<!-- /MarkdownTOC -->

# One Two Three
Lowercase all characters

Further more you can also expand the lowercasing capability by setting the lowercase attribute to all(or any values other than false and only_ascii).

<!-- MarkdownTOC autolink="true" lowercase="all" -->

- [ПРИМЕР EXAMPLE][пример-example]

<!-- /MarkdownTOC -->

# ПРИМЕР EXAMPLE

You can also specify this in your configuration with key defaults.lowercase.

Manipulation of auto link ids

You can manipulate your link ids in your configuration using the key id_replacements.

{
  "id_replacements": [
    {
      "pattern": "\\s+",
      "replacement": "-"
    },
    {
      "pattern": "!|#|$|&|'|\\(|\\)|\\*|\\+|,|/|:|;|=|_|\\?|@|\\[|\\]|`|\"|\\.|<|>|{|}|™|®|©|&lt;|&gt;|&amp;|&apos;|&quot;|&#60;|&#62;|&#38;|&#39;|&#34;",
      "replacement": ""
    }
  ]
}
  1. Regular expression is allowed in each sets
    • It will be simply expanded into python's re.sub(pattern, replacement, id)
  2. The replacement sequence executes from top to bottom

An example:

# Super Product™

This heading link of this heading is changed to following id

#super-product
  • The ' ' (space) is replaced with - (dash), since ' ' is included in the first set
  • The '™' is replaced with nothing, since '™' is included in the second set

URI encoding

By default non-ASCII characters in link ids are URL encoded.

<!-- MarkdownTOC autolink="true" -->

- [Ejemplos de español](#ejemplos-de-espa%C3%B1ol)
- [日本語の例](#%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%81%AE%E4%BE%8B)
- [Примеры русского](#%D0%9F%D1%80%D0%B8%D0%BC%D0%B5%D1%80%D1%8B-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D0%B3%D0%BE)
- [**的例子](#%E4%B8%AD%E5%9B%BD%E7%9A%84%E4%BE%8B%E5%AD%90)

<!-- /MarkdownTOC -->

# Ejemplos de español
# 日本語の例
# Примеры русского
# **的例子

As mentioned you can disable this by setting the uri_encoding attribute to false, like so: uri_encoding="false".

<!-- MarkdownTOC autolink="true" uri_encoding="false" -->

- [Ejemplos de español](#ejemplos-de-español)
- [日本語の例](#日本語の例)
- [Примеры русского](#Примеры-русского)
- [**的例子](#**的例子)

<!-- /MarkdownTOC -->

# Ejemplos de español
# 日本語の例
# Примеры русского
# **的例子

Markdown Preview compatible

If you want to use MarkdownTOC with Markdown Preview, you should use markdown_preview attribute. You can set this attribute to either markdown or github.

When you set it to markdown, you can get same links rendered by MarkdownPreview's markdown parser.

<!-- MarkdownTOC autolink="true" markdown_preview="markdown" -->

- [Hello 世界 World](#hello-world)
- [ESPAÑA](#espana)
- [ПРИМЕР RUSSIAN](#russian)

<!-- /MarkdownTOC -->

# Hello 世界 World
# ESPAÑA
# ПРИМЕР RUSSIAN

When you set it to github, you can get same links rendered by MarkdownPreview's github parser.

<!-- MarkdownTOC autolink="true" markdown_preview="github" -->

- [Hello 世界 World](#hello-%25E4%25B8%2596%25E7%2595%258C-world)
- [ESPAÑA](#espa%25C3%25B1a)
- [ПРИМЕР RUSSIAN](#%25D0%25BF%25D1%2580%25D0%25B8%25D0%25BC%25D0%25B5%25D1%2580-russian)

<!-- /MarkdownTOC -->

# Hello 世界 World
# ESPAÑA
# ПРИМЕР RUSSIAN

Currently no other parsers are supported.

If you want to disable this feature, set it to false.

Link Prefix

You can also set prefix of links.

<!-- MarkdownTOC autolink=true link_prefix="user-content-" -->

- [My Heading](#user-content-my-heading)

<!-- /MarkdownTOC -->

# My Heading

You can manipulate this in your configuration using the key defaults.link_prefix.

Control of levels listed in TOC

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

### Heading 3
Lorem ipsum...

#### Heading 4
Lorem ipsum...

With default levels:

<!-- MarkdownTOC -->

- Heading 1
  - Heading 2
    - Heading 3
      - Heading 4

<!-- /MarkdownTOC -->

With levels set to 1,2:

<!-- MarkdownTOC levels="1,2" -->

- Heading 1
  - Heading 2

<!-- /MarkdownTOC -->

Please note that the default for the attribute levels is "1,2,3,4,5,6", it means all heading sizes will be included.

You can also specify this in your configuration with key defaults.levels.

The maximum size for headings is 6 according to the Markdown specification

Ordered or unordered style for TOC elements

The plugin supports two styles of TOC element listing:

  • unordered
  • ordered

A Markdown document with the following contents:

# Heading 1
Lorem ipsum...

## Heading 2
Lorem ipsum...

### Heading 3
Lorem ipsum...

### Heading 4
Lorem ipsum...

## Heading 5
Lorem ipsum...

# Heading 6
Lorem ipsum...

Will with style unordered:

<!-- MarkdownTOC style="unordered" -->

- Heading 1
  - Heading 2
    - Heading 3
    - Heading 4
  - Heading 5
- Heading 6

<!-- /MarkdownTOC -->

And with style ordered:

<!-- MarkdownTOC style="ordered" -->

1. Heading 1
  1. Heading 2
    1. Heading 3
    1. Heading 4
  1. Heading 5
1. Heading 6

<!-- /MarkdownTOC -->

Please note that the default for the attribute is: unordered.

You can set your default style in your configuration with the key defaults.style.

Customizable list bullets in TOC

You can define the list items used for the TOC for each level. The first item is for the first level, the second for the second and so on until the last one of the list and then it starts over from the beginning.

<!-- MarkdownTOC bullets="-,+,*" -->

- foo
  + bar
    * baz
      - foo
        + bar
          * baz

<!-- /MarkdownTOC -->

You can set default list bullets in your configuration with the key defaults.bullets.

The example above could also be described as:

{
  "defaults": {
    "bullets": ["-","+","*"]
  }
}

You can also set it in attribute. In this case the values type is 'conmma separated string'.

<!-- MarkdownTOC bullets="-,+,*" -->

Specify custom indentation prefix

The indentation prefix is a specification of the string used to indent the TOC elements.

An ugly but demonstrative example could be to use an emoji.

<!-- MarkdownTOC autolink="true" indent=":point_right: " -->

- [Heading 1](#heading-1)
:point_right: - [Heading 2](#heading-2)
:point_right: :point_right: - [Heading 3](#heading-3)
:point_right: :point_right: - [Heading 4](#heading-4)
:point_right: - [Heading 5](#heading-5)
- [Heading 6](#heading-6)

<!-- /MarkdownTOC -->

Please note that the default for the attribute is: '\t'.

You can set your default indentation in your configuration with the key defaults.indent.

Preserve images in headings

If you want to preserve images in headings, set remove_image to false.

<!-- MarkdownTOC remove_image="false" -->

- ![check](check.png) Everything is OK

<!-- /MarkdownTOC -->

# ![check](check.png) Everything is OK

Please note that the default for the attribute is: false.

<!-- MarkdownTOC -->

- Everything is OK

<!-- /MarkdownTOC -->

# ![check](check.png) Everything is OK

You can change your default setting in your configuration with the key defaults.remove_image.

Excluded headings

You can exclude certain headings in the TOC by adding a special comment to the line above the line with the heading, as shown below.

<!-- MarkdownTOC:excluded -->
## This heading will be excluded

Usage

  1. Open your Markdown file
  2. Set cursor to position where you want to insert a TOC
  3. Pick from menu: Tools > MarkdownTOC > Insert TOC
  4. TOC is inserted in document
  5. Evaluate your TOC and customize using attributes or configuration
  6. Update contents and save...
  7. TOC has been updated

Don't remove the comment tags if you want to update every time saving.

Tips

How to remove anchors added by MarkdownTOC

If you want to remove the TOC again, you do not have to go through your complete Markdown and remove all tags manually - just follow this simple guide (see also: Auto anchoring when heading has anchor defined).

  1. Open your Markdown file
  2. Set the attribute autoanchor to false, this clears all anchors
<!-- MarkdownTOC autoanchor="false" -->

Please see the below animation demonstrating the change

Demo animation of removal of toc

  1. Now delete the TOC section from beginning to end and **MarkdownTOC** integration is gone
<!-- MarkdownTOC autoanchor="false" -->

...

<!-- /MarkdownTOC -->

Ref: Github issue #76

Addressing issues with Github Pages

If you are using Github Pages you might experience that some themes do not render heading correctly.

This can be addressed simply by setting autoanchor to false

<!-- MarkdownTOC autoanchor="false" -->

And when Jekyll is done, your headings should render correctly.

Ref: Github issue #81

Using MarkdownTOC with Markdownlint

If you are using Markdownlint (Node implementation), it will report several violations out of the box.

The basic configuration you can use to address these looks like the following:

{
    "html": false,
    "blanks-around-headings": false,
    "ul-indent": {
        "indent": 4
    }
}
  • html set to false, to allow use of HTML since MarkdownTOC relies on HTML tags to assist the Markdown
  • blanks-around-headings should be set to false, since anchors are places closed to the headings that are listed in the TOC
  • ul-indent should have it's parameter indent set to 4 to adhere with the default of 4 used by MarkdownTOC, whereas Markdownlint defaults to 2

If you have configured MarkdownTOC differently, you can adjust your Markdownlint configuration accordingly.

Do note that this tip is based on the Node implementation, available on GitHub, which uses a project specific .markdownlint.json based configuration.

Limitations

MarkdownTOC does come with some limitations.

For more information on compatibility, please see the dedicated section.

Headings in lists are not included in the auto-generated table of contents

Example of Markdown heading in a Markdown listing, not being included in the auto-generated Table of Contents

- # this is a heading

Attributes

The following attributes can be used to control the generation of the TOC.

attribute values default
autoanchor trueorfalse false
autolink trueorfalse false
bracket "round"or"square" "round"
indent string "\t"
levels string (decimal list separated with ,) "1,2,3,4,5,6"
link_prefix string ""
bullets string "-"
lowercase "all"or"only_ascii"or"false" "only_ascii"
remove_image trueorfalse true
style "ordered" or "unordered" "unordered"
uri_encoding trueorfalse true
markdown_preview ""or"github"or"markdown" ""

You can define your own default values via package preferences, Sublime Text's way of letting users customize package settings. Please see the Section on Configuration for more details for MarkdownTOC.

Installation

Using Package Control

  1. Run “Package Control: Install Package” command, find and install MarkdownTOC plugin.
  2. Restart Sublime Text

Package Control

From Git

git clone [email protected]:naokazuterada/MarkdownTOC.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/MarkdownTOC

From downloadable archive

  1. Download zip-file and unpack it.
  2. Open the Sublime Text Packages/ directory (pick menu: Sublime Text > Preferences > Browse Packages).
  3. Move the MarkdownTOC/ directory into the Packages/ directory.

Configuration

You can use attributes to customize a TOC in a single Markdown document, but if you want to keep the same TOC configuration accross multiple Markdown documents, you can configure your own defaults.

Pick: Sublime Text > Preferences > Package Settings > MarkdownTOC > Settings - User

Alternatively you can create the file ~/Library/Application Support/Sublime Text 3/Packages/User/MarkdownTOC.sublime-settings by hand.

Example: MarkdownTOC.sublime-settings

{
  "defaults": {
    "autolink": true,
    "bracket": "square",
    "levels": "1,2",
    "indent": "    ",
    "remove_image": false,
    "bullets": "*",
    "style": "ordered"
  },
  "id_replacements": [
    {
      "pattern": "\\s+",
      "replacement": "-"
    },
    {
      "pattern": "&lt;|&gt;|&amp;|&apos;|&quot;|&#60;|&#62;|&#38;|&#39;|&#34;|!|#|$|&|'|\\(|\\)|\\*|\\+|,|/|:|;|=|_|\\?|@|\\[|\\]|`|\"|\\.|<|>|{|}|™|®|©",
      "replacement": ""
    }
  ]
}

Please see the section on attributes for an overview of values and the section on customization.

Configuration precendence is as follows:

  1. Attributes specified in MarkdownTOC begin tag (see: Customizing generation of TOC using attributes)
  2. MarkdownTOC Settings - user (this section)
  3. MarkdownTOC Settings - default (see: Attributes)

For an overview of the specific behaviour behind an attribute, please refer to the below list.

Github Configuration

A configuration for writing Markdown primaily for use on Github could look like the following:

{
  "defaults": {
    "autolink": true,
    "bracket": "round",
    "lowercase": "only_ascii"
  }
}

Configuration and Collaboration

You should be aware that if you collaborate with other Markdown writers and users of MarkdownTOC, you might have changes going back and forth simply due to differing configurations.

If that is the case and you cannot agree on a configuration, choose configuration using attributes specified in the document instead.

Example of attribute configuration for the above configuration settings in file:

<!-- MarkdownTOC autolink="true" bracket="round" autoanchor="true" -->

Compatibility

This is by no means an exhaustive list and you are welcome to provide additional information and feedback. Here is listed what Markdown rendering platforms and tools where compatibility and incompatibily has been asserted with the MarkdownTOC plugin.

Application Compatibility
Github Compatible
Gitblit 1.6.x Incompatible
Gitlab 8.10.x Compatible
BitBucket 5.12.2 Incompatible

Contributing

Contributions are most welcome, please see the guidelines on contributing.

License

Author

References

Markdown Table of Contents Generators

Here follows a list of other Markdown Table of Contents generators, for inspiration and perhaps even use in the situation where the MarkdownTOC Sublime Text plugin is not the right tool for the job. Please note that the list is by no means authoritative or exhaustive and is not a list of recommendations, since we can only endorse MarkdownTOC our contribution to the Markdown Table of Content generators toolbox.

  • doctoc Node (npm) implementation with CLI interface
  • markdown-toclify Python implementation with CLI interface

Recommended plugins for use with MarkdownTOC

markdowntoc's People

Contributors

ddidier avatar gitter-badger avatar in4lio avatar jonasbn avatar kthakar avatar mariohuq avatar math2001 avatar naokazuterada avatar nickhstr avatar orthographic-pedant avatar sjml avatar terminalfi avatar theskumar avatar ziembla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdowntoc's Issues

Don't change case in Auto-link feature

Is it possible to add one more configuration option?
Almost everything can be customized, except that auto-anchors are lowercase.
Can you make that optional? With one simple flag in settings?

I need auto-anchors like "One_Two_Three", and not like "one_two_three".
Thanks in advance.

Auto linking (w/ anchor) syntax issue

Hi,
I see and tried the auto-link-fill feature where we can add an "[with-anchor]" with one header.
But obviously, this "[with-anchor]" style will be consider as the mark of an inline link of that header line and will be shown in the export file whereas the TOC part just extract it as id but not use its context. So, it go against the markdown's syntax. And this cause the cool feature become useless.

Thanks
ray

Autolinking isn't working

Hi!

I've just downloaded a plugin to my sublime text 3 via package control. It seems that autolinking isn't correctly working, looks like a bug, here's what I have generated:

- [a][a]
    - [b][b]
    - [c][c]
        - [d][d]
        - [e][e]

shouldn't it be like [a](#a)? and my custom settings are:

{
  "default_autolink": true,
  "default_depth": 3,
  "default_autoanchor": true
}

Thank you!.

Add regex support for id replacement?

This plugin is so great, but I have some problem to use this plugin with GitLab.

GitLab has its own markdown syntax called GitLab Flavored Markdown. When render markdown into html, there are several problem:

  1. Header's anchor id is generated by its value, but all non-ascii characters(like chinese character) will be trimmed. For example:
    # 1. Hello World will has an id 1-hello-world
    # 1. Hello 世界 World will also has id 1-hello-world, "世界" is trimmed.
    So if I want this plugin support gitlab, I must add all chinese characters(6,000 at least) to id_replacements settings, it's impossible.
  2. Another way is set autoanchor=true, this will add an <a name="anchor-id"></a>, but I don't know why, this tag is ignored when render to html.

So I thought that maybe id_replacements could add regex support, so that I could use just one regex to match all characters I need, just like this:

for _substitute, pattern in regex_replacements.iteritems():
    _str = re.sub(pattern, _substitute, _str)

Allow custom string before TOC links

Hi there I want to suggest an option to insert a custom string into the TOC links.

Generally, the links are fine: [Section](#section) points to the heading "Section".

But my articles are also listed on an index page, and the TOC is visible on the index page. When shown on the index page, the TOC links would not work because they point to a non-existent heading.

I'd like to be able to add a string, {{site.baseurl}}{{page.url}}/ to the link, so that the TOC link would look like

[Section]({{site.baseurl}}{{page.url}}/#section)

Then when clicked on the index page the link would point to the correct position in the article.

'cannot find TOC tags' err when insert new TOC

Hi team,

After I installed MarkdownTOC on sublimetext 3 and then tried to inert new TOC, I got this err:

'cannot find TOC tags'

Traceback (most recent call last):
  File "Y:\Dev\Sublime Text 3\sublime_plugin.py", line 556, in run_
    return self.run(edit)
  File "MarkdownTOC in Y:\Dev\Sublime Text 3\Data\Installed Packages\MarkdownTOC.sublime-package", line 40, in run
TypeError: Can't convert 'bool' object to str implicitly

But I have successfully installed MarkdownTOC on my another PC and it works fine.

Could you pls help with this?

Add Github TOC option?

Currently the package generates a TOC entry as:

- [the section title][the-section-title]

Github's README.md files support the following format:

- [the section title](#the-section-title)

the default way won't work. Couldn't an option be added to generate TOC's using Github's format?

Allow to include images in titles

Hi !

When writing technical documentations with markdown, I often have an image in my titles (the icon of the tool the section describes). I'd love to be able to display that image in the TOC.

For now this

## Reference

### ![Load data icon](images/icon_import.png) Load data

becomes this in the TOC

- Reference
    - !Load data icon Load data

Thanks !

リスト階層構造の自動調整

目次の最初のheadingのインデント量をルートに設定して、それ以降から天引きにしているが、タグの中に変数の用に持たせた方が良いかも。

<!-- MarkdownTOC root=## -->

みたいな感じ?

リスト階層構造の自動調整機能

headingの階層構造がちゃんとh1>h2>h3のように順番通りになっていなくても、インデントをうまい具合に調整してくれる機能をもたせるかどうか。

現状、下記のように揃っていないと、うまくリストにならないときがある。

# aaa
### aaaa

TOC can't extract <a> tag from headings?

i usually add anchor along with headings like below:

## my heading <a name="myAnchor"></a>

then insert TOC using markdownTOC, the result is:

<!-- MarkdownTOC depth=0 autolink -->

- [my heading <a name="myAnchor"></a>](#my-heading-<a-name"myanchor"><a>)

<!-- /MarkdownTOC -->

## my heading <a name="myAnchor"></a>

that's not what i want, i expect things like below:

<!-- MarkdownTOC depth=0 autolink -->

- [my heading <a name="myAnchor"></a>](#myAnchor)

<!-- /MarkdownTOC -->

## my heading <a name="myAnchor"></a>

any ideas? thx.

Update not working

I'm pretty sure there's something wrong with my setup, I just can't find what.

MarkdownTOC works great for me only for TOC creation, i.e. Insert TOC works fine. However, Update TOC stays always greyed out, and the TOC won't change if I change headers.

Any idea what could be going on?

I'm using the latest version of MarkdownTOC (2014.05.08.15.45.04), on ST3 (b3059).

Depth control bug

Now depth depends on heading level, but it should depends on list depth on TOC.


Now

<!-- MarkdownTOC depth=1 -->

<!-- /MarkdownTOC -->


## haeding

## haeding

it should be...

<!-- MarkdownTOC depth=1 -->

- haeding
- haeding

<!-- /MarkdownTOC -->


## haeding

## haeding

Limitation level of headings

[ idea from @bobef on #51 ]

It limits heading level in TOC.

<!-- MarkdownTOC depth_min=2 depth_max=3 -->

- Heading 2
- Heading 3

<!-- /MarkdownTOC -->

# Heading 1
...

## Heading 2
...

### Heading 3
...

### Heading 4
...

<!-- MarkdownTOC depth_min=2 -->

- Heading 2
- Heading 3
- Heading 4

<!-- /MarkdownTOC -->

# Heading 1
...

## Heading 2
...

### Heading 3
...

#### Heading 4
...

Auto-update on save for extensions other than .md

I would very much like that my html files with markdown (and markdown TOC) inside would benefit from auto-updating on save… Or any other extension for that matter (pandoc insists on .markdown extension for example).
Thanks,

Pascal

ValueError when setting autoanchor to true

Hi,

I am using sublime text 2.0.2 with the following MarkdownTOC.sublime-settings:

{
  "default_autolink": true,
  "default_bracket": "round",
  "default_depth": 0,
  "id_replacements": {
    "-": " ",
    "" : ["!","#","$","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]","`","\"", ".","<",">","{","}","™","®","©"]
  },
  "default_autoanchor": true,
  "default_style": "ordered"
}

TOC gets built with "default_autoanchor" : false, but when setting it to true, the following output appears in the console:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./MarkdownTOC.py", line 40, in run
    toc += self.get_toc(attrs, sel.end(), edit)
  File "./MarkdownTOC.py", line 232, in get_toc
    self.update_anchors(edit, items, bool(attrs['autoanchor']))
  File "./MarkdownTOC.py", line 248, in update_anchors
    new_anchor = '\n<a name="{}"></a>'.format(item[3])
ValueError: zero length field name in format

Any help would be appreciated.

cheers,

dom

min() arg is an empty sequence

When i try to insert TOC i get the following error:
min() arg is an empty sequence

I insert it in the following markdown code:

Markdown plugin

deloverskrift

deloverskrift

deloverskrift

Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
return self.run(edit)
File ".\MarkdownTOC.py", line 28, in run
File ".\MarkdownTOC.py", line 105, in get_TOC
File ".\MarkdownTOC.py", line 147, in format
ValueError: min() arg is an empty sequence

list number incroee

below is th toc , so you can see the problem

1. [json交互时返回的通用格式](#json交互时返回的通用格式)
2. [各页面详细说明](#各页面详细说明)
    1. [首页](#首页)
        1. [功能说明](#功能说明)
        2. [场景](#场景)
            1. [打开](#打开)
    3. [产品搜索](#产品搜索)
        4. [功能说明](#功能说明-1)
        5. [场景](#场景-1)
            1. [打开](#打开-1)
    6. [注册登陆页](#注册登陆页)
        7. [功能说明](#功能说明-2)
        8. [场景](#场景-2)
            1. [打开](#打开-2)
            2. [用户名验证](#用户名验证)
            3. [登陆](#登陆)
            4. [验证码验证](#验证码验证)
            5. [注册](#注册)
            6. [忘记密码](#忘记密码)
    9. [详情页](#详情页)
        10. [功能说明](#功能说明-3)
        11. [场景](#场景-3)
            1. [打开](#打开-3)
            2. [供应商查询](#供应商查询)
            3. [产品评价](#产品评价)
    12. [ 二级类页](#-二级类页)
    2. [搜索结果页](#搜索结果页)
        1. [功能说明](#功能说明-4)
        2. [场景](#场景-4)
            1. [搜索](#搜索)


Module distutils.util is unavailable in sublime text 2.

Reloading plugin ~/.config/sublime-text-2/Packages/MarkdownTOC/MarkdownTOC.py
Traceback (most recent call last):
  File "./sublime_plugin.py", line 62, in reload_plugin
  File "./MarkdownTOC.py", line 5, in <module>
    import distutils.util
ImportError: No module named distutils.util

Multiple TOCs in the MD

Hi. Thanks for the great plugin. It is very useful to me. I'd like to make a feature request.

It would be very useful to be able to have multiple tocs. When I insert one toc it shows the headers after the place the toc is inserted. This is very useful. But I need to be able to insert multiple tocs. The use case is this. I have some pretty long documents (javascript api docs). I want to have toc at the top and then toc for different sections. So on the top the toc won't be mile long and when you go to a specific section you can navigate to the subsections. Right now I achieve this by enabling full depth of the toc headers in the config and then I copy-paste manually from the main toc to the sections. Needless to say I have to keep track manually and update all sections when I change them.

And this brings me to the second part - it would be very useful to be able to specify options per TOC. The options that normally go in the sublime config like "default_depth": 6. I imagine something like <!-- MarkdownTOC 3-7 --> which would mean "generate toc here for the headers level 3-7 starting from this point of the document". This way one can maintain sections easily.

Regards,
Bobi

Editing disabled after usage

Text insertion / deletion is disabled for my Markdown document in Sublime Text after using either "Insert" or "Update". E.g.

  1. create simple document
  2. use "insert toc" command
  3. press letter "a"
  4. NO letter "a" is inserted in document

Expected to be able to edit immediately after using TOC plugin.

To workaround, initiate a "Find" command (Command + F) then cancel it (ESC).

Using current release build of ST 3.

Use external TOC generator

[EDIT] different TOC tool. Other one was not suitable.

The way this tool hooks into Sublime is very neat. Unfortunately, the same cannot be said for the TOC generation itself.

It would be easier to just replace the inside TOC generation to be calling this other tool:

https://github.com/thlorenz/doctoc

That one is already implemented and work very well to generate markdown TOC.
Mant thanks.

Looks like something changed .. now getting following error on Insert TOC ..

Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run_
File "./MarkdownTOC.py", line 36, in run
File "./MarkdownTOC.py", line 123, in get_toc
RuntimeError: Missing } in quantified repetition. The error occured while parsing the regular expression fragment: '=+)$|^#{1,>>>HERE>>>None}[^#]'. in regular expression ^.*?(?:(?:
)|
|
)(?:-+|=+)$|^#{1,None}[^#]

line 123(and around it ) ... this is straight from github version pulled 15' ago. ..

# TODO: add "end" parameter
def get_toc(self, attrs, begin):

    # Search headings in docment
    if attrs['depth'] == 0:
        pattern_hash = "^#+?[^#]"
    else:
        pattern_hash = "^#{1," + str(attrs['depth']) + "}[^#]"
    headings = self.view.find_all(
        "%s|%s" % (pattern_h1_h2_equal_dash, pattern_hash))  # <-- line 123 is here ..

    headings = self.remove_items_in_codeblock(headings)

Does not work with GFM

The following MD

#Test
...

results in

<ul>
<li>
<a href="#test">Test</a>
...
</ul>
...
<h1>
<a id="user-content-test" class="anchor" href="#test" aria-hidden="true"><span class="octicon octicon-link"></span></a>Test</h1>
...

Note the user-content prefix!

Partial TOC generated for multiple mismatched blockquotes

Thank you for the very useful plugin!

ISSUE

Given certain markup having two headers we generate a TOC with one header.

Expected the TOC to contain two headers.

EXAMPLE

# Heading 1
 ```
 Blockquote 1 - notice the leading space ( ) for opening blockquote, and no-space for closing
```

# Heading 2 will be missing
 ```
 Blockquote 2 - notice again the same leading spacing as above
```

RESULT

<!-- MarkdownTOC depth=3 bracket=round autolink=true -->

- [Heading 1](#heading-1)

<!-- /MarkdownTOC -->

Broken reference when header has square brackets

Current result:

<!-- MarkdownTOC -->

- [function(foo](#, bar)
- [function(foo\](#, bar\)

<!-- /MarkdownTOC -->

# function(foo[, bar])
# function(foo\[, bar\])

Expected:

<!-- MarkdownTOC -->

- [function(foo\[, bar\])](functionfoo-bar)

<!-- /MarkdownTOC -->

# function(foo[, bar])

Don't \escape characters inside `code`

Here's a perfectly reasonable header:

## `function(param, [optional])`

Here's what MarkdownTOC generates:

- [`function\(param, \[optional\]\)`](#functionparam-optional)

Here's how it looks:

image

Escaping brackets inside code is not needed, and those backslashes get rendered.
It should be possible to avoid this problem by using a Markdown parser.

Headers/TOC anchor links broken: TOC contains empty links?

This is an example file for demonstrating my issue with MarkdownTOC for Sumblime Text.

<!-- MarkdownTOC depth=0 -->

- [](#First Level)
    - [](#Second Level.)
- [This almost works](#almost)

<!-- /MarkdownTOC -->


# [First Level](#first-level)

Paragraph?

## [Second Level.][#level2] 

Paragraph text after second level. 

# This almost works[almost]

But markdown renders the above ("almost works") as the following (formatted here for viewability):

<h1>This almost works[almost]</h1>

... which is obviously not the intended outcome. Presumably because, to my knowledge, the "almost working" example is not valid Markdown for what I'm trying to achieve... Is this somehow the fault of my Markdown renderer? I realize maybe this is a MultiMarkdown feature... should I be using that explicitly?

Plugin no longer working in Sublime 3 Build 3059

I enjoy the plugin and I have been using it for quite a while. However, it recently stopped working and I tested it on files that worked previously and even a simple plain markdown file. I consistently get the error "cannot find TOC tags" in the sublime status bar at the bottom, but otherwise nothing happens. It was working until recently. Any ideas on how to troubleshoot?

Allow the use of different list bullets for different levels

I would like to be able to define the list items used for the TOC for each level, like

* H1
  - H2
    + H3
      *  H4

It might be configurable like this

"list_indent_bullets": ["*", "-", "+"]

Where the first item ist for the first level, the second for the second and so on until the last one of the list and then it starts over from the beginning.

See also sublime text package MarkdownEditing settings: mde.list_indent_bullets

Ignore comments inside Python code blocks

MarkdownTOC sees comments inside Python fenced code blocks as additional headers and includes them in the table of contents.

I think anything that looks like a header inside a code block should probably be ignored. I realize this is probably not a very simple fix and this might just be an issue for GitHub Flavored Markdown.

The following is an example:

# This should be a header in the TOC
## As should this

Here comes a fenced Python code block:

```python
import os

# but this is just a comment inside 
# a Python fenced code block
#####################################

# as are these comments that show up as headers
# as are these comments that show up as headers
```

And this is the TOC that the above code produces:

<!-- MarkdownTOC depth=2 -->

- This should be a header in the TOC
    - As should this
- but this is just a comment inside
- a Python fenced code block
- as are these comments that show up as headers
- as are these comments that show up as headers

<!-- /MarkdownTOC -->

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.