1/* DokuWiki MoaiEditor Highlight_header.js file 2 Version : 0.5a (May 6, 2026) 3 Author : MoaiTools <info@moaitools.org> 4 License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ 5 6/* Handles the syntax highlighting of headers (h1,h2,h3,h4,h5). 7*/ 8MoaiEditor.HighlightHeader = class { 9 10 constructor(outer) { 11 12 // Arguments 13 this.outer = outer; 14 } 15 // ──────────────────────────────────── 16 highlight (content, syntax, linetext) { 17 18 const matcher = moaiEditor.matches.matcher; 19 20 // Parse the line text 21 const parsed = matcher.headers.isHeader(linetext); 22 23 // Do not highlight if it does not have header syntax 24 if (!parsed) { 25 content.textContent = linetext; 26 content.style.background = "none"; 27 return; 28 } 29 // Clear the contents 30 content.textContent = ''; 31 32 // Prepare the head, body and tail of the header 33 const type = parsed.type; 34 const text = parsed.content; 35 var pos_start = parsed.contentStart + (text.length - text.trimStart().length); 36 var pos_end = parsed.contentEnd - (text.length - text.trimEnd().length); 37 const head = linetext.substring(0, pos_start); 38 const tail = linetext.substring(pos_end); 39 40 // Create the HTML elements (must use 'append' for text to prevent the browser from intepreting code like '<pre>') 41 var inner = moaiEditor.createHTML('<span class="moaied-syntax-inner"></span>'); 42 inner.append(parsed.text); 43 var box = moaiEditor.createHTML('<span class="moaied-syntax-box">'+type+'</span>'); 44 var outer = moaiEditor.createHTML('<span class="moaied-syntax-header '+type+'"></span>'); 45 outer.append(head); 46 outer.appendChild(inner); 47 outer.append(tail); 48 outer.appendChild(box); 49 50 // Update the node 51 content.appendChild(outer); 52 } 53 // ──────────────────────────────────── 54}; // End Class 55