|
693 | 693 | (get-page-uuid page-names-to-uuids ((some-fn ::original-name :block/name) block) {:block block}) |
694 | 694 | (:block/uuid block)) |
695 | 695 | properties-text-values)) |
696 | | - ;; TODO: Add import support for :template. Ignore for now as they cause invalid property types |
697 | 696 | (if (contains? props :template) |
698 | 697 | {} |
699 | 698 | (let [props' (-> (update-built-in-property-values |
|
782 | 781 | (cond-> block |
783 | 782 | true |
784 | 783 | (merge block-properties) |
| 784 | + (:template properties') |
| 785 | + (update :block/tags (fnil conj []) :logseq.class/Template) |
785 | 786 | (seq classes-from-properties) |
786 | 787 | ;; Add a map of {:block.temp/new-class TAG} to be processed later |
787 | 788 | (update :block/tags |
|
944 | 945 | use in build-block-tx. This walk is only done once for perf reasons" |
945 | 946 | [config ast-blocks] |
946 | 947 | (let [results (atom {:simple-queries [] |
| 948 | + :cards [] |
947 | 949 | :asset-links [] |
948 | 950 | :embeds [] |
949 | 951 | :zotero-imported-files {} |
|
980 | 982 | parsed-path (common-util/safe-read-string relative-path)] |
981 | 983 | (when (string? parsed-path) |
982 | 984 | (swap! results update :zotero-linked-files conj parsed-path))) |
| 985 | + (and (vector? x) |
| 986 | + (= "Macro" (first x)) |
| 987 | + (= "cards" (:name (second x)))) |
| 988 | + (swap! results update :cards conj x) |
983 | 989 | (and (vector? x) |
984 | 990 | (= "Macro" (first x)) |
985 | 991 | (= "query" (:name (second x)))) |
|
1032 | 1038 | (assoc :block/collapsed? true)))] |
1033 | 1039 | {:block block' |
1034 | 1040 | :pvalues-tx pvalues-tx'}) |
1035 | | - {:block block}))) |
| 1041 | + (if-let [cards-macro (first (:cards walked-ast-blocks))] |
| 1042 | + (let [query (-> (:arguments (second cards-macro)) first string/trim) |
| 1043 | + props {:logseq.property/query query} |
| 1044 | + {:keys [block-properties pvalues-tx]} |
| 1045 | + (build-properties-and-values props db page-names-to-uuids |
| 1046 | + (select-keys block [:block/properties-text-values :block/name :block/title :block/uuid]) |
| 1047 | + options) |
| 1048 | + block' |
| 1049 | + (-> (update block :block/tags (fnil conj []) :logseq.class/Cards) |
| 1050 | + (merge block-properties |
| 1051 | + {:block/title (string/trim (string/replace-first title #"\{\{cards(.*)\}\}" ""))}))] |
| 1052 | + {:block block' |
| 1053 | + :pvalues-tx pvalues-tx}) |
| 1054 | + {:block block})))) |
1036 | 1055 |
|
1037 | 1056 | (defn- handle-block-properties |
1038 | 1057 | "Does everything page properties does and updates a couple of block specific attributes" |
|
1390 | 1409 | :block/tags [:logseq.class/Quote-block]}) |
1391 | 1410 | block)) |
1392 | 1411 |
|
| 1412 | +(defn- handle-math |
| 1413 | + "If a block's entire content is a single displayed math formula, convert to #Math-block node. |
| 1414 | + Detects blocks whose title is entirely delimited by $$ markers." |
| 1415 | + [block _opts] |
| 1416 | + (let [title (string/trim (:block/title block))] |
| 1417 | + (if (and (string/starts-with? title "$$") |
| 1418 | + (string/ends-with? title "$$") |
| 1419 | + (> (count title) 4) |
| 1420 | + ;; ensure there's no nested $$ pair (i.e. not two separate inline formulas) |
| 1421 | + (not (string/includes? (subs title 2 (- (count title) 2)) "$$"))) |
| 1422 | + (let [math-content (string/trim (subs title 2 (- (count title) 2)))] |
| 1423 | + (merge block |
| 1424 | + {:block/title math-content |
| 1425 | + :logseq.property.node/display-type :math |
| 1426 | + :block/tags [:logseq.class/Math-block]})) |
| 1427 | + block))) |
| 1428 | + |
1393 | 1429 | (defn- split-title-by-code-fences |
1394 | 1430 | "Parses a block title string line-by-line, splitting into non-code text parts |
1395 | 1431 | and code fence segments. All code fences are extracted regardless of whether |
|
1492 | 1528 | (update-block-tags db (:user-options options) per-file-state (:all-idents import-state)) |
1493 | 1529 | (handle-embeds page-names-to-uuids walked-ast-blocks (select-keys options [:log-fn])) |
1494 | 1530 | (handle-quotes (select-keys options [:log-fn])) |
| 1531 | + (handle-math (select-keys options [:log-fn])) |
1495 | 1532 | (update-block-marker options) |
1496 | 1533 | (update-block-priority options) |
1497 | 1534 | add-missing-timestamps |
|
0 commit comments