Community
    • Login

    Display markdown outline view through Functionlist

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    15 Posts 8 Posters 3.2k 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.
    • Michael VincentM
      Michael Vincent @linpengcheng
      last edited by Michael Vincent

      @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
      • PeterJonesP
        PeterJones
        last edited by

        @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
        • MAPJe71M
          MAPJe71
          last edited by

          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>
          
          Ernesto SaavedraE A 2 Replies Last reply Reply Quote 2
          • linpengchengL
            linpengcheng
            last edited by

            @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
            • Ernesto SaavedraE
              Ernesto Saavedra @MAPJe71
              last edited by

              @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

              PeterJonesP T 2 Replies Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Ernesto Saavedra
                last edited by

                @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

                  @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

                    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.

                    PeterJonesP 1 Reply Last reply Reply Quote 1
                    • PeterJonesP
                      PeterJones @Theodan23
                      last edited by PeterJones

                      @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

                        @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