(ns outliner.model.core.logic (:require [clojure.string :as string] [outliner.model.core.tree :as tree] [outliner.model.core.markdown :as markdown] [outliner.model.core.text-ops :as text-ops] [outliner.model.core.annotations :as annotations])) (defmulti resolve-variable (fn [var-name] var-name)) (defmethod resolve-variable :default [var-name] var-name) (defn resolve-text [node] (let [text (:text node)] (if (and (string? text) (string/starts-with? text "$")) (resolve-variable text) text))) (defn valid-doc? [doc] (let [root-ids (:root doc) nodes (:nodes doc)] (and (seq root-ids) (seq nodes) (get nodes (first root-ids))))) ;; Delegations to core ops (def merge-annotations annotations/merge-annotations) (def trim-node-text text-ops/trim-node-text) (defn sanitize-text [node] (markdown/sanitize-text node)) (defn get-path [doc id] (tree/get-path doc id)) (defn breadcrumb-text [node] (let [resolved-node (assoc node :text (resolve-text node)) text (text-ops/render-annotated-text resolved-node markdown/normalize-markdown)] (if (> (count text) 25) (str (subs text 0 11) "\u2026" (subs text (- (count text) 11))) text))) (defn find-prev-id ([doc id] (tree/find-prev-id doc id)) ([doc id zoom-id] (tree/find-prev-id doc id zoom-id))) (defn find-next-id ([doc id] (tree/find-next-id doc id)) ([doc id zoom-id] (tree/find-next-id doc id zoom-id))) (defn markdown-to-annotated [text] (markdown/markdown-to-annotated text)) (defn annotated-to-markdown [text annotations] (markdown/annotated-to-markdown text annotations)) (defn parse-markdown [text] (markdown/parse-markdown text)) (defn parse-multi-line-markdown [text] (markdown/parse-multi-line-markdown text)) (defn node-to-markdown ([doc id] (markdown/node-to-markdown doc id)) ([doc id level] (markdown/node-to-markdown doc id level))) (defn horizontal-line? [node] (boolean (some #(= (:type %) :horizontal-line) (:annotations node))))