mirror of
https://github.com/logseq/logseq.git
synced 2026-04-25 14:44:53 +00:00
* fix: Date sorting nonsensical * simplify normalize-block * adjusted handling of sets and added tests Co-authored-by: Junyi Du <junyidu.cn@gmail.com>
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
(ns frontend.format.block
|
||||
"Block code needed by app but not graph-parser"
|
||||
(:require [clojure.string :as string]
|
||||
[logseq.graph-parser.block :as gp-block]
|
||||
(:require ["@sentry/react" :as Sentry]
|
||||
[cljs-time.format :as tf]
|
||||
[clojure.string :as string]
|
||||
[frontend.config :as config]
|
||||
[frontend.date :as date]
|
||||
[frontend.db :as db]
|
||||
[frontend.format :as format]
|
||||
[frontend.state :as state]
|
||||
[frontend.handler.notification :as notification]
|
||||
["@sentry/react" :as Sentry]
|
||||
[frontend.state :as state]
|
||||
[logseq.graph-parser.block :as gp-block]
|
||||
[logseq.graph-parser.config :as gp-config]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[logseq.graph-parser.mldoc :as gp-mldoc]))
|
||||
[logseq.graph-parser.mldoc :as gp-mldoc]
|
||||
[logseq.graph-parser.property :as gp-property]))
|
||||
|
||||
(defn extract-blocks
|
||||
"Wrapper around logseq.graph-parser.block/extract-blocks that adds in system state
|
||||
@@ -36,6 +38,29 @@ and handles unexpected failure."
|
||||
([original-page-name with-id? with-timestamp?]
|
||||
(gp-block/page-name->map original-page-name with-id? (db/get-db (state/get-current-repo)) with-timestamp? (state/get-date-formatter))))
|
||||
|
||||
(defn- normalize-as-percentage
|
||||
([block]
|
||||
(some->> block
|
||||
str
|
||||
(re-matches #"(-?\d+\.?\d*)%")
|
||||
second
|
||||
(#(/ % 100)))))
|
||||
|
||||
(defn- normalize-as-date
|
||||
([block]
|
||||
(some->> block
|
||||
str
|
||||
date/valid?
|
||||
(tf/unparse date/custom-formatter))))
|
||||
|
||||
(defn normalize-block
|
||||
"Normalizes supported formats such as dates and percentages."
|
||||
([block]
|
||||
(->> [normalize-as-percentage normalize-as-date identity]
|
||||
(map #(% block))
|
||||
(remove nil?)
|
||||
(first))))
|
||||
|
||||
(defn parse-block
|
||||
([block]
|
||||
(parse-block block nil))
|
||||
|
||||
Reference in New Issue
Block a user