Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blockquote support #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Any custom map provided will the merged to following the default map used by the
:list {:ol {:numbered true}
:ul {:symbol "• "}}
:paragraph {}
:quote {:style :italic
:color [64 64 64]}
:spacer {:allow-extra-line-breaks? true
:single-value 0
:extra-starting-value 0}
Expand All @@ -69,6 +71,7 @@ Any custom map provided will the merged to following the default map used by the
- [line](#line)
- [list](#list)
- [paragraph](#paragraph)
- [quote](#quote)
- [spacer](#spacer)

#### anchor
Expand Down Expand Up @@ -201,6 +204,15 @@ is equivalent to
"doc.pdf")
```

#### quote
```clojure
user=> (markdown->clj-pdf {} "> This is a blockquote")
[:paragraph {:style :italic :color [64 64 64]} "This is a blockquote"]

user=> (markdown->clj-pdf {:quote {:style :bold :indent 20} "> Quote with custom styling")
[:paragraph {:style :bold :indent 20 :color [64 64 64]} "Quote with custom styling"]
```

#### spacer

```clojure
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject clj-pdf-markdown "0.2.1"
(defproject clj-pdf-markdown "0.2.2-SNAPSHOT"
:description "Library for rendering markdown to clj-pdf data-structure syntax."
:url "https://github.com/leontalbot/clj-pdf-markdown"
:license {:name "Eclipse Public License"
Expand Down
9 changes: 8 additions & 1 deletion src/clj_pdf_markdown/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
:list {:ol {:numbered true}
:ul {:symbol "• "}}
:paragraph {}
:quote {:style :italic
:color [64 64 64]}
:spacer {:allow-extra-line-breaks? true
:single-value 0
:extra-starting-value 0}
Expand Down Expand Up @@ -170,7 +172,7 @@

(def render-derivals
{:LineBreak [:HardLineBreak :SoftLineBreak]
:Literal [:BlockQuote :FencedCodeBlock :IndentedCodeBlock :Code]})
:Literal [:FencedCodeBlock :IndentedCodeBlock :Code]})

(defn make-hierarchy-from-derivals [derivals]
(reduce (fn [hier [child parent]] (derive hier child parent))
Expand Down Expand Up @@ -261,6 +263,11 @@
(defmethod render :HtmlInline [pdf-config node]
(->> node .getLiteral (html-tag->clj-pdf pdf-config)))

(defmethod render :BlockQuote [pdf-config node]
(->> node
(render-children* pdf-config)
(into [:paragraph (:quote pdf-config)])))

(defmethod render :Literal [pdf-config node]
(.getLiteral node))

Expand Down
13 changes: 13 additions & 0 deletions test/clj_pdf_markdown/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@
(is (= [[:paragraph {} "This is simple text"]]
(markdown->clj-pdf {:wrap {:unwrap-singleton? false}} "This is simple text"))))

(testing "blockquote"
(is (= [:paragraph {:style :italic :color [64 64 64]} "This is a quote"]
(markdown->clj-pdf {} "> This is a quote")))

(is (= [:paragraph {:style :bold :color [64 64 64]} "Styled quote"]
(markdown->clj-pdf {:quote {:style :bold}} "> Styled quote")))

(is (= [:paragraph {:style :italic, :color [64 64 64]}
[:paragraph {} "This is a quote" [:spacer 0]
"with multiple lines" [:spacer 0]
[:phrase {:style :italic} "and markup!"]]]
(markdown->clj-pdf {} "> This is a quote\n> with multiple lines\n> *and markup!*"))))

(testing "spacer"
(is (= [:paragraph {} "This is" [:spacer 0] "a spacer."]
(markdown->clj-pdf {} "This is\na spacer.")))
Expand Down