forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move block-ref fns and vars to their own ns
Similar to page-ref to keep namespaces explicit
- Loading branch information
1 parent
e0b1f6b
commit 4ec5827
Showing
18 changed files
with
107 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
deps/graph-parser/src/logseq/graph_parser/util/block_ref.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns logseq.graph-parser.util.block-ref | ||
"General purpose vars and util fns for block-refs" | ||
(:require [clojure.string :as string])) | ||
|
||
(def left-parens "Opening characters for block-ref" "((") | ||
(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 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))) | ||
|
||
(defn ->block-ref | ||
"Creates block ref string given id" | ||
[block-id] | ||
(str left-parens block-id right-parens)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.