Community
    • Login

    h1's in function list for navigation

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 3 Posters 183 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.
    • G
      githuemphasis129
      last edited by

      hi. is there a way to list all the h1 headings in a .md file in the function list for navigation? or is there a better way to do similar?

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

        @githuemphasis129 ,

        is there a way to list all the h1 headings in a .md file in the function list for navigation?

        Yep. Notepad++ has the View > Function List command, which will show a function list. And any syntax-highlighting language (whether built-in or UDL) can have the FunctionList definition customized to your desires, assuming you know regex.

        Here is an example of mine, which actually does all headings (not just h1)
        8ec1c9ef-f186-444e-b58d-0ced32e8d603-image.png

        You can then double-click on any of the lines in the Function List panel to go to that line in the editor.

        Instructions:

        Assuming a normal installation (where settings are in %AppData%\Notepad++, create a new file called %AppData%\Notepad++\functionList\udl_markdown.xml with the contents:

        <?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)(^\h*\K[#]+\h*(.*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\h*$))"/>
                </parser>
            </functionList>
        </NotepadPlus>
        

        Then edit %AppData%\Notepad++\functionList\overrideMap.xml (if it doesn’t exist, copy c:\Program Files\Notepad++\functionList\overrideMap.xml to %AppData%\Notepad++\functionList\overrideMap.xml, then edit it). Add the line

        			<association id= "udl_markdown.xml"		userDefinedLangName="Markdown (preinstalled)"/>
        

        in the User Defined Languages section:
        7cc9b026-2b77-47d8-9fb1-a31e6f10f14d-image.png

        Save those files. Exit Notepad++ and restart the app. Now, if you open a .md file and it’s using the Language > Markdown (preinstalled) UDL entry that comes with Notepad++, then if you show the View > Function List, and any header lines will show up as double-clickable table-of-contents.

        If you only want h1, and not h2 or deeper, change to mainExpr="(?x-s)(^\h*\K[#]\h*([^#]*?)$|^(.*)(?=[\r\n]+^([-=])\4{2,}\h*$))" in the udl_markdown.xml file, save, exit, and restart N++.

        MJKlodt747M 1 Reply Last reply Reply Quote 1
        • MJKlodt747M
          MJKlodt747 @PeterJones
          last edited by

          @PeterJones, thank you for those straightforward instructions!

          I was able to get this working, even with my own custom language parser I made for my markdown files.

          How can I update it so that the function list displays with indentations, similar to a table of contents?

          For example:

          my-notes.md
          # H1
              ## H2
                  ### H3
                      #### H4
          # H1
              ## H2
                  ....
          

          Thanks in advance.

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

            @MJKlodt747 said in h1's in function list for navigation:

            How can I update it so that the function list displays with indentations, similar to a table of contents?

            Get rid of the \K in the mainExpr=..., and the Function List display will show any prefixed spaces (after you save, exit Notepad++, and re-run Notepad++, obviously).

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