|
|
@@ -13,14 +13,22 @@
|
|
|
(defn add-or-update-marker
|
|
|
[content format marker]
|
|
|
(let [[re-pattern new-line-re-pattern]
|
|
|
- (if (= :org format)
|
|
|
- [#"\*+\s" #"\n\*+\s"]
|
|
|
- [#"#+\s" #"\n#+\s"])
|
|
|
+ (case format
|
|
|
+ :org
|
|
|
+ [#"^\*+\s" #"\n\*+\s"]
|
|
|
+
|
|
|
+ :markdown
|
|
|
+ [#"^#+\s" #"\n#+\s"]
|
|
|
+
|
|
|
+ ;; failback to makrdown
|
|
|
+ [#"^#+\s" #"\n#+\s"])
|
|
|
+
|
|
|
pos
|
|
|
(if-let [matches (seq (util/re-pos new-line-re-pattern content))]
|
|
|
(let [[start-pos content] (last matches)]
|
|
|
(+ start-pos (count content)))
|
|
|
(count (util/safe-re-find re-pattern content)))
|
|
|
+
|
|
|
new-content
|
|
|
(str (subs content 0 pos)
|
|
|
(string/replace-first (subs content pos)
|
|
|
@@ -57,8 +65,8 @@
|
|
|
Returns [new-content new-marker]."
|
|
|
[content marker new-marker format preferred-workflow]
|
|
|
(let [content (string/triml content)
|
|
|
- new-marker (or new-marker
|
|
|
- (cycle-marker-state (or marker
|
|
|
- (last (util/safe-re-find (marker-pattern format) content))) ; Returns the last matching group (last vec)
|
|
|
- preferred-workflow))]
|
|
|
+ marker (or (not-empty marker)
|
|
|
+ (last (util/safe-re-find (marker-pattern format) content))) ; Returns the last matching group (last vec)
|
|
|
+ new-marker (or (not-empty new-marker)
|
|
|
+ (cycle-marker-state marker preferred-workflow))]
|
|
|
[(add-or-update-marker content format new-marker) new-marker]))
|