Skip to content

Instantly share code, notes, and snippets.

@adamdharrington
Last active February 27, 2023 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdharrington/230d225f405a3b336a60 to your computer and use it in GitHub Desktop.
Save adamdharrington/230d225f405a3b336a60 to your computer and use it in GitHub Desktop.
Create a Markdown Table of Contents with Notepad++ macros

Create a Markdown Table of Contents with Notepad++ macros

Instructions

  1. Find the shortcuts.xml file (in windows it's in: Users%{USERNAME}%\AppData\Roaming\Notepad++)
  2. Close Notepad ++
  3. Add the contents of the above macro into your shortcuts.xml file (as indicated in the sample)
  4. Save and close
  5. Open Notepad++
  6. If you wish to change the shortcut you can do so under the "macros -> modify/delete" menu.

Demo

Turns a line like this:

I'm a Heading

Into:

- [I'm a Heading](#i'm-a-heading)

With the following line at the end of your document to act as a placemarked heading:

### I'm a Heading

Demo Two (before)

Contents

Section One

Section Two

Section Three

Whatever You Want and As Long As You Want

Demo Two (after)

Contents

Section One

Section Two

Section Three

Whatever You Want and As Long As You Want

<Macro name="Markdown - TOC" Ctrl="yes" Alt="yes" Shift="no" Key="219">
<Action type="0" message="2453" wParam="0" lParam="0" sParam="" />
<Action type="0" message="2315" wParam="0" lParam="0" sParam="" />
<Action type="0" message="2177" wParam="0" lParam="0" sParam="" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="-" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="[" />
<Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="]" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="(" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="#" />
<Action type="2" message="0" wParam="42020" lParam="0" sParam="" />
<Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
<Action type="2" message="0" wParam="42020" lParam="0" sParam="" />
<Action type="2" message="0" wParam="42017" lParam="0" sParam="" />
<Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
<Action type="3" message="1601" wParam="0" lParam="0" sParam=" " />
<Action type="3" message="1625" wParam="0" lParam="1" sParam="" />
<Action type="3" message="1602" wParam="0" lParam="0" sParam="-" />
<Action type="3" message="1702" wParam="0" lParam="384" sParam="" />
<Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
<Action type="0" message="2306" wParam="0" lParam="0" sParam="" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam=")" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />
<Action type="0" message="2318" wParam="0" lParam="0" sParam="" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="#" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="#" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="#" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
<Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />
</Macro>
<NotepadPlus>
<InternalCommands />
<Macros>
<!-- Insert Macro here -->
</Macros>
</NotepadPlus>
@kshraval
Copy link

When I press shortcut Ctrl+Alt+[ on a line I want to be a heading, it is adding at the end of the file as you've described. However I could not understand how can I use this table of contents which is created at the end of the file to navigate to those sections?

For example I got this at the end of my txt file:

Section One

Section Two

Now what? What do I need to do for navigating to these respective sections.

@e-motiv
Copy link

e-motiv commented Feb 23, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment