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.