Skip to content

Commit

Permalink
enhance(drawer): properties? and drawer? check
Browse files Browse the repository at this point in the history
  • Loading branch information
llcc authored and tiensonqin committed Aug 30, 2021
1 parent 67f17e2 commit 396f59d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
(string/replace content old new))
content))
content (drawer/insert-drawer
block content "logbook"
format content "logbook"
(util/format (str (if (= :org (state/get-preferred-format)) "-" "*")
" State \"DONE\" from \"%s\" %s")
marker
Expand Down
14 changes: 3 additions & 11 deletions src/main/frontend/util/drawer.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns frontend.util.drawer
(:require [clojure.string :as string]
[frontend.handler.block :as block-handler]
[frontend.util :as util]
[frontend.util.property :as property]
[frontend.format.mldoc :as mldoc]))
Expand All @@ -19,20 +18,13 @@
(string/join "\n" [(drawer-start typ) value drawer-end])
(string/join "\n" [(drawer-start typ) drawer-end]))))

(defn drawer-block?
[block]
(and
(vector? block)
(= "Drawer" (first block))))

(defn insert-drawer
[{:block/keys [format] :as block} content typ value]
[format content typ value]
(when (string? content)
(try
(let [ast (mldoc/->edn content (mldoc/default-config format))
has-properties? (mldoc/properties? (second ast))
has-typ-drawer? (mldoc/typ-drawer?
(nth ast (if has-properties? 2 1)) typ)
has-properties? (some (fn [x] (mldoc/properties? x)) ast)
has-typ-drawer? (some (fn [x] (mldoc/typ-drawer? x typ)) ast)
lines (string/split-lines content)
title (first lines)
body (string/join "\n" (rest lines))
Expand Down

0 comments on commit 396f59d

Please sign in to comment.