Getting Markdown headers in the function list panel
-
I installed this under my functionlist folder for notepad++ but the markdown headers still don’t appear in the function list panel. any ideas?
<?xml version="1.0" encoding="UTF-8"?> <NotepadPlus> <functionList> <!-- Other parser definitions here --> <!-- Markdown headers: Match any line starting with 1-6 "#" characters --> <parser id="md_headers" displayName="Markdown" ext="md" commentExpr="(#+)"> <function mainExpr="^[\t ]*(#{1,6}[ \t].+)$"> <functionName> <nameExpr expr="(#{1,6}[ \t].+)" /> </functionName> </function> </parser> </functionList> </NotepadPlus>
-
@Bill-M said in Getting Markdown headers in the function list panel:
I installed this under my functionlist folder for notepad++
Did you also update your
overrideMap.xml
to point to that file? or did you just put your XML in that folder? https://npp-user-manual.org/docs/config-files/#function-list describesAnd when you do, make sure that you have the
userDefinedLangName
attribute in the new tag inoverrideMap.xml
match the exact name of the UDL. For example, the pre-installed Markdown UDL that ship with Notepad++ are namedMarkdown (preinstalled)
andMarkdown (preinstalled dark mode)
. If you setuserDefinedLangName="Markdown"
, it would not properly associate with either of the actual UDL that ship with Notepad++.For my UDL header list,
<!-- Other parser definitions here -->
That’s surprising, and might also be causing you a problem. Since v7.9.1 in 2020, the old
functionList.xml
was split into separate files in thefunctionList\
directory; each XML file in that directory should only have one<parser>
.For example, in my
%AppData%\Notepad++\functionList\
directory, I have a file calledudl_markdown.xml
which looks like,<?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,}\s*$))"/> </parser> </functionList> </NotepadPlus>
and then in my override map, alongside the example UDL overrides that ship with the default, I added
<association id= "udl_markdown.xml" userDefinedLangName="Markdown (preinstalled)"/>
After saving those files, and restarting Notepad++, I successfully have FunctionList show me the
#
header lines (as well as header lines that have a line of plain text followed by a line of 3 or more---
or===
, as that’s an alternative header nomenclature in some markdown variants) – I’ve been successfully using that for years now.commentExpr="(#+)"
Oh, that might be another gotcha. When the function list parser is looking, if it matches the comment expression, things found within that comment will not be searched for function names. So by saying that
#+
is your comment, the FunctionList parser will ignore anything that’s one or more#
characters. This means it will probably not ever be able to match your#{1,6}
in your function’smainExpr
… I would highly recommend usingcommentExpr=""
rather than giving it a value.If I update my
<assocation ...>
to point to the new definition, and modify your definition to be<?xml version="1.0" encoding="UTF-8"?> <NotepadPlus> <functionList> <!-- Markdown headers: Match any line starting with 1-6 "#" characters --> <parser id="md_headers" displayName="Markdown (preinstalled)" ext="md" commentExpr=""> <function mainExpr="(?-s)^[ \t]*(#{1,6}[ \t].+)$"> <functionName> <nameExpr expr="(#{1,6}[ \t].+)" /> </functionName> </function> </parser> </functionList> </NotepadPlus>
… then it works for me.
So, to sum up the things I’ve seen:
- you must set an
<association ...>
tag in youroverrideMap.xml
, making sure thatuserDefinedLangName
’s value is the exact name of your UDL (probablyMarkdown (preinstalled)
orMarkdown (preinstalled dark mode)
) and thatid
is the exact name of your file in thefunctionList\
directory - you should only have one
<parser>
perfunctionList\_____.xml
file - if you define
commentExpr
, then the parser will not look for function names (or in your case, markdown headers), so make sure you don’t set that to something that interferes with recognizing your headers (I would recommendcommentExpr=""
, because you don’t need the parser to ignore anything)
- you must set an