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

Blockquote elements error on rendering #2

Open
svdm opened this issue May 29, 2018 · 2 comments
Open

Blockquote elements error on rendering #2

svdm opened this issue May 29, 2018 · 2 comments

Comments

@svdm
Copy link
Contributor

svdm commented May 29, 2018

Trying to render a blockquote throws an exception right now:

user> (markdown->clj-pdf "> This is a quote")
java.lang.IllegalArgumentException: No matching field found: getLiteral for class org.commonmark.node.BlockQuote

The issue is that the :default case of the render method relies on .getLiteral on the parsed element. This works fine for code blocks etc, but blockquotes are parsed differently by commonmark-java. For this case it creates a BlockQuote containing one or more Paragraph nodes. The BlockQuote node itself has no .getLiteral implementation, hence the error.

Something like this seems to work, but I'm not familiar enough with this lib and clj-pdf to be sure it's entirely the right approach:

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

It also has the downside of using a plain :paragraph, which makes it hard to style quotes.

@leontalbot
Copy link
Collaborator

leontalbot commented May 29, 2018

Nice catch.

I guess this would work (untested):

Adapt default-pdf-config like so: {:quote {:style :italic :color [128 128 128]} ...}

Change render-derivals by removing :BlockQuote from :Literal.

Add this :BlockQuote render method:

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

If this works for you, feel free to send a PR with new test and README adapted.

@svdm
Copy link
Contributor Author

svdm commented May 29, 2018

Thanks! That does the trick for my use case, so I've created PR #3 with those changes and some basic test/readme additions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants