From d2c4a58b8032533c17c845dde8546a352adc7f38 Mon Sep 17 00:00:00 2001 From: baiy Date: Fri, 26 Feb 2021 10:09:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/tool/code.vue | 152 ++++++++++++++-------------- src/views/tool/library/formatter.js | 15 +++ 2 files changed, 90 insertions(+), 77 deletions(-) create mode 100644 src/views/tool/library/formatter.js diff --git a/src/views/tool/code.vue b/src/views/tool/code.vue index 34d560a..fbbdd32 100644 --- a/src/views/tool/code.vue +++ b/src/views/tool/code.vue @@ -1,88 +1,86 @@ \ No newline at end of file diff --git a/src/views/tool/library/formatter.js b/src/views/tool/library/formatter.js new file mode 100644 index 0000000..6c1ed91 --- /dev/null +++ b/src/views/tool/library/formatter.js @@ -0,0 +1,15 @@ +import codeFormatter from 'code-formatter' +import xmlFormatter from "xml-formatter" + +export default (code, type, isCompress = false) => { + if (type === "xml") { + return xmlFormatter(code, { + indentation: isCompress ? '' : ' ', + collapseContent: true, + lineSeparator: isCompress ? '' : '\n' + }); + } + return codeFormatter(code, { + method: isCompress ? type + "min" : type + }) +} \ No newline at end of file -- GitLab