|
|
@@ -36,8 +36,31 @@
|
|
|
(def right-parens "Closing characters for block-ref" "))")
|
|
|
(def left-and-right-parens "Opening and closing characters for block-ref"
|
|
|
(str left-parens right-parens))
|
|
|
+(def block-ref-re #"\(\(([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\)\)")
|
|
|
|
|
|
-(defn block-ref-string?
|
|
|
+(defn get-all-block-ref-ids
|
|
|
+ [content]
|
|
|
+ (map second (re-seq block-ref-re content)))
|
|
|
+
|
|
|
+(defn get-block-ref-id
|
|
|
+ "Extracts block id from block-ref using regex"
|
|
|
+ [s]
|
|
|
+ (second (re-matches block-ref-re s)))
|
|
|
+
|
|
|
+(defn get-string-block-ref-id
|
|
|
+ "Extracts block id from block-ref by stripping parens e.g. ((123)) -> 123.
|
|
|
+ This is a less strict version of get-block-ref-id"
|
|
|
+ [s]
|
|
|
+ (subs s 2 (- (count s) 2)))
|
|
|
+
|
|
|
+(defn block-ref?
|
|
|
+ "Determines if string is block ref using regex"
|
|
|
+ [s]
|
|
|
+ (boolean (get-block-ref-id s)))
|
|
|
+
|
|
|
+(defn string-block-ref?
|
|
|
+ "Determines if string is block ref by checking parens. This is less strict version
|
|
|
+of block-ref?"
|
|
|
[s]
|
|
|
(and (string/starts-with? s left-parens)
|
|
|
(string/ends-with? s right-parens)))
|
|
|
@@ -47,11 +70,6 @@
|
|
|
[block-id]
|
|
|
(str left-parens block-id right-parens))
|
|
|
|
|
|
-(defn block-ref->block-id
|
|
|
- "Extracts block id from block-ref string e.g. ((123)) -> 123."
|
|
|
- [s]
|
|
|
- (subs s 2 (- (count s) 2)))
|
|
|
-
|
|
|
(defn- get-page-reference
|
|
|
[block supported-formats]
|
|
|
(let [page (cond
|
|
|
@@ -111,7 +129,7 @@
|
|
|
|
|
|
:else
|
|
|
nil)]
|
|
|
- (text/block-ref-un-brackets! page)))
|
|
|
+ (when page (or (get-block-ref-id page) page))))
|
|
|
|
|
|
(defn- get-block-reference
|
|
|
[block]
|
|
|
@@ -131,8 +149,8 @@
|
|
|
(let [{:keys [name arguments]} (second block)]
|
|
|
(when (and (= name "embed")
|
|
|
(string? (first arguments))
|
|
|
- (block-ref-string? (first arguments)))
|
|
|
- (block-ref->block-id (first arguments))))
|
|
|
+ (string-block-ref? (first arguments)))
|
|
|
+ (get-string-block-ref-id (first arguments))))
|
|
|
|
|
|
(and (vector? block)
|
|
|
(= "Link" (first block))
|
|
|
@@ -140,7 +158,9 @@
|
|
|
(if (= "id" (:protocol (second (:url (second block)))))
|
|
|
(:link (second (:url (second block))))
|
|
|
(let [id (second (:url (second block)))]
|
|
|
- (text/block-ref-un-brackets! id)))
|
|
|
+ ;; these can be maps
|
|
|
+ (when (string? id)
|
|
|
+ (or (get-block-ref-id id) id))))
|
|
|
|
|
|
:else
|
|
|
nil)]
|