UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

44 lines (43 loc) 2 kB
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */ var n = Object.defineProperty; var o = (i, e, s) => e in i ? n(i, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[e] = s; var t = (i, e, s) => o(i, typeof e != "symbol" ? e + "" : e, s); class g { constructor(e = {}) { t(this, "defaultOptions", { indentSize: 2, maxLineLength: 80 }); this.options = e, this.options = { ...this.defaultOptions, ...e }; } format(e) { let s = "", r = 0; const { indentSize: c } = { ...this.defaultOptions, ...this.options }; return e = e.replace(/<[^>]*class="[^"]*\bresize-handle\b[^"]*"[^>]*>.*?<\/[^>]*>/g, ""), e = e.replace(/<[^>]*class="[^"]*\bresize-handle\b[^"]*"[^>]*\/?>/g, ""), e = e.replace(/\s*draggable="true"\s*/g, " "), e = e.replace(/\s*contenteditable="true"\s*/g, " "), e = e.replace(/\sselected\s*/g, " "), e = e.replace(/\shover\s*/g, " "), e = e.replace(/\bdragging\b/g, ""), e = e.replace(/class="\s+([^"]*)\s+"/g, 'class="$1"'), e = e.replace(/class="\s+([^"]*)"/g, 'class="$1"'), e = e.replace(/class="([^"]*)\s+"/g, 'class="$1"'), e = e.replace(/(<[^>]*)\s*style="position:\s*relative;"\s*/g, "$1"), e.split(/(<[^>]+>)/g).filter(Boolean).forEach((a) => { a.trim() && (a.match(/^<\//) && (r = Math.max(0, r - 1)), a.startsWith("<") ? s += ` ` + " ".repeat(r * c) + a : s += a, a.match(/^<[^/][^>]*[^/]>$/) && !this.isVoidElement(a) && (r = Math.max(0, r + 1))); }), s.trim(); } isVoidElement(e) { const s = e.match(/<([a-zA-Z0-9-]+)/); return s ? [ "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr" ].includes(s[1].toLowerCase()) : !1; } } export { g as HTMLFormatter };