• Login
Community
  • Login

Display markdown outline view through Functionlist

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
15 Posts 8 Posters 4.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P
    PeterJones
    last edited by Nov 2, 2019, 10:41 PM

    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’s Markdown (Default).

    I just confirmed that replacing Markdown(Monokai) with Markdown (Default), and doing a simple markdown file, worked as expected:

    c3ef918a-214c-4ac0-b1cc-d781e742d855-image.png

    A 1 Reply Last reply Nov 4, 2019, 1:23 PM Reply Quote 2
    • M
      MAPJe71
      last edited by Nov 3, 2019, 12:16 AM

      See also issue 5986 and issue 5945.

      1 Reply Last reply Reply Quote 2
      • A
        Alan Kilborn @PeterJones
        last edited by Nov 4, 2019, 1:23 PM

        @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…

        1 Reply Last reply Reply Quote 2
        • M
          Michael Vincent @linpengcheng
          last edited by Michael Vincent Nov 4, 2019, 3:58 PM Nov 4, 2019, 3:58 PM

          @linpengcheng

          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.

          1 Reply Last reply Reply Quote 1
          • P
            PeterJones
            last edited by Nov 4, 2019, 4:30 PM

            @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 recognition

            5cc7b6a4-3455-4ebc-aea4-bf4eeb410f06-image.png

            This could be endlessly tweaked for everyone’s markdown-interpreting preferences. :-)

            1 Reply Last reply Reply Quote 2
            • M
              MAPJe71
              last edited by Nov 4, 2019, 10:04 PM

              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,
              									(?&amp;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>
              
              E A 2 Replies Last reply Jul 14, 2021, 10:38 AM Reply Quote 2
              • L
                linpengcheng
                last edited by Nov 5, 2019, 1:12 AM

                @linpengcheng said in Display markdown outline view through Functionlist:

                (?:^|\n)[-]{3,}\s*(\r*|\n*)$

                This paragraph is used to write Marp-markdown-Slide, I use marp-cli to generate Slide.

                Marp home

                Marp github

                1 Reply Last reply Reply Quote 1
                • E
                  Ernesto Saavedra @MAPJe71
                  last edited by Jul 14, 2021, 10:38 AM

                  @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

                  P T 2 Replies Last reply Jul 14, 2021, 1:52 PM Reply Quote 0
                  • P
                    PeterJones @Ernesto Saavedra
                    last edited by Jul 14, 2021, 1:52 PM

                    @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.

                    1 Reply Last reply Reply Quote 3
                    • T
                      Theodan23 @Ernesto Saavedra
                      last edited by Jan 4, 2025, 11:46 PM

                      @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 sharing

                      I 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,
                      									(?&amp;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.

                      1 Reply Last reply Reply Quote 0
                      • T
                        Theodan23
                        last edited by Jan 4, 2025, 11:56 PM

                        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.

                        P 1 Reply Last reply Jan 5, 2025, 12:19 AM Reply Quote 1
                        • P
                          PeterJones @Theodan23
                          last edited by PeterJones Jan 5, 2025, 12:22 AM Jan 5, 2025, 12:19 AM

                          @Dan-Ignat-0 ,

                          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).

                          1 Reply Last reply Reply Quote 3
                          • A
                            amr66 @MAPJe71
                            last edited by May 22, 2025, 4:46 PM

                            @MAPJe71 I like your solution. Unfortunately I get all comment lines from my (python) code fences into the function list. I tried some things without success, it seems that my skills in regex are limited.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors