Compare commits

...

2 Commits

Author SHA1 Message Date
143862059a 0.0.11 2026-03-27 14:45:58 -07:00
07237e833b Add script content preservation during formatting 2026-03-27 14:45:54 -07:00
2 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@because/hype",
"version": "0.0.10",
"version": "0.0.11",
"module": "src/index.tsx",
"type": "module",
"exports": {

View File

@ -54,7 +54,25 @@ const minify = function(el) {
const convert = {
comment: [],
line: []
line: [],
script: []
};
const preserveScripts = function (el) {
convert.script = [];
el = el.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/gi, function (match, open, content, close) {
if (!content.trim()) return match;
convert.script.push(content);
return open + '[#s# : ' + (convert.script.length - 1) + ' : #s#]' + close;
});
return el;
};
const restoreScripts = function (el) {
convert.script.forEach(function (content, index) {
el = el.replace('[#s# : ' + index + ' : #s#]', content);
});
return el;
};
const comment = function (el) {
@ -125,11 +143,13 @@ const tidy = function (el) {
const render = function (el, opt) {
el = closing(el);
el = preserveScripts(el);
el = comment(el);
el = entity(el);
el = minify(el);
el = line(el);
el = tidy(el);
el = restoreScripts(el);
return el;
};