can i use function list in Notepad++ 7.9.5?
-
i want outliner for mark down file.
i just want the header like vs code,not the markdown preview.
is it possible by extension? -
@bge-low ,
Is it possible by extension?
If by “extension” you meant “plugin” – that’s not necessary, at least for the first-level of what you requested; as shown below, it will work with builtin Notepad++ features.
If by “extension”, you mean “file extension”, then yes; if your Markdown UDL defines the
ext
box asmd markdown
or similar, any files ending in.md
or.markdown
will have the Markdown UDL lexer applied automatically, and will also have the functionList feature applied if you’ve followed the steps described below. (Since there is a pre-installed Markdown UDL included with Notepad++, and it does define the extensions, then it will probably work by extension without extra effort beyond what’s described below.)Instructions
Notepad++ has the built in Function List tool, which is meant for showing functions, classes, and the like. However, to some extent, it can be used to find the headers in markdown.
To accomplish this, follow the instructions in the npp-user-manual.org Function List page as well as the Function List config files section
- Exit all instances of the Notepad++ application
- Edit
%AppData%\Notepad++\functionList\overrideMap.xml
.
Just before the ending</associationMap>
, add a line
If you have an unedited copy of overrideMap.xml, putting it in the group with the other example UDL is a good idea:<association id= "markdown.xml" userDefinedLangName="Markdown (preinstalled)"/>
and SaveoverrideMap.xml
- Edit
%AppData%\Notepad++\functionList\markdown.xml
. Give it content like the following:
The function expression will recognize markdown headers that are prefixed with one or more #, or headers that are indicated by a following line consisting of<?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)(^[#]+\s*(.*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\s*$))"/> </parser> </functionList> </NotepadPlus>
---
or===
. If you have other requirements, you can add them into the regular expression
Savemarkdown.xml
- Exit Notepad++ and re-start the application (required to get it to re-read the config files)
- Now when you open a Markdown file in Notepad++, the View > Function List panel will show the outline, like in my screenshot below.
As you can see, it doesn’t make a multi-layer hierarchy, like you showed… but since it keeps the
#
prefixes, you can still see which level of hierarchy you are on. Using the “class” feature of the Function List syntax (see the FAQ, linked below), you could make it give one level of hierarchy, though it would require some additional development on your part to update themarkdown.xml
contents per the FAQ and npp-user-manual.org instructions. And personally, I don’t think a single layer or hierarchy is worth the effort for Markdown “functionList” features.References:
-
FYI, I followed Peter’s instructions and it worked perfectly.
I was somewhat of a risk-taker and skipped step 1, with no problems. :-) -
I notice that the dynamic highlight color in the Function List of the function your caret is in in the editor window is rather subtle (using the default theme).
In case it is unclear, I mean as you caret around in your main document area, the Function List shows you which “function” you are currently in.
I don’t mean when you click on a function in the FL window – when I do that, the background highlight of the function clicked is suitably contrasting.For me the background coloring is much more subtle than your screenshot shows for
## Another Level 2
.Is there a technique for making this more visible (i.e., making the background color of that function name darker)?
This feels like it might have been something discussed before?
-
Hello @bge-low, @peterjones, @alan-kilborn and All,
After some tests on our
NodeBB
forum and some searches on legalMarkdown
syntax, I think that we should change the present syntax :<function mainExpr="(?x-s)(^[#]+\s*(.*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\s*$))"/>
into this new one :
<function mainExpr="(?-s)^#{1,6}(?:(?=[\t\x20]*$)|[\t\x20]+\K.+)|^.+(?=\R\x20{0,3}[-=]+[\t\x20]*$)"/>
You may test it against this text, using the
Markdown (preinstalled)
language :Line 1 Line 2 ###### HEADER Text of level 6 Line 3 Line 4 Line 5 is a HEADER line ======= Line 6 Line 7 is ALSO a HEADER line - Line 8 Line 9 # Level 1 HEADER Text Line 10 : the NEXT line is an EMPTY HEADER text ### Line 11 Line 12
With the
free-spacing
mode, this regex can be re-expressed as below :(?x-s) # FREE-SPACING mode and any DOT matches a SINGLE STANDARD char ONLY ^ \# {1,6} # From 1 to SIX '#' characters ... (?: # START of a NON capturing group 1 (?= [\t\x20]* $ ) # IF followed with POSSIBLE TAB or SPACE character(s) till the END of CURRENT line | # OR [\t\x20]+ # followed with, at least, one TAB or SPACE character \K .+ # and, AFTER a RESET, followed with the REMAINDER or CURRENT line ) # END of the NON-CAPTURING group 1 | # OR ^.+ # CURRENT line contents ... (?= # Start of a POSITIVE look-ahead \R\x20{0,3} # IF followed with A LINE-BREAK, and from ZERO to THREE SPACE character(s) [-=]+ # followed with, at least, ONE DASH or EQUAL sign [\t\x20]*$ # Followed with POSSIBLE TAB or SPACE character(s) till the END of CURRENT line ) # END of the POSITIVE look-ahead
Best Regards,
guy038
-
@PeterJones
thanks peter.your tutorial worked perfectly.but i still have other question.
can the function list be “fold” like vs code?
header1 locate in top,header2 and header3 locate in under of header1. -
@bge-low said in can i use function list in Notepad++ 7.9.5?:
but i still have other question.
can the function list be “fold” like vs code?I think Peter answered this one:
As you can see, it doesn’t make a multi-layer hierarchy
So the very short answer is No.
-
thanks for comment.do i have to develop for folding function?
that looks like very hard. -
@bge-low said in can i use function list in Notepad++ 7.9.5?:
do i have to develop for folding function?
If you want that feature, I’d say Yes.
Otherwise you can make a FEATURE REQUEST for the N++ developers, but that offers no guarantee of implementation. -
thanks for comment.
i may have to make plugin.
https://npp-user-manual.org/docs/plugins/