h1's in function list for navigation
-
hi. is there a way to list all the h1 headings in a .md file in the function list for navigation? or is there a better way to do similar?
-
is there a way to list all the h1 headings in a .md file in the function list for navigation?
Yep. Notepad++ has the View > Function List command, which will show a function list. And any syntax-highlighting language (whether built-in or UDL) can have the FunctionList definition customized to your desires, assuming you know regex.
Here is an example of mine, which actually does all headings (not just h1)
You can then double-click on any of the lines in the Function List panel to go to that line in the editor.
Instructions:
Assuming a normal installation (where settings are in
%AppData%\Notepad++
, create a new file called%AppData%\Notepad++\functionList\udl_markdown.xml
with the contents:<?xml version="1.0" encoding="UTF-8"?> <!-- ==========================================================================\ | | To learn how to make your own language parser, please check the following | link: | https://npp-user-manual.org/docs/function-list/ | \=========================================================================== --> <NotepadPlus> <functionList> <parser displayName="Markdown (preinstalled)" id="Markdown (preinstalled)" commentExpr=""> <function mainExpr="(?x-s)(^\h*\K[#]+\h*(.*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\h*$))"/> </parser> </functionList> </NotepadPlus>
Then edit
%AppData%\Notepad++\functionList\overrideMap.xml
(if it doesn’t exist, copyc:\Program Files\Notepad++\functionList\overrideMap.xml
to%AppData%\Notepad++\functionList\overrideMap.xml
, then edit it). Add the line<association id= "udl_markdown.xml" userDefinedLangName="Markdown (preinstalled)"/>
in the User Defined Languages section:
Save those files. Exit Notepad++ and restart the app. Now, if you open a
.md
file and it’s using the Language > Markdown (preinstalled) UDL entry that comes with Notepad++, then if you show the View > Function List, and any header lines will show up as double-clickable table-of-contents.If you only want h1, and not h2 or deeper, change to
mainExpr="(?x-s)(^\h*\K[#]\h*([^#]*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\h*$))"
in theudl_markdown.xml
file, save, exit, and restart N++.