6.5.0 - 新增 opencc 模块; 修复编辑器问题; 优化打包应用功能及文件管理器
This commit is contained in:
2850
app/src/main/assets-app/js-beautify/beautify.js
Normal file
2850
app/src/main/assets-app/js-beautify/beautify.js
Normal file
File diff suppressed because it is too large
Load Diff
43
app/src/main/assets-app/js-beautify/xml_formatter.js
Normal file
43
app/src/main/assets-app/js-beautify/xml_formatter.js
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
const stringTimesN = (n, char) => Array(n + 1).join(char)
|
||||
|
||||
// Adapted from https://gist.github.com/sente/1083506
|
||||
function prettifyXml(xmlInput, options) {
|
||||
options = options || {};
|
||||
let newlineOption = options.newline || '\n';
|
||||
let indentOption = options.indent || 4;
|
||||
let margin = options.margin || '';
|
||||
const indentString = stringTimesN(indentOption, ' ')
|
||||
|
||||
let formatted = '';
|
||||
const regex = /(>)(<)(\/*)/g;
|
||||
const xml = xmlInput.replace(regex, '$1' + newlineOption + '$2$3');
|
||||
let pad = 0;
|
||||
xml.split(/\r?\n/).forEach(l => {
|
||||
const line = l.trim();
|
||||
|
||||
let indent = 0;
|
||||
if (line.match(/.+<\/\w[^>]*>$/)) {
|
||||
indent = 0;
|
||||
} else if (line.match(/^<\/\w/)) {
|
||||
// Somehow istanbul doesn't see the else case as covered, although it is. Skip it.
|
||||
/* istanbul ignore else */
|
||||
if (pad !== 0) {
|
||||
pad -= 1
|
||||
}
|
||||
} else if (line.match(/^<\w([^>]*[^\/])?>.*$/)) {
|
||||
indent = 1
|
||||
} else {
|
||||
indent = 0
|
||||
}
|
||||
|
||||
const padding = stringTimesN(pad, indentString);
|
||||
formatted += margin + padding + line + newlineOption // eslint-disable-line prefer-template
|
||||
pad += indent
|
||||
})
|
||||
|
||||
return formatted.trim()
|
||||
}
|
||||
|
||||
// For non-es2015 usage
|
||||
module.exports = prettifyXml
|
||||
Reference in New Issue
Block a user