Skip to content

Commit

Permalink
feat(blocks, parser): adds correct parsing for nested page links in h… (
Browse files Browse the repository at this point in the history
#311)

* feat(blocks, parser): adds correct parsing for nested page links in hashtags; add auto link for hashtags and page links

* style: fix testing code style
  • Loading branch information
thesophiaxu authored Jul 31, 2020
1 parent cf87fe6 commit 55c89e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cljc/athens/parser.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
hashtag = hashtag-bare | hashtag-delimited
<hashtag-bare> = <'#'> #'[^\\ \\+\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\?\\\"\\;\\:\\]\\[]+' (* Unicode: L = letters, M = combining marks, N = numbers *)
<hashtag-delimited> = <'#'> <'[['> #'[^\\]]+' <']]'>
<hashtag-delimited> = <'#'> <'[['> page-link-content <']]'>
url-image = <'!'> url-link-text url-link-url
Expand Down
7 changes: 4 additions & 3 deletions src/cljs/athens/parse_renderer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@
(let [block (pull db/dsdb '[*] [:block/uid uid])]
[:span (use-style block-ref {:class "block-ref"})
[:span {:class "contents" :on-click #(navigate-uid uid)} (parse-and-render (:block/string @block) uid)]]))
:hashtag (fn [tag-name]
(let [node (pull db/dsdb '[*] [:node/title tag-name])]
:hashtag (fn [& tag-name]
(let [parsed-name (concat tag-name)
node (pull db/dsdb '[*] [:node/title parsed-name])]
[:span (use-style hashtag {:class "hashtag"
:on-click #(navigate-uid (:block/uid @node))})
[:span {:class "formatting"} "#"]
[:span {:class "contents"} tag-name]]))
[:span {:class "contents"} parsed-name]]))
:url-image (fn [{url :url alt :alt}]
[:img (use-style image {:class "url-image"
:alt alt
Expand Down
14 changes: 8 additions & 6 deletions src/cljs/athens/views/blocks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@
uid (gen-block-uid)]
(db-fn inner-title now uid)))
(str "[[" inner-title "]]")))
:hashtag (fn [title]
(when (and (string? title) (link-fn title))
(let [now (now-ts)
uid (gen-block-uid)]
(db-fn title now uid)))
(str "#" title))} (parser/parse-to-ast source-str)))
:hashtag (fn [& title]
(let [inner-title (apply + title)]
(when (and (string? inner-title)
(link-fn inner-title))
(let [now (now-ts)
uid (gen-block-uid)]
(db-fn inner-title now uid)))
(str "#" inner-title)))} (parser/parse-to-ast source-str)))


(defn on-change
Expand Down
3 changes: 3 additions & 0 deletions test/athens/parser_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
[:block "that’s " [:hashtag "very cool"] ", yeah"]
"that’s #[[very cool]], yeah"

[:block "also here's " [:hashtag "nested " [:page-link "links"]] " in hashtags!"]
"also here's #[[nested [[links]]]] in hashtags!"

[:block "Ends after " [:hashtag "words_are_over"] "!"]
"Ends after #words_are_over!"

Expand Down

0 comments on commit 55c89e7

Please sign in to comment.