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.

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:
  1. Go to Atom->Preferences..., then click on Open Config Folder.

  2. On the Project tab, search for the file TOC.coffee that you can find within the folder packages/markdown-toc/lib/.
  3. Find the line
    hash = hash.replace /[^a-z0-9\u4e00-\u9fa5äüö\-]/g, ""
    which can be found at line # 197.
  4. Modify the regex by adding the characters \_ like this:
    hash = hash.replace /[^a-z0-9\u4e00-\u9fa5äüö\-\_]/g, ""
  5. Save everything, restart Atom, and re-open your project.
  6. 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

Popular posts from this blog

Deactivate conda's base environment on startup

Product review: SMONET wireless security camera system

Draw arrows with GIMP plugins