Skip to content

Commit

Permalink
Split out text ns to graph-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
logseq-cldwalker committed May 11, 2022
1 parent f529777 commit 65804b4
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 103 deletions.
6 changes: 3 additions & 3 deletions docs/dev-practices.md
Expand Up @@ -101,9 +101,9 @@ For this workflow:
1. Add `^:focus` metadata flags to tests e.g. `(deftest ^:focus test-name ...)`.
2. In another shell, run `node static/tests.js -i focus` to only run those
tests. To run all tests except those tests run `node static/tests.js -e focus`.
3. Or focus namespaces: Using the regex option `-r`, run tests for `frontend.text-test` with `node static/tests.js -r text`.
3. Or focus namespaces: Using the regex option `-r`, run tests for `frontend.util.page-property-test` with `node static/tests.js -r page-property`.

Multiple options can be specified to AND selections. For example, to run all `frontend.text-test` tests except for the focused one: `node static/tests.js -r text -e focus`
Multiple options can be specified to AND selections. For example, to run all `frontend.util.page-property-test` tests except for the focused one: `node static/tests.js -r page-property -e focus`

For help on more options, run `node static/tests.js -h`.

Expand All @@ -114,7 +114,7 @@ shadow-cljs watch test --config-merge '{:autorun true}'`. The test output may
appear where shadow-cljs was first invoked e.g. where `yarn watch` is running.
Specific namespace(s) can be auto run with the `:ns-regexp` option e.g. `npx
shadow-cljs watch test --config-merge '{:autorun true :ns-regexp
"frontend.text-test"}'`.
"frontend.util.page-property-test"}'`.

## Logging

Expand Down
14 changes: 7 additions & 7 deletions src/main/frontend/components/block.cljs
Expand Up @@ -45,7 +45,7 @@
[frontend.security :as security]
[frontend.state :as state]
[frontend.template :as template]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.ui :as ui]
[frontend.util :as util]
[frontend.util.clock :as clock]
Expand Down Expand Up @@ -726,7 +726,7 @@
(defn- render-macro
[config name arguments macro-content format]
(if macro-content
(let [ast (->> (gp-mldoc/->edn macro-content (gp-mldoc/default-config format))
(let [ast (->> (mldoc/->edn macro-content (gp-mldoc/default-config format))
(map first))
paragraph? (and (= 1 (count ast))
(= "Paragraph" (ffirst ast)))]
Expand Down Expand Up @@ -853,7 +853,7 @@
(not (string/includes? s "."))
(page-reference (:html-export? config) s config label)

(util/url? s)
(gp-util/url? s)
(->elem :a {:href s
:data-href s
:target "_blank"}
Expand Down Expand Up @@ -1703,8 +1703,8 @@
(for [elem elems]
(rum/with-key elem (str (random-uuid)))))

(and (string? v) (util/wrapped-by-quotes? v))
(util/unquote-string v)
(and (string? v) (gp-util/wrapped-by-quotes? v))
(gp-util/unquote-string v)

:else
(inline-text config (:block/format block) (str v)))]))
Expand Down Expand Up @@ -2708,11 +2708,11 @@
;; (cond
;; (= lang "quote")
;; (let [content (string/trim (string/join "\n" lines))]
;; ["Quote" (first (gp-mldoc/->edn content (gp-mldoc/default-config :markdown)))])
;; ["Quote" (first (mldoc/->edn content (gp-mldoc/default-config :markdown)))])

;; (contains? #{"query" "note" "tip" "important" "caution" "warning" "pinned"} lang)
;; (let [content (string/trim (string/join "\n" lines))]
;; ["Custom" lang nil (first (gp-mldoc/->edn content (gp-mldoc/default-config :markdown))) content])
;; ["Custom" lang nil (first (mldoc/->edn content (gp-mldoc/default-config :markdown))) content])

;; :else
;; ["Src" options])))
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/hierarchy.cljs
Expand Up @@ -4,7 +4,7 @@
[frontend.db :as db]
[frontend.db.model :as db-model]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.ui :as ui]
[medley.core :as medley]
[rum.core :as rum]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/journal.cljs
Expand Up @@ -8,7 +8,7 @@
[frontend.db.model :as model]
[frontend.handler.page :as page-handler]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.ui :as ui]
[frontend.util :as util]
[goog.object :as gobj]
Expand Down
6 changes: 3 additions & 3 deletions src/main/frontend/components/page.cljs
Expand Up @@ -26,7 +26,7 @@
[frontend.handler.route :as route-handler]
[frontend.mixins :as mixins]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.search :as search]
[frontend.ui :as ui]
[frontend.util :as util]
Expand Down Expand Up @@ -215,8 +215,8 @@
(reset! *edit? false)
(notification/show! "Illegal page name, can not rename!" :warning))
blur-fn (fn [e]
(when (util/wrapped-by-quotes? @*title-value)
(swap! *title-value util/unquote-string)
(when (gp-util/wrapped-by-quotes? @*title-value)
(swap! *title-value gp-util/unquote-string)
(gobj/set (rum/deref input-ref) "value" @*title-value))
(state/set-state! :editor/editing-page-title? false)
(cond
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/repo.cljs
Expand Up @@ -14,7 +14,7 @@
[reitit.frontend.easy :as rfe]
[rum.core :as rum]
[frontend.mobile.util :as mobile-util]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[promesa.core :as p]
[electron.ipc :as ipc]
[goog.object :as gobj]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/components/select.cljs
Expand Up @@ -10,7 +10,7 @@
[frontend.ui :as ui]
[frontend.util :as util]
[frontend.db :as db]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[rum.core :as rum]
[frontend.config :as config]
[frontend.handler.repo :as repo-handler]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/conn.cljs
Expand Up @@ -7,7 +7,7 @@
[frontend.mobile.util :as mobile-util]
[frontend.state :as state]
[frontend.config :as config]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[logseq.graph-parser.util :as gp-util]
[datascript.core :as d]))

Expand Down
7 changes: 4 additions & 3 deletions src/main/frontend/db/query_dsl.cljs
Expand Up @@ -6,13 +6,14 @@
[clojure.set :as set]
[clojure.string :as string]
[clojure.walk :as walk]
[frontend.state :as state]
[frontend.date :as date]
[frontend.db.model :as model]
[frontend.db.query-react :as query-react]
[frontend.db.utils :as db-utils]
[frontend.db.rules :as rules]
[frontend.template :as template]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.util :as util]
[logseq.graph-parser.util :as gp-util]))

Expand Down Expand Up @@ -238,7 +239,7 @@
(let [k (string/replace (name (nth e 1)) "_" "-")
v (nth e 2)
v (if-not (nil? v)
(text/parse-property k v)
(text/parse-property k v (state/get-config))
v)
v (if (coll? v) (first v) v)]
{:query (list 'property '?b (keyword k) v)
Expand Down Expand Up @@ -283,7 +284,7 @@
(let [[k v] (rest e)
k (string/replace (name k) "_" "-")]
(if (some? v)
(let [v' (text/parse-property k v)
(let [v' (text/parse-property k v (state/get-config))
val (if (coll? v') (first v') v')]
{:query (list 'page-property '?p (keyword k) val)
:rules [:page-property]})
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/query_react.cljs
Expand Up @@ -10,7 +10,7 @@
[frontend.debug :as debug]
[frontend.extensions.sci :as sci]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.util :as util]
[logseq.graph-parser.util :as gp-util]
[lambdaisland.glogi :as log]))
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/diff.cljs
Expand Up @@ -6,7 +6,7 @@
[cljs-bean.core :as bean]
[frontend.util :as util]
[logseq.graph-parser.util :as gp-util]
[frontend.text :as text]))
[logseq.graph-parser.text :as text]))

(defn diff
[s1 s2]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/external/roam.cljs
Expand Up @@ -7,7 +7,7 @@
[clojure.string :as string]
[frontend.util :as util]
[logseq.graph-parser.util :as gp-util]
[frontend.text :as text]))
[logseq.graph-parser.text :as text]))

(defonce all-refed-uids (atom #{}))
(defonce uid->uuid (atom {}))
Expand Down
3 changes: 0 additions & 3 deletions src/main/frontend/format.cljs
Expand Up @@ -2,12 +2,9 @@
(:require [frontend.format.mldoc :refer [->MldocMode] :as mldoc]
[frontend.format.adoc :refer [->AdocMode]]
[frontend.format.protocol :as protocol]
[frontend.text :as text]
[logseq.graph-parser.mldoc :as gp-mldoc]
[clojure.string :as string]))

(set! gp-mldoc/parse-property text/parse-property)

(defonce mldoc-record (->MldocMode))
(defonce adoc-record (->AdocMode))

Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/format/block.cljs
Expand Up @@ -7,7 +7,7 @@
[frontend.db :as db]
[frontend.format :as format]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.utf8 :as utf8]
[frontend.util :as util]
[frontend.util.property :as property]
Expand Down Expand Up @@ -185,7 +185,7 @@
(remove string/blank? v)
(if (string/blank? v)
nil
(text/parse-property format k v)))
(text/parse-property format k v (state/get-config))))
k (keyword k)
v (if (and
(string? v)
Expand Down
10 changes: 8 additions & 2 deletions src/main/frontend/format/mldoc.cljs
@@ -1,6 +1,7 @@
(ns frontend.format.mldoc
(:require [clojure.string :as string]
[frontend.format.protocol :as protocol]
[frontend.state :as state]
[goog.object :as gobj]
[lambdaisland.glogi :as log]
["mldoc" :as mldoc :refer [Mldoc]]
Expand Down Expand Up @@ -43,15 +44,20 @@
(if (string/blank? content)
{}
(let [[headers blocks] (-> content (parse-opml) (gp-util/json->clj))]
[headers (gp-mldoc/collect-page-properties blocks gp-mldoc/parse-property)]))
[headers (gp-mldoc/collect-page-properties blocks gp-mldoc/parse-property (state/get-config))]))
(catch js/Error e
(log/error :edn/convert-failed e)
[])))

(defn ->edn
"Wrapper around gp-mldoc/->edn which provides config state"
[content config]
(gp-mldoc/->edn content config (state/get-config)))

(defrecord MldocMode []
protocol/Format
(toEdn [_this content config]
(gp-mldoc/->edn content config))
(->edn content config))
(toHtml [_this content config references]
(export "html" content config references))
(loaded? [_this]
Expand Down
16 changes: 8 additions & 8 deletions src/main/frontend/handler/editor.cljs
Expand Up @@ -34,7 +34,7 @@
[frontend.search :as search]
[frontend.state :as state]
[frontend.template :as template]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.utf8 :as utf8]
[frontend.util :as util :refer [profile]]
[frontend.util.clock :as clock]
Expand Down Expand Up @@ -357,7 +357,7 @@
content (drawer/with-logbook block content)
content (with-timetracking block content)
first-block? (= left page)
ast (gp-mldoc/->edn (string/trim content) (gp-mldoc/default-config format))
ast (mldoc/->edn (string/trim content) (gp-mldoc/default-config format))
first-elem-type (first (ffirst ast))
first-elem-meta (second (ffirst ast))
properties? (contains? #{"Property_Drawer" "Properties"} first-elem-type)
Expand Down Expand Up @@ -1942,7 +1942,7 @@
props (into [] (:properties block))
content* (str (if (= :markdown format) "- " "* ")
(property/insert-properties format content props))
ast (gp-mldoc/->edn content* (gp-mldoc/default-config format))
ast (mldoc/->edn content* (gp-mldoc/default-config format))
blocks (block/extract-blocks ast content* true format)
fst-block (first blocks)]
(assert fst-block "fst-block shouldn't be nil")
Expand Down Expand Up @@ -2851,7 +2851,7 @@
(when-let [editing-block (state/get-edit-block)]
(let [page-id (:db/id (:block/page editing-block))
blocks (block/extract-blocks
(gp-mldoc/->edn text (gp-mldoc/default-config format)) text true format)
(mldoc/->edn text (gp-mldoc/default-config format)) text true format)
blocks' (block/with-parent-and-left page-id blocks)]
(paste-blocks blocks' {}))))

Expand Down Expand Up @@ -2902,17 +2902,17 @@
(state/set-copied-full-blocks! blocks)
(paste-blocks blocks {})))

(and (util/url? text)
(and (gp-util/url? text)
(not (string/blank? (util/get-selected-text))))
(html-link-format! text)

(and (util/url? text)
(and (gp-util/url? text)
(or (string/includes? text "youtube.com")
(string/includes? text "youtu.be"))
(mobile-util/is-native-platform?))
(commands/simple-insert! (state/get-edit-input-id) (util/format "{{youtube %s}}" text) nil)

(and (util/url? text)
(and (gp-util/url? text)
(string/includes? text "twitter.com")
(mobile-util/is-native-platform?))
(commands/simple-insert! (state/get-edit-input-id) (util/format "{{twitter %s}}" text) nil)
Expand Down Expand Up @@ -3169,7 +3169,7 @@
[format content semantic?]
(and (string/includes? content "\n")
(if semantic?
(let [ast (gp-mldoc/->edn content (gp-mldoc/default-config format))
(let [ast (mldoc/->edn content (gp-mldoc/default-config format))
first-elem-type (first (ffirst ast))]
(mldoc/block-with-title? first-elem-type))
true)))
Expand Down
5 changes: 3 additions & 2 deletions src/main/frontend/handler/export.cljs
Expand Up @@ -15,6 +15,7 @@
[frontend.publishing.html :as html]
[frontend.state :as state]
[frontend.util :as util]
[frontend.format.mldoc :as mldoc]
[logseq.graph-parser.mldoc :as gp-mldoc]
[goog.dom :as gdom]
[promesa.core :as p])
Expand Down Expand Up @@ -214,7 +215,7 @@
(let [block (db/entity [:block/uuid (uuid block-uuid)])
block-content (get-blocks-contents repo (:block/uuid block))
format (:block/format block)
ast (gp-mldoc/->edn block-content (gp-mldoc/default-config format))
ast (mldoc/->edn block-content (gp-mldoc/default-config format))
embed-pages-new (get-embed-pages-from-ast ast)
embed-blocks-new (get-embed-blocks-from-ast ast)
block-refs-new (get-block-refs-from-ast ast)
Expand Down Expand Up @@ -258,7 +259,7 @@
(let [page-name* (util/page-name-sanity-lc page-name)
page-content (get-page-content repo page-name*)
format (:block/format (db/entity [:block/name page-name*]))
ast (gp-mldoc/->edn page-content (gp-mldoc/default-config format))
ast (mldoc/->edn page-content (gp-mldoc/default-config format))
embed-pages-new (get-embed-pages-from-ast ast)
embed-blocks-new (get-embed-blocks-from-ast ast)
block-refs-new (get-block-refs-from-ast ast)
Expand Down
7 changes: 4 additions & 3 deletions src/main/frontend/handler/extract.cljs
Expand Up @@ -7,8 +7,9 @@
[frontend.db :as db]
[frontend.format :as format]
[frontend.format.block :as block]
[frontend.format.mldoc :as mldoc]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.util :as util]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.mldoc :as gp-mldoc]
Expand Down Expand Up @@ -142,7 +143,7 @@
[]
(let [format (format/get-format file)
_ (println "Parsing start: " file)
ast (gp-mldoc/->edn content (gp-mldoc/default-config format
ast (mldoc/->edn content (gp-mldoc/default-config format
;; {:parse_outline_only? true}
))]
(println "Parsing finished : " file)
Expand All @@ -151,7 +152,7 @@
(->> (last first-block)
(map (fn [[x y]]
[x (if (string? y)
(text/parse-property format x y)
(text/parse-property format x y (state/get-config))
y)]))
(into {})
(walk/keywordize-keys)))]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/route.cljs
Expand Up @@ -7,7 +7,7 @@
[frontend.handler.recent :as recent-handler]
[frontend.handler.search :as search-handler]
[frontend.state :as state]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.util :as util]
[logseq.graph-parser.util :as gp-util]
[medley.core :as medley]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/search.cljs
Expand Up @@ -7,7 +7,7 @@
[frontend.state :as state]
[frontend.util :as util]
[promesa.core :as p]
[frontend.text :as text]
[logseq.graph-parser.text :as text]
[frontend.util.drawer :as drawer]
[frontend.util.property :as property]))

Expand Down

0 comments on commit 65804b4

Please sign in to comment.