### Customizing Markdown Lowering with React Components and Custom Classes Source: https://github.com/kiranshila/cybermonday/blob/master/README.md Extend the lowering step by providing an options map to set default attributes for HTML tags and custom lowering functions. This example shows rendering math with a React component and applying a custom class to paragraphs. ```clojure (ns main.core (:require [cybermonday.core :as cm] ["@matejmazur/react-katex" :as TeX])) (defn lower-inline-math [[_ _ math]] [:> TeX {:math math}]) (cm/parse-md markdown {:default-attrs {:p {:class ["my-class"]}} :lower-fns {:markdown/inline-math lower-inline-math}}) ``` -------------------------------- ### Soft Line Break IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a soft line break in the IR AST. This typically renders as a newline without starting a new paragraph. ```clojure [:markdown/soft-line-break {}] ``` -------------------------------- ### Render KaTeX Math with Auto-render Extension Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Customize inline math delimiters for KaTeX rendering by overriding the default parsing behavior. ```clojure (ns my-library (:require [cybermonday.core :as cn])) (defn parse-math [[_ _ & [math]]] (str "$$" math "$$")) (cm/parse-md "$`y=mx+b`$" {:markdown/inline-math parse-math}) ``` -------------------------------- ### Process Markdown AST with Templating Source: https://github.com/kiranshila/cybermonday/blob/master/doc/03-Templates.md This function walks the Markdown AST and applies a template to string nodes, excluding code blocks. It uses pogonos for string rendering. ```clojure (defn process-template [mdast template-vals] (clojure.walk/prewalk (fn [item] (if (cybermonday.utils/hiccup? item) (let [[tag attrs & body] item] (if (not= tag :code) (cybermonday.utils/make-hiccup-node tag attrs (map #(if (string? %) (pogonos.core/render-string % template-vals) %) body)) item)) item)) mdast)) ``` -------------------------------- ### IR Node Structure Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Illustrates the general structure of an IR node, comprising a namespaced keyword, an attribute map, and an optional body. ```clojure [:markdown/keyword attr-map & body] ``` -------------------------------- ### Add Anchor Links to Headings Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Customize heading lowering to automatically generate anchor links with unique IDs and appropriate attributes for navigation. ```clojure (ns my-library (:require [clojure.string :as str] [cybermonday.utils :refer [gen-id make-hiccup-node]] [cybermonday.core :as cm])) (defn lower-heading [[_ attrs & body :as node]] (make-hiccup-node (keyword (str "h" (:level attrs))) (dissoc (let [id (if (nil? (:id attrs)) (gen-id node) (:id attrs))] (assoc attrs :id id :class "anchor" :href (str "#" id))) :level) body)) (parse-md "# A Heading" {:markdown/heading lower-heading}) ``` -------------------------------- ### Image IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an image in the IR AST. Includes source URL, alt text, and an optional title. ```clojure [:img {:src "cat.png" :alt "Witty alt-text" :title "More info"}] ``` -------------------------------- ### Convert Markdown to Intermediate Representation (IR) Source: https://github.com/kiranshila/cybermonday/blob/master/README.md Obtain the direct Intermediate Representation (IR) of the markdown string. This is useful if you need to work with the AST before HTML conversion. ```clojure (require '[cybermonday.ir :as cm-ir]) (cm-ir/md-to-ir my-markdown-str) ``` -------------------------------- ### Split Content with HTML Comment Divider Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Capture and process HTML comments to implement content dividers, such as separating a blurb from a full article. ```clojure (ns my-library (:require [clojure.string :as str] [cybermonday.core :as cm])) (defn content-split [[_ _ body]]) (when (str/includes? body "more") [:div {:class "content-split"}])) (cm/parse-md "" {:markdown/html-comment content-split}) ``` -------------------------------- ### Image Reference IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an image reference in the IR AST, similar to a link reference but for images. ```clojure [:markdown/image-ref {:reference [:markdown/reference {:title "Foo" :label "1" :url "#baz"}]} "Bar"] ``` -------------------------------- ### Auto Link IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an automatically generated link in the IR AST. The :href attribute contains the link URL. ```clojure [:markdown/autolink {:href "www.foo.bar"}] ``` -------------------------------- ### Parse Markdown with Custom Options Source: https://github.com/kiranshila/cybermonday/blob/master/doc/01-Usage.md Use the `parse-md` function to parse a markdown string. Customize lowering functions and default attributes for HTML tags. ```clojure (parse-md my-md-string {:lower-fns {:markdown/node lower-node-fn} :default-attrs {:p {:style {:color :red}}}}) ``` -------------------------------- ### Reference IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a reference link in the IR AST. It includes a title, label, and URL for the reference. ```clojure [:markdown/reference {:title "Title", :label "1", :url "/url"}] ``` -------------------------------- ### Link IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a hyperlink in the IR AST. The :href attribute specifies the URL, and :title is optional. ```clojure [:a {:href "https://example.com" :title "A neat website"} "Click me"] ``` -------------------------------- ### HTML Comment IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an HTML comment in the IR AST. ```clojure [:markdown/html-comment {} "I'm a comment!"] ``` -------------------------------- ### Task List Item IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a task list item in the IR AST, indicating checked state and list context. ```clojure [:markdown/task-list-item {:checked? false, :ordered? false} [:p {} "Unchecked and unordered"]] ``` -------------------------------- ### Heading IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a heading in the IR AST. The :level attribute specifies the heading level (1-6). ```clojure [:markdown/heading {:level 1} "Heading"] ``` -------------------------------- ### Inline Math IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents inline mathematical expressions in the IR AST. Content is treated as text within a :pre block by default. ```clojure [:markdown/inline-math {} "y=mx+b"] ``` -------------------------------- ### Parse Markdown to HTML Hiccup Source: https://github.com/kiranshila/cybermonday/blob/master/README.md Use this function to convert a markdown string into an HTML hiccup representation. Ensure the cybermonday.core namespace is required. ```clojure (require '[cybermonday.core :as cm]) (cm/parse-md my-markdown) ``` -------------------------------- ### Mail Link IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an email link in the IR AST. The :address attribute contains the email address. ```clojure [:markdown/mail-link {:address "you@example.com"}] ``` -------------------------------- ### Link Reference IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a link reference in the IR AST, potentially containing a nested :markdown/reference node. ```clojure [:markdown/link-ref {:reference [:markdown/reference {:title "Foo" :label "1" :url "#baz"}]} "Bar"] ``` -------------------------------- ### Ordered List Item IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an ordered list item in the IR AST. Used for standard numbered list items. ```clojure [:markdown/ordered-list-item {} "Item"] ``` -------------------------------- ### Bullet List Item IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a bullet list item in the IR AST. Used for standard unordered list items. ```clojure [:markdown/bullet-list-item {} "Item"] ``` -------------------------------- ### Footnote Block IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents the content of a footnote in the IR AST. Includes the footnote ID and its content. ```clojure [:markdown/footnote-block {:id "1" :content "I'm a footnote"}] ``` -------------------------------- ### Footnote IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a footnote marker in the IR AST. The :id attribute specifies the footnote identifier. ```clojure [:markdown/footnote {:id "1"}] ``` -------------------------------- ### Table Cell IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a table cell in the IR AST. Attributes indicate if it's a header and its text alignment. ```clojure [:markdown/table-cell {:header? true :alignment "center"}] ``` -------------------------------- ### Fenced Code Block IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents a fenced code block in the IR AST. The :language attribute specifies the programming language. ```clojure [:markdown/fenced-code-block {:language "julia"} "code"] ``` -------------------------------- ### Indented Code Block IR Node Source: https://github.com/kiranshila/cybermonday/blob/master/doc/02-AST.md Represents an indented code block in the IR AST. This is typically used for code blocks that are indented by four spaces. ```clojure [:markdown/indented-code-block {} "code"] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.