/* DokuWiki MoaiEditor Highlight_header.js file Version : 0.5a (May 6, 2026) Author : MoaiTools License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ /* Handles the syntax highlighting of headers (h1,h2,h3,h4,h5). */ MoaiEditor.HighlightHeader = class { constructor(outer) { // Arguments this.outer = outer; } // ──────────────────────────────────── highlight (content, syntax, linetext) { const matcher = moaiEditor.matches.matcher; // Parse the line text const parsed = matcher.headers.isHeader(linetext); // Do not highlight if it does not have header syntax if (!parsed) { content.textContent = linetext; content.style.background = "none"; return; } // Clear the contents content.textContent = ''; // Prepare the head, body and tail of the header const type = parsed.type; const text = parsed.content; var pos_start = parsed.contentStart + (text.length - text.trimStart().length); var pos_end = parsed.contentEnd - (text.length - text.trimEnd().length); const head = linetext.substring(0, pos_start); const tail = linetext.substring(pos_end); // Create the HTML elements (must use 'append' for text to prevent the browser from intepreting code like '
')
        var inner = moaiEditor.createHTML('');
        inner.append(parsed.text);
        var box = moaiEditor.createHTML(''+type+'');
        var outer = moaiEditor.createHTML('');
        outer.append(head);
        outer.appendChild(inner);
        outer.append(tail);
        outer.appendChild(box);
        
        // Update the node
        content.appendChild(outer);
    }
    // ────────────────────────────────────
}; // End Class