naokazuterada / MarkdownTOC

SublimeText3 plugin which generate a table of contents (TOC) in a markdown document.
https://packagecontrol.io/packages/MarkdownTOC
MIT License
301 stars 48 forks source link

Does not work with GFM #54

Closed normenmueller closed 7 years ago

normenmueller commented 9 years ago

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!

naokazuterada commented 9 years ago

Sorry, I couldn't understand what you mean. Please explain more.

normenmueller commented 9 years ago

Sorry for the confusion.

I'm using your plug-in in combination with MarkdownPreview. There I have the option to post to GitHub for transformation utilizing GitHub's GFM.

There sections get user-content- prefix. So it would be nice, if there would be an option to specify those prefixes.

Currently, as a dirty workaround I did the following in MarkdownTOC.py:

$ git diff
diff --git a/MarkdownTOC.py b/MarkdownTOC.py
index 21bf71a..727cd4e 100644
--- a/MarkdownTOC.py
+++ b/MarkdownTOC.py
@@ -185,7 +185,8 @@ class MarkdowntocInsert(sublime_plugin.TextCommand):

             # Add indent
             for i in range(_indent):
-                toc += '\t'
+                # XXX change '\t' to '    '
+                toc += '    '

             # Reference-style links: e.g. '# heading [my-anchor]'
             list_reference_link = list(pattern_reference_link.finditer(_text))
@@ -220,12 +221,13 @@ class MarkdowntocInsert(sublime_plugin.TextCommand):
                     level_counters.append(1)
                 list_prefix = "%d. " % level_counters[-1]

+            # XXX add `user-content-` to work with GFM
             if _id == None:
                 toc += list_prefix + _text + '\n'
             elif attrs['bracket'] == 'round':
-                toc += list_prefix + '[' + _text + '](#' + _id + ')\n'
+                toc += list_prefix + '[' + _text + '](#user-content-' + _id + ')\n'
             else:
-                toc += list_prefix + '[' + _text + '][' + _id + ']\n'
+                toc += list_prefix + '[' + _text + '][user-content-' + _id + ']\n'    

Cheers, /nm

naokazuterada commented 7 years ago

Hi @normenmueller, this issue is fixed in 2.7.0. It's been a long time, though. 🤕

naokazuterada commented 7 years ago

108