markdown-toc Atom package: problem with underscores in headings
markdown-toc (version 0.4.2) is an Atom (version 1.28.0) package that generates a table of contents from all your markdown headings. However, when generating links for headings having underscores (e.g. "The file logging_conf.json") by markdown-toc, the underscores are ignored in the generated relative URLs. GitHub needs the underscores within the headings' URLs so your internal links work correctly.
Thus, you will have to modify the regex used by markdown-toc for ignoring some characters (e.g. underscore) in the headings when forming the relative links. In order to do so, do the following:
Underscores are ignored by default by the markdown-toc package when generating the relative URLs for the internal links in the TOC |
Thus, you will have to modify the regex used by markdown-toc for ignoring some characters (e.g. underscore) in the headings when forming the relative links. In order to do so, do the following:
- Go to Atom->Preferences..., then click on Open Config Folder.
- On the Project tab, search for the file TOC.coffee that you can find within the folder packages/markdown-toc/lib/.
- Find the line
hash = hash.replace /[^a-z0-9\u4e00-\u9fa5äüö\-]/g, ""
- Modify the regex by adding the characters
\_
like this:
- Save everything, restart Atom, and re-open your project.
- Toggle the markdown-toc package to regenerate your TOC with the URLs having the underscores. Now, your internal links with underscores are working under GitHub markdown files (e.g. README.md).
Yeah! The underscores are not ignored anymore in the relative URLs by markdown-toc
Comments
Post a Comment