mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 19:36:35 +00:00
fix: can't parse graphs because of links regular expressions
close #4308
This commit is contained in:
@@ -150,7 +150,7 @@
|
||||
|
||||
;; TODO: we should move this to mldoc
|
||||
(defn extract-properties
|
||||
[properties]
|
||||
[format properties]
|
||||
(when (seq properties)
|
||||
(let [properties (seq properties)
|
||||
page-refs (->>
|
||||
@@ -179,7 +179,7 @@
|
||||
(remove string/blank? v)
|
||||
(if (string/blank? v)
|
||||
nil
|
||||
(text/parse-property k v)))
|
||||
(text/parse-property format k v)))
|
||||
k (keyword k)
|
||||
v (if (and
|
||||
(string? v)
|
||||
@@ -413,7 +413,7 @@
|
||||
(if (or (:pre-block? block)
|
||||
(= (:format block) :org))
|
||||
content
|
||||
(text/remove-indentation-spaces content (inc (:level block)) false))))]
|
||||
(mldoc/remove-indentation-spaces content (inc (:level block)) false))))]
|
||||
(if (= format :org)
|
||||
content
|
||||
(property/->new-properties content))))
|
||||
@@ -516,7 +516,7 @@
|
||||
(recur headings (rest blocks) timestamps' properties last-pos last-level children (conj block-all-content block-content) body))
|
||||
|
||||
(property/properties-ast? block)
|
||||
(let [properties (extract-properties (second block))]
|
||||
(let [properties (extract-properties format (second block))]
|
||||
(recur headings (rest blocks) timestamps properties last-pos last-level children (conj block-all-content block-content) body))
|
||||
|
||||
(heading-block? block)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require [cljs-bean.core :as bean]
|
||||
[clojure.string :as string]
|
||||
[frontend.format.protocol :as protocol]
|
||||
[frontend.text :as text]
|
||||
[frontend.utf8 :as utf8]
|
||||
[frontend.util :as util]
|
||||
[goog.object :as gobj]
|
||||
@@ -87,6 +86,18 @@
|
||||
config
|
||||
(or references default-references)))
|
||||
|
||||
(defn remove-indentation-spaces
|
||||
[s level remove-first-line?]
|
||||
(let [lines (string/split-lines s)
|
||||
[f & r] lines
|
||||
body (map (fn [line]
|
||||
(if (string/blank? (util/safe-subs line 0 level))
|
||||
(util/safe-subs line level)
|
||||
line))
|
||||
(if remove-first-line? lines r))
|
||||
content (if remove-first-line? body (cons f body))]
|
||||
(string/join "\n" content)))
|
||||
|
||||
(defn- ->vec
|
||||
[s]
|
||||
(if (string? s) [s] s))
|
||||
@@ -99,7 +110,7 @@
|
||||
(distinct)))
|
||||
|
||||
(defn collect-page-properties
|
||||
[ast]
|
||||
[ast parse-property]
|
||||
(if (seq ast)
|
||||
(let [original-ast ast
|
||||
ast (map first ast) ; without position meta
|
||||
@@ -119,7 +130,7 @@
|
||||
(let [k (keyword (string/lower-case k))
|
||||
v (if (contains? #{:title :description :filters :macro} k)
|
||||
v
|
||||
(text/parse-property k v))]
|
||||
(parse-property k v))]
|
||||
[k v]))))
|
||||
properties (into (linked/map) properties)
|
||||
macro-properties (filter (fn [x] (= :macro (first x))) properties)
|
||||
@@ -168,7 +179,7 @@
|
||||
(let [{:keys [start_pos end_pos]} pos-meta
|
||||
content (utf8/substring content start_pos end_pos)
|
||||
spaces (re-find #"^[\t ]+" (first (string/split-lines content)))
|
||||
content (if spaces (text/remove-indentation-spaces content (count spaces) true)
|
||||
content (if spaces (remove-indentation-spaces content (count spaces) true)
|
||||
content)
|
||||
block ["Src" (assoc (second block) :full_content content)]]
|
||||
[block pos-meta])
|
||||
@@ -181,6 +192,8 @@
|
||||
"Hiccup"
|
||||
"Heading"} type))
|
||||
|
||||
(def parse-property nil)
|
||||
|
||||
(defn ->edn
|
||||
[content config]
|
||||
(if (string? content)
|
||||
@@ -191,7 +204,7 @@
|
||||
(parse-json config)
|
||||
(util/json->clj)
|
||||
(update-src-full-content content)
|
||||
(collect-page-properties)))
|
||||
(collect-page-properties parse-property)))
|
||||
(catch js/Error e
|
||||
(js/console.error e)
|
||||
[]))
|
||||
@@ -203,7 +216,7 @@
|
||||
(if (string/blank? content)
|
||||
{}
|
||||
(let [[headers blocks] (-> content (parse-opml) (util/json->clj))]
|
||||
[headers (collect-page-properties blocks)]))
|
||||
[headers (collect-page-properties blocks parse-property)]))
|
||||
(catch js/Error e
|
||||
(log/error :edn/convert-failed e)
|
||||
[])))
|
||||
@@ -246,3 +259,8 @@
|
||||
[ast typ]
|
||||
(and (contains? #{"Drawer"} (ffirst ast))
|
||||
(= typ (second (first ast)))))
|
||||
|
||||
(defn link?
|
||||
[format link]
|
||||
(when (string? link)
|
||||
(= "Link" (ffirst (inline->edn link (default-config format))))))
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
(ns frontend.format.mldoc-test
|
||||
(:require [frontend.format.mldoc]))
|
||||
Reference in New Issue
Block a user