Markdown nested headings in function list

Markdown nested headings in function list

44
Basic UserBasic User
44

    Mar 15, 2019#1

    It seems the existing markdown function list is really not helpful, as it groups h1s, h2s, h3s together rather than nesting h2s under h1s, h3s under h2s etc.

    Code: Select all

    # First heading
    Some text
    ## Sub-heading 2nd level
    Some text
    ### Sub-heading 3rd level
    Some text
    # Second heading
    Some text
    # Third heading
    Some text
    I don't think anyone pictures a document like this when they use nested headings.. 
    2019-03-15 13_40_46-[D__Documents_Work_Personal_ussNotes_README.md] - HomePc - UltraEdit 64-bit.png (3.36KiB)
    I was trying to work out how to nest them properly. It seems I cannot use the next h1 as a delimiter for finding nested headings.. 

    Code: Select all

    /TGBegin "Heading 1"
    /TGFindStr = "%# ^(?+^)$"
    /TGFindStr = "%^(?+^)^p====+$"
    /TGBegin "Heading 2"
    /TGFindStr = "%## ^(?+^)$"
    /TGFindBStart = "%# "
    /TGFindBEnd = "%# "
    /TGEnd
    /TGEnd
    I could introduce artificial constructs like looking for "#end" as the closing delimiter, but that introduces a lot of problems and makes it much harder to write markdown naturally.

    Any ideas?

    Rob
    :)
    UltraEdit - licensed for life!

    http://robertmarkbramprogrammer.blogspot.com

    6,603547
    Grand MasterGrand Master
    6,603547

      Mar 18, 2019#2

      Following hierarchical function string definition using Perl regular expression could be used in the wordfile for a hierarchical heading list in function list view.

      Code: Select all

      /TGBegin "Heading 1"
      /TGFindStr = "^# (.+)$"
      /TGBegin "Heading 2"
      /TGFindStr = "^## (.+)$"
      /TGFindBStart = "^# "
      /TGFindBEnd = "^# |\z"
      /TGBegin "Heading 3"
      /TGFindStr = "^### (.+)$"
      /TGFindBStart = "^## "
      /TGFindBEnd = "^#{1,2} |^z"
      /TGEnd
      /TGEnd
      /TGEnd
      /Regexp Type = Perl
      
      UltraEdit searches for lines starting with one # and a space for headings of level 1. When a heading level 1 is found, it searches in block starting with the line containing heading level 1 and ending with next line containing a heading level 1 or end of buffer (= end of file depending on file size respectively always end of file depending on version of UltraEdit) for lines starting with two # and a space for headings of level 2. When a heading level 2 is found, UE searches in block starting with the line containing heading level 2 and ending with next line containing either a heading level 1 or a heading level 2 or end of buffer (end of file) for lines starting with three # and a space for headings of level 3.

      But please take into account on using such a hierarchical heading function list for markdown files that a missing heading at a specific level results automatically in ignoring all headings of lower level. That means if for example the markdown file misses somewhere heading level 1, all headings level 2, 3, ... are ignored up to first line with heading level 1 which could mean all headings are ignored if the markdown file contains for example only headings of level 2 and 3, but no headings of level 1.

      In real it would be necessary to search for lines starting with one to six # and a space for headings level 1 to 6 and list them by replacing each # by two (three, four) spaces before getting the found line displayed in function list. But doing a replace on parts of found lines before getting them displayed in function list is not possible. That's not how function list feature of UltraEdit is designed for. It would be possible to use a script executed for example by key to search in active markdown file for headings and list them in output window as document structure list where missing heading levels would not matter.
      Best regards from an UC/UE/UES for Windows user from Austria

      44
      Basic UserBasic User
      44

        Mar 19, 2019#3

        That works brilliantly.. thank you!
        UltraEdit - licensed for life!

        http://robertmarkbramprogrammer.blogspot.com