Emit image links as image embeds rather than as html links

pull/2867/head
angusiguess 2021-09-22 17:46:16 -03:00 committed by Tienson Qin
parent 32ddeaa3c8
commit 695765df78
2 changed files with 27 additions and 1 deletions

View File

@ -56,6 +56,15 @@
:id :label
:placeholder "Label"}]]])
(def image-link-steps [[:editor/input (str slash "link")]
[:editor/show-input [{:command :image-link
:id :link
:placeholder "Link"
:autoFocus true}
{:command :image-link
:id :label
:placeholder "Label"}]]])
(def zotero-steps [[:editor/input (str slash "zotero")]
[:editor/show-zotero]])
@ -226,7 +235,7 @@
[:editor/search-block :reference]] "Create a backlink to a block"]
["Block embed" (embed-block) "Embed a block here" "Embed a block here"]
["Link" link-steps "Create a HTTP link"]
["Image link" link-steps "Create a HTTP link to a image"]
["Image link" image-link-steps "Create a HTTP link to a image"]
(when (state/markdown?)
["Underline" [[:editor/input "<ins></ins>"
{:last-pattern slash

View File

@ -1826,6 +1826,14 @@
:org (util/format "[[%s][%s]]" link label)
nil)))
(defn- get-image-link
[format link label]
(let [link (or link "")
label (or label "")]
(case (keyword format)
:markdown (util/format "![%s](%s)" label link)
:org (util/format "[[%s]]"))))
(defn handle-command-input
[command id format m pos]
(case command
@ -1838,6 +1846,15 @@
(get-link format link label)
format
{:last-pattern (str commands/slash "link")})))
:image-link
(let [{:keys [link label]} m]
(if (and (string/blank? link)
(string/blank? label))
nil
(insert-command! id
(get-image-link format link label)
format
{:last-pattern (str commands/slash "link")})))
nil)
(state/set-editor-show-input! nil)