auto-match <style> and <script> tags
Hunter
Wednesday, December 24th, 2025 at 11:14 PM
393 ...defaultKeymap
394 ]),
395 html(),
396 + // Auto-close <style> and <script> tags (not handled by default html() extension)
397 + EditorView.inputHandler.of((view, from, to, text) => {
398 + if (text !== '>') return false;
399 + const before = view.state.doc.sliceString(Math.max(0, from - 20), from);
400 + const match = before.match(/<(style|script)(\s[^>]*)?$/i);
401 + if (!match) return false;
402 + const tagName = match[1].toLowerCase();
403 + const closingTag = `</${tagName}>`;
404 + view.dispatch({
405 + changes: { from, to, insert: '>' + closingTag },
406 + selection: { anchor: from + 1 }
407 + });
408 + return true;
409 + }),
410 githubDark,
411 indentUnit.of("\t"),
412 placeholder("Build something with HTML..."),