Skip to content

Commit

Permalink
Merge pull request #12 from LucianoLaratelli/master
Browse files Browse the repository at this point in the history
add parse-{front,body} fns for luciano's convenience
  • Loading branch information
kiranshila committed Aug 29, 2021
2 parents 912751c + 90c7b60 commit e1ce3f2
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/cybermonday/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,30 @@
(def parse-yaml #?(:clj yaml/parse-string
:cljs (comp ->clj yaml/parse)))

(defn parse-front
"Parse only the frontmatter of a markdown file. "
[md]
(let [[_ fm body] (re-matches frontmatter-re md)]
(when fm (parse-yaml fm)))
)

(defn parse-body
"Parse only the body of a markdown file."
([md opts]
(let [[_ fm body] (re-matches frontmatter-re md)]
(cond-> body
true ir/md-to-ir
(:process-templates? opts) templates/parse-templates
true (lowering/to-html-hiccup opts)
true utils/cleanup-whitespace)))
([md] (parse-md md nil)))

(defn parse-md
"Generates HTML hiccup from markdown and associated frontmatter
See `cybermonday.lowering/to-html-hiccup` for opts map values.
Set `:process-templates?` to true to process mustache templates"
([md opts]
(let [[_ fm body] (re-matches frontmatter-re md)]
{:frontmatter (when fm (parse-yaml fm))
:body (cond-> body
true ir/md-to-ir
(:process-templates? opts) templates/parse-templates
true (lowering/to-html-hiccup opts)
true utils/cleanup-whitespace)}))
{:frontmatter (parse-front md)
:body (parse-body md opts)})
([md] (parse-md md nil)))

0 comments on commit e1ce3f2

Please sign in to comment.