|
|
@@ -132,13 +132,11 @@
|
|
|
[:editor/set-heading heading]
|
|
|
[:editor/move-cursor-to-end]])
|
|
|
|
|
|
-(defn- markdown-headings
|
|
|
+(defn- headings
|
|
|
[]
|
|
|
- (let [format (state/get-preferred-format)]
|
|
|
- (when (= (name format) "markdown")
|
|
|
- (mapv (fn [level]
|
|
|
- (let [heading (str "h" level)]
|
|
|
- [heading (->heading (apply str (repeat level "#")))])) (range 1 7)))))
|
|
|
+ (mapv (fn [level]
|
|
|
+ (let [heading (str "h" level)]
|
|
|
+ [heading (->heading level)])) (range 1 7)))
|
|
|
|
|
|
(defonce *matched-commands (atom nil))
|
|
|
(defonce *initial-commands (atom nil))
|
|
|
@@ -241,7 +239,7 @@
|
|
|
;; ["Upload an image" [[:editor/click-hidden-file-input :id]]]
|
|
|
)]
|
|
|
|
|
|
- (markdown-headings)
|
|
|
+ (headings)
|
|
|
|
|
|
;; time & date
|
|
|
|
|
|
@@ -593,19 +591,33 @@
|
|
|
(property/goto-properties-end format current-input)
|
|
|
(cursor/move-cursor-backward current-input 3)))))
|
|
|
|
|
|
+(defonce markdown-heading-pattern #"^#+\s+")
|
|
|
+(defn set-markdown-heading
|
|
|
+ [content heading]
|
|
|
+ (let [heading-str (apply str (repeat heading "#"))]
|
|
|
+ (if (util/safe-re-find markdown-heading-pattern content)
|
|
|
+ (string/replace-first content
|
|
|
+ markdown-heading-pattern
|
|
|
+ (str heading-str " "))
|
|
|
+ (str heading-str " " (string/triml content)))))
|
|
|
+
|
|
|
+(defn clear-markdown-heading
|
|
|
+ [content]
|
|
|
+ [:pre (string? content)]
|
|
|
+ (string/replace-first content
|
|
|
+ markdown-heading-pattern
|
|
|
+ ""))
|
|
|
+
|
|
|
(defmethod handle-step :editor/set-heading [[_ heading]]
|
|
|
(when-let [input-id (state/get-edit-input-id)]
|
|
|
(when-let [current-input (gdom/getElement input-id)]
|
|
|
- (let [edit-content (gobj/get current-input "value")
|
|
|
- heading-pattern #"^#+\s+"
|
|
|
- new-value (cond
|
|
|
- (util/safe-re-find heading-pattern edit-content)
|
|
|
- (string/replace-first edit-content
|
|
|
- heading-pattern
|
|
|
- (str heading " "))
|
|
|
- :else
|
|
|
- (str heading " " (string/triml edit-content)))]
|
|
|
- (state/set-edit-content! input-id new-value)))))
|
|
|
+ (let [current-block (state/get-edit-block)
|
|
|
+ format (:block/format current-block)]
|
|
|
+ (if (= format :markdown)
|
|
|
+ (let [edit-content (gobj/get current-input "value")
|
|
|
+ new-content (set-markdown-heading edit-content heading)]
|
|
|
+ (state/set-edit-content! input-id new-content))
|
|
|
+ (state/pub-event! [:editor/set-org-mode-heading current-block heading]))))))
|
|
|
|
|
|
(defmethod handle-step :editor/search-page [[_]]
|
|
|
(state/set-editor-action! :page-search))
|