Community
    • Login

    Getting Markdown headers in the function list panel

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    2 Posts 2 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.
    • Bill MB
      Bill M
      last edited by

      I installed this under my functionlist folder for notepad++ but the markdown headers still don’t appear in the function list panel. any ideas?

      <?xml version="1.0" encoding="UTF-8"?>
      <NotepadPlus>
        <functionList>
          <!-- Other parser definitions here -->
          
          <!-- Markdown headers: Match any line starting with 1-6 "#" characters -->
          <parser id="md_headers" displayName="Markdown" ext="md" commentExpr="(#+)">
            <function mainExpr="^[\t ]*(#{1,6}[ \t].+)$">
              <functionName>
                <nameExpr expr="(#{1,6}[ \t].+)" />
              </functionName>
            </function>
          </parser>
          
        </functionList>
      </NotepadPlus>
      
      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Bill M
        last edited by

        @Bill-M said in Getting Markdown headers in the function list panel:

        I installed this under my functionlist folder for notepad++

        Did you also update your overrideMap.xml to point to that file? or did you just put your XML in that folder? https://npp-user-manual.org/docs/config-files/#function-list describes

        And when you do, make sure that you have the userDefinedLangName attribute in the new tag in overrideMap.xml match the exact name of the UDL. For example, the pre-installed Markdown UDL that ship with Notepad++ are named Markdown (preinstalled) and Markdown (preinstalled dark mode). If you set userDefinedLangName="Markdown", it would not properly associate with either of the actual UDL that ship with Notepad++.

        For my UDL header list,

        <!-- Other parser definitions here -->

        That’s surprising, and might also be causing you a problem. Since v7.9.1 in 2020, the old functionList.xml was split into separate files in the functionList\ directory; each XML file in that directory should only have one <parser>.

        For example, in my %AppData%\Notepad++\functionList\ directory, I have a file called udl_markdown.xml which looks like,

        <?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,}\s*$))"/>
                </parser>
            </functionList>
        </NotepadPlus>
        

        and then in my override map, alongside the example UDL overrides that ship with the default, I added

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

        After saving those files, and restarting Notepad++, I successfully have FunctionList show me the # header lines (as well as header lines that have a line of plain text followed by a line of 3 or more --- or ===, as that’s an alternative header nomenclature in some markdown variants) – I’ve been successfully using that for years now.

        commentExpr="(#+)"

        Oh, that might be another gotcha. When the function list parser is looking, if it matches the comment expression, things found within that comment will not be searched for function names. So by saying that #+ is your comment, the FunctionList parser will ignore anything that’s one or more # characters. This means it will probably not ever be able to match your #{1,6} in your function’s mainExpr… I would highly recommend using commentExpr="" rather than giving it a value.

        If I update my <assocation ...> to point to the new definition, and modify your definition to be

        <?xml version="1.0" encoding="UTF-8"?>
        <NotepadPlus>
          <functionList>
            <!-- Markdown headers: Match any line starting with 1-6 "#" characters -->
            <parser id="md_headers" displayName="Markdown (preinstalled)" ext="md" commentExpr="">
              <function mainExpr="(?-s)^[ \t]*(#{1,6}[ \t].+)$">
                <functionName>
                  <nameExpr expr="(#{1,6}[ \t].+)" />
                </functionName>
              </function>
            </parser>
          </functionList>
        </NotepadPlus>
        

        … then it works for me.

        So, to sum up the things I’ve seen:

        1. you must set an <association ...> tag in your overrideMap.xml, making sure that userDefinedLangName’s value is the exact name of your UDL (probably Markdown (preinstalled) or Markdown (preinstalled dark mode)) and that id is the exact name of your file in the functionList\ directory
        2. you should only have one <parser> per functionList\_____.xml file
        3. if you define commentExpr, then the parser will not look for function names (or in your case, markdown headers), so make sure you don’t set that to something that interferes with recognizing your headers (I would recommend commentExpr="" , because you don’t need the parser to ignore anything)
        1 Reply Last reply Reply Quote 2
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors