Modularize js-beautify library related code

This commit is contained in:
Andrey Antukh 2023-12-22 16:09:31 +01:00 committed by Alonso Torres
parent 1318a5c3c8
commit 9cba125abe
3 changed files with 32 additions and 24 deletions

View file

@ -0,0 +1,26 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.util.code-beautify
(:require
["js-beautify" :as beautify]
[cuerdas.core :as str]))
(defn format-html
[data]
(beautify/html data #js {:indent_size 2}))
(defn format-code
[code type]
(let [type (if (keyword? type) (name type) type)]
(cond-> code
(= type "svg")
(-> (str/replace "<defs></defs>" "")
(str/replace "><" ">\n<"))
(or (= type "svg") (= type "html"))
(format-html))))