mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 00:24:51 +00:00
Page references wip
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
(ns frontend.format.org.block
|
||||
(:require [frontend.util :as util]))
|
||||
(:require [frontend.util :as util]
|
||||
[clojure.walk :as walk]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(defn heading-block?
|
||||
[block]
|
||||
@@ -7,6 +9,12 @@
|
||||
(vector? block)
|
||||
(= "Heading" (first block))))
|
||||
|
||||
(defn target-block?
|
||||
[block]
|
||||
(and
|
||||
(vector? block)
|
||||
(contains? #{"Target" "Radio_Target"} (first block))))
|
||||
|
||||
(defn task-block?
|
||||
[block]
|
||||
(and
|
||||
@@ -51,6 +59,17 @@
|
||||
:tag/name tag})
|
||||
tags))
|
||||
|
||||
(defn with-refs
|
||||
[{:keys [title children] :as heading}]
|
||||
(let [ref-pages (atom [])]
|
||||
(walk/postwalk
|
||||
(fn [form]
|
||||
(when (target-block? form)
|
||||
(swap! ref-pages conj (string/lower-case (last form))))
|
||||
form)
|
||||
(concat title children))
|
||||
(assoc heading :ref-pages (vec @ref-pages))))
|
||||
|
||||
;; TODO create a dummy heading if no headings exists
|
||||
(defn extract-headings
|
||||
[blocks last-pos]
|
||||
@@ -74,6 +93,7 @@
|
||||
:timestamps timestamps)
|
||||
(assoc-in [:meta :end-pos] last-pos)
|
||||
(update :tags ->tags))
|
||||
heading (with-refs heading)
|
||||
last-pos' (get-in heading [:meta :pos])]
|
||||
(recur (conj headings heading) [] (rest blocks) {} last-pos'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user