1
0
Эх сурвалжийг харах

fix: code block issue

Close #2000
Tienson Qin 4 жил өмнө
parent
commit
70ebbc286b

+ 1 - 1
src/main/frontend/extensions/code.cljs

@@ -64,7 +64,7 @@
                   fl (first lines)
                   ll (last lines)]
               (when (and fl ll)
-                (let [value' (str fl "\n" value "\n" ll)
+                (let [value' (str (string/trim fl) "\n" value "\n" (string/trim ll))
                       ;; FIXME: What if there're multiple code blocks with the same value?
                       content' (string/replace-first content full-content value')]
                   (editor-handler/save-block-if-changed! block content'))))))

+ 8 - 2
src/main/frontend/format/block.cljs

@@ -384,6 +384,10 @@
         content (cons f body)]
     (string/join "\n" content)))
 
+(defn src-block?
+  [block]
+  (some (fn [x] (and (vector? x) (= "Src" (first x)))) (:body block)))
+
 (defn- get-block-content
   [utf8-content block format]
   (let [meta (:meta block)
@@ -392,11 +396,13 @@
                                   (:start-pos meta)
                                   end-pos)
                   (utf8/substring utf8-content
-                                  (:start-pos meta)))]
+                                  (:start-pos meta)))
+        content-orig content]
     (let [content (when content
                     (let [content (text/remove-level-spaces content format)]
                       (if (or (:pre-block? block)
-                              (= (:format block) :org))
+                              (= (:format block) :org)
+                              (src-block? block))
                         content
                         (remove-indentation-spaces content (:level block)))))]
       (if (= format :org)