30 lines
1009 B
JavaScript
30 lines
1009 B
JavaScript
|
|
/**
|
||
|
|
* 格式化HTML文件 - 将转义字符恢复为可编辑状态
|
||
|
|
*/
|
||
|
|
const fs = require('fs');
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
const inputFile = path.join(__dirname, 'extension_clean/out/webview/panel.html');
|
||
|
|
const outputFile = path.join(__dirname, 'extension_clean/out/webview/panel_formatted.html');
|
||
|
|
|
||
|
|
// 读取文件
|
||
|
|
let content = fs.readFileSync(inputFile, 'utf8');
|
||
|
|
|
||
|
|
// 处理转义字符
|
||
|
|
content = content
|
||
|
|
.replace(/\\n/g, '\n') // \n -> 真正的换行
|
||
|
|
.replace(/\\t/g, '\t') // \t -> 真正的tab
|
||
|
|
.replace(/\\r/g, '') // \r -> 删除
|
||
|
|
.replace(/\\"/g, '"') // \" -> "
|
||
|
|
.replace(/\\'/g, "'") // \' -> '
|
||
|
|
.replace(/\\\\/g, '\\'); // \\ -> \
|
||
|
|
|
||
|
|
// 写入格式化后的文件
|
||
|
|
fs.writeFileSync(outputFile, content, 'utf8');
|
||
|
|
|
||
|
|
console.log('HTML格式化完成!');
|
||
|
|
console.log('输入文件:', inputFile);
|
||
|
|
console.log('输出文件:', outputFile);
|
||
|
|
console.log('文件大小:', content.length, '字符');
|
||
|
|
console.log('行数:', content.split('\n').length);
|