mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 11:26:26 +00:00
fix: issue-9380 - #card should only be appended to the title
https://github.com/logseq/logseq/issues/9380 Bug: Make block with any text and one property after the text Use bullet context menu to call «Make Flashcard» command
This commit is contained in:
25
src/main/frontend/util/block_content.cljs
Normal file
25
src/main/frontend/util/block_content.cljs
Normal file
@@ -0,0 +1,25 @@
|
||||
(ns frontend.util.block-content
|
||||
"utils for text content residing in a block"
|
||||
(:require [clojure.string :as string]
|
||||
[frontend.format.mldoc :as mldoc]
|
||||
[logseq.graph-parser.mldoc :as gp-mldoc]))
|
||||
|
||||
|
||||
|
||||
(defn get-ast
|
||||
[content format]
|
||||
(mldoc/->edn content (gp-mldoc/default-config format)))
|
||||
|
||||
(defn has-title?
|
||||
[content format]
|
||||
(let [ast (get-ast content format)]
|
||||
(mldoc/block-with-title? (ffirst (map first ast)))))
|
||||
|
||||
(defn get-title&body
|
||||
"parses content and returns [title body]
|
||||
returns nil if no title"
|
||||
[content format]
|
||||
(let [lines (string/split-lines content)]
|
||||
(if (has-title? content format)
|
||||
[(first lines) (string/join "\n" (rest lines))]
|
||||
[nil (string/join "\n" lines)])))
|
||||
@@ -12,7 +12,8 @@
|
||||
[logseq.graph-parser.text :as text]
|
||||
[frontend.db :as db]
|
||||
[frontend.state :as state]
|
||||
[frontend.util.cursor :as cursor]))
|
||||
[frontend.util.cursor :as cursor]
|
||||
[frontend.util.block-content :as content]))
|
||||
|
||||
(defn hidden-properties
|
||||
"These are properties hidden from user including built-in ones and ones
|
||||
@@ -228,8 +229,8 @@
|
||||
(insert-property format content key value false))
|
||||
([format content key value front-matter?]
|
||||
(when (string? content)
|
||||
(let [ast (mldoc/->edn content (gp-mldoc/default-config format))
|
||||
title? (mldoc/block-with-title? (ffirst (map first ast)))
|
||||
(let [ast (content/get-ast content format)
|
||||
title? (content/has-title? content format)
|
||||
has-properties? (or (and title?
|
||||
(or (mldoc/properties? (second ast))
|
||||
(mldoc/properties? (second
|
||||
@@ -239,9 +240,7 @@
|
||||
ast)))))
|
||||
(mldoc/properties? (first ast)))
|
||||
lines (string/split-lines content)
|
||||
[title body] (if title?
|
||||
[(first lines) (string/join "\n" (rest lines))]
|
||||
[nil (string/join "\n" lines)])
|
||||
[title body] (content/get-title&body content format)
|
||||
scheduled (filter #(string/starts-with? % "SCHEDULED") lines)
|
||||
deadline (filter #(string/starts-with? % "DEADLINE") lines)
|
||||
body-without-timestamps (filter
|
||||
|
||||
Reference in New Issue
Block a user