Browse Source

fix: remove properties

Tienson Qin 4 years ago
parent
commit
bfaa65a996

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

@@ -12,7 +12,6 @@
             [clojure.string :as string]
             [dommy.core :as dom]
             [frontend.utf8 :as utf8]
-            [frontend.util.property :as property]
             ["codemirror" :as cm]
             ["codemirror/addon/edit/matchbrackets"]
             ["codemirror/addon/edit/closebrackets"]
@@ -64,7 +63,7 @@
         (:block/uuid config)
         (let [block (db/pull [:block/uuid (:block/uuid config)])
               format (:block/format block)
-              content (property/remove-properties format (:block/content block))
+              content (:block/content block)
               full-content (:full_content (last (:rum/args state)))]
           (when (and full-content (string/includes? content full-content))
             (let [lines (string/split-lines full-content)

+ 6 - 2
src/main/frontend/util/property.cljs

@@ -89,8 +89,11 @@
 
       (not org?)
       (let [lines (string/split-lines content)
-            non-properties (get (group-by simplified-property? lines) false)]
-        (string/join "\n" non-properties))
+            lines (if (simplified-property? (first lines))
+                    (drop-while simplified-property? lines)
+                    (cons (first lines)
+                          (drop-while simplified-property? (rest lines))))]
+        (string/join "\n" lines))
 
       :else
       content)))
@@ -271,6 +274,7 @@
   [format content]
   (remove-property format "id" content false))
 
+;; FIXME: only remove from the properties area
 (defn remove-built-in-properties
   [format content]
   (let [built-in-properties* (built-in-properties)

+ 10 - 2
src/test/frontend/util/property_test.cljs

@@ -42,10 +42,18 @@
       "** hello"
 
       (property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n")
-      "** hello"
+      "** hello"))
+
+  (testing "invalid-properties"
+    (are [x y] (= x y)
+      (property/remove-properties :markdown "hello\nnice\nfoo:: bar")
+      "hello\nnice\nfoo:: bar"
+
+      (property/remove-properties :markdown "hello\nnice\nfoo:: bar\ntest")
+      "hello\nnice\nfoo:: bar\ntest"
 
       (property/remove-properties :markdown "** hello\nx:: y\n\na:: b\n")
-      "** hello\n")))
+      "** hello\n\na:: b")))
 
 (deftest test-insert-property
   (are [x y] (= x y)