Community
    • Login

    h1's in function list for navigation

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 142 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++.

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