mirror of
https://github.com/penpot/penpot.git
synced 2025-07-22 10:07:14 +02:00
✨ Modularize js-beautify library related code
This commit is contained in:
parent
1318a5c3c8
commit
9cba125abe
3 changed files with 32 additions and 24 deletions
26
frontend/src/app/util/code_beautify.cljs
Normal file
26
frontend/src/app/util/code_beautify.cljs
Normal 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))))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue