This info is related to: Section Editor Plugin: First Stable Release - #37 by Mark_S
As you started the section-editor discussion I was thinking about an open pull-request at GitHub: Add more start/end parser ranges by SmilyOrg · Pull Request #4977 · Jermolene/TiddlyWiki5 · GitHub
It would extend the TiddlyWiki internal parse-tree with some “start / stop” information that would make your “sectioning / replace” mechanism much easier if some of this info would be exposed to the eg: search and search-replace operators.
Since the tiddler parse-tree is cached, accessing this info should be very fast and it would make sure, that the wikitext filters use the same parsing rules as the core. eg: !.class heading text and so on.
The parse-tree for
! heading 1
some text
! heading 2
looks like this:
[
    {
        "type": "element",
        "tag": "h1",
        "attributes": {
            "class": {
                "type": "string",
                "value": ""
            }
        },
        "children": [
            {
                "type": "text",
                "text": "heading 1"
            }
        ]
    },
    {
        "type": "element",
        "tag": "p",
        "children": [
            {
                "type": "text",
                "text": "some text"
            }
        ]
    },
    {
        "type": "element",
        "tag": "h1",
        "attributes": {
            "class": {
                "type": "string",
                "value": ""
            }
        },
        "children": [
            {
                "type": "text",
                "text": "heading 2"
            }
        ]
    }
]
The parse-tree with the PR active would look like this:
[
    {
        "type": "element",
        "tag": "h1",
        "attributes": {
            "class": {
                "type": "string",
                "value": ""
            }
        },
        "children": [
            {
                "type": "text",
                "text": "heading 1",
                "start": 2,
                "end": 11
            }
        ]
    },
    {
        "type": "element",
        "tag": "p",
        "children": [
            {
                "type": "text",
                "text": "some text",
                "start": 13,
                "end": 22
            }
        ],
        "start": 13,
        "end": 22
    },
    {
        "type": "element",
        "tag": "h1",
        "attributes": {
            "class": {
                "type": "string",
                "value": ""
            }
        },
        "children": [
            {
                "type": "text",
                "text": "heading 2",
                "start": 26,
                "end": 35
            }
        ]
    }
]
The character count starts with 0 and line-feeds \n are also counted. … As you can see, if the numbering would be optimized it would be simple to find the 2 heading level-1’s or any other element that we want to find. …
just to let you know
-mario