Display markdown outline view through Functionlist
-
functionList.xml:
<associationMap> <association id= "Markdown(Monokai)" userDefinedLangName="Markdown(Monokai)" /> <association id= "Markdown(Monokai)" ext=".md" /> <association id= "Markdown(Monokai)" ext=".markdown" /> </associationMap> <parsers> <parser displayName="Markdown(Monokai)" id ="Markdown(Monokai)" commentExpr="" > <function mainExpr="(?x)((?:^|\n)[#]+\s+(.*?)(\r*|\n*)$) |((?:^|\n)[-]{3,}\s*(\r*|\n*)$)" /> </parser> </parsers>
-
Is there a question lurking somewhere there??
-
I interpreted it as someone sharing a hack / tip / trick to be able to use the FunctionList feature to give an outline of a markdown document. I didn’t try it (yet), but I think sharing hacks, tips, and tricks is a great thing to have in this forum, which is why I upvoted it.
It should be noted that users will need to use their association ID for markdown, if their Markdown UDL doesn’t happen to be called
Markdown(Monokai)
. If you use the default Markdown UDL that ships with Notepad++, it’sMarkdown (Default)
.I just confirmed that replacing
Markdown(Monokai)
withMarkdown (Default)
, and doing a simple markdown file, worked as expected: -
See also issue 5986 and issue 5945.
-
@PeterJones said in Display markdown outline view through Functionlist:
I think sharing hacks, tips, and tricks is a great thing to have in this forum, which is why I upvoted it.
I agree with that. However, if you’re going to share something, at least put a little effort into describing what it means and how to use it. Clearly from my earlier comment, I at least had no idea…
-
Awesome - thanks!
Didn’t work exactly like I wanted - it would highlight the line above the heading so I did a slight modification:
<parser displayName="Markdown" id ="Markdown" commentExpr="" > <function mainExpr="(?x)((?:^|\n)[#]+\s+(.*?)(\r*|\n*)$)"> <functionName> <nameExpr expr="(?:[#]+\s+)(.*)"/> </functionName> </function> </parser>
Cheers.
-
@Michael-Vincent said:
it would highlhght the line above
True.
But the original was intended to catch the daring-fireball-style header-above-
----
-or-====
, which yours didn’t catch.I combined both philosophies:
<function mainExpr="(?x-s)(^[#]+\s*(.*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\s*$))" />
# H1 Text ## H2 Blah ### H3 here ### H3.2 yo ## H2.2 something # H1 heheheh DaringFireballUnderline- Indicated Header Too ----- DaringFireballUnderline= Indicated Header Too === Not sure that mixed =-=- should be header =-=-= Normal text # END
This version catches either style, doesn’t require a space after the
#
for the header (I’ve seen some markdowns that don’t require that space); for the underline style, I made the executive decision that it only counts if it’s all-hyphen or all-equal, so mixed-hyphen-equal will not trigger the header recognitionThis could be endlessly tweaked for everyone’s markdown-interpreting preferences. :-)
-
Or try this one:
<!-- ======================================================== [ Markdown ] --> <!-- | Based on: | https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5945 \--> <parser displayName="[TODO] Markdown" id ="markdown_header" commentExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?ms: # Code block ^ # ...at start-of-line a (?'BLOCK'\x7E{3}(?!\x7E)|\x60{3}(?!\x60)) # block-start indicator \w*\h*$ # .*? # ...whatever, ^\x20{0,3} # ...optional indentation for a \k'BLOCK' # block-end indicator \h*$ # with trailing white-space only ) " > <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?m-s) # ^ and $ match at line-breaks, dot does not ^ # at start-of-line (?'NOCODE_INDENT' \x20{0,3}(?!\x20) # indent of 3 spaces max, otherwise it's code ) (?: # ATX-style heading (?'LEVEL'\x23{1,6}(?!\x23)) # nr. of hashes indicate level \h+ # at least one white-space \K # discard text matched so far (?: [^\r\n\x5C] | \x5C. # backslash escape sequence )+ (?: # closing sequence \h+ # ...starts w/ at least one white-space \x23+ # ...contains only hashes, amount arbitrary )? # ...is optional \h*$ # trailing white-space up till line-break | # Setext-style heading \K # discard text matched so far [^\r\n]+ # whatever, (?= # ...up till \h*(?:\r?\n|\n?\r) # ...any trailing white-space and a line-break, (?&NOCODE_INDENT) # ...indent for header indicator (?:={3,}|-{3,}) # ...H1- or H2-header indicator resp., \h*$ # ...trailing white-space up till line-break ) ) " > <functionName> <nameExpr expr="(?x) (?| (?:\h+\x23+\h*$) [^\r\n]+ (?= \h+\x23 ) | .* ) " /> </functionName> </function> </parser>
-
@linpengcheng said in Display markdown outline view through Functionlist:
(?:^|\n)[-]{3,}\s*(\r*|\n*)$
This paragraph is used to write
Marp-markdown-Slide
, I usemarp-cli
to generate Slide. -
@MAPJe71 The parser works nicely. However indentation is lost (Subtitles, Subsubtitles, … are listed at the same level). Is there somehow a way to replace the ‘#’ with a empty space or ‘_’ but only for the visualization in the function list?
Best regards and thanks for contributing and sharing -
@Ernesto-Saavedra said in Display markdown outline view through Functionlist:
Is there somehow a way to replace
Sorry, the functionList processing is a match-search, not a search-and-replace.
You can make a single-level hierarchy by doing a “class” vs “function” in the definition, as described in the function list overview and function list config files documentation, or in @MAPJe71’s FAQ Desk: Function List Basics entry.
-
@Ernesto-Saavedra said in Display markdown outline view through Functionlist:
@MAPJe71 The parser works nicely. However indentation is lost (Subtitles, Subsubtitles, … are listed at the same level). Is there somehow a way to replace the ‘#’ with a empty space or ‘_’ but only for the visualization in the function list?
Best regards and thanks for contributing and sharingI found a way to prevent the indentation from being lost in @MAPJe71 's parser (which I prefer to the others, as it seems more complete).
Whatever the
<function>
block matches gets passed to the<functionName>
block, so our problem is that the<function>
block is discarding the hashes due to the two\K
lines. So I removed them, and pulled them up to a common point, where it should no longer discard the hashes:<!-- ======================================================== [ Markdown ] --> <!-- | Based on: | https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5945 \--> <parser displayName="[TODO] Markdown" id ="markdown_header" commentExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?ms: # Code block ^ # ...at start-of-line a (?'BLOCK'\x7E{3}(?!\x7E)|\x60{3}(?!\x60)) # block-start indicator \w*\h*$ # .*? # ...whatever, ^\x20{0,3} # ...optional indentation for a \k'BLOCK' # block-end indicator \h*$ # with trailing white-space only ) " > <function mainExpr="(?x) # free-spacing (see `RegEx - Pattern Modifiers`) (?m-s) # ^ and $ match at line-breaks, dot does not ^ # at start-of-line (?'NOCODE_INDENT' \x20{0,3}(?!\x20) # indent of 3 spaces max, otherwise it's code ) \K # discard text matched so far (?: # ATX-style heading (?'LEVEL'\x23{1,6}(?!\x23)) # nr. of hashes indicate level \h+ # at least one white-space (?: [^\r\n\x5C] | \x5C. # backslash escape sequence )+ (?: # closing sequence \h+ # ...starts w/ at least one white-space \x23+ # ...contains only hashes, amount arbitrary )? # ...is optional \h*$ # trailing white-space up till line-break | # Setext-style heading [^\r\n]+ # whatever, (?= # ...up till \h*(?:\r?\n|\n?\r) # ...any trailing white-space and a line-break, (?&NOCODE_INDENT) # ...indent for header indicator (?:={3,}|-{3,}) # ...H1- or H2-header indicator resp., \h*$ # ...trailing white-space up till line-break ) ) " > <functionName> <nameExpr expr="(?x) (?| (?:\h+\x23+\h*$) [^\r\n]+ (?= \h+\x23 ) | .* ) " /> </functionName> </function> </parser>
Now the hashes show up for me in the Function List, and show the level of the heading.
-
As an aside, Notepad++ really should start including all of this in a markdown_preinstalled.xml and associated by default in the overrideMap.xml that it ships with. To ship a product with a “Markdown (preinstalled)” UDL, but not include the Function List functionality for basic navigation seems like an incomplete feature.
-
For non-programming langauges, like Markdown, there’s probably less concensus among users as whether “headers” or something else is the most likely “function” to include, which is probably why the developer hasn’t included such. But asking the developer (follow our Feature Request / Bug FAQ) to include the FunctionList would be reasonable at this stage (though someone would likely have to create the unitTest for him as well, otherwise he might not include it on his own).