Stream: helpdesk (published)

Topic: How to display html in Jupyter with Julia?


view this post on Zulip Davi Sales Barreira (Apr 09 2021 at 19:05):

How do I display "html" in Jupyter Notebook with Julia? I've tried searching for a package, but didn't find any specific.

view this post on Zulip Mason Protter (Apr 09 2021 at 19:10):

You can just use the html string macro!

view this post on Zulip Mason Protter (Apr 09 2021 at 19:12):

image.png

view this post on Zulip Davi Sales Barreira (Apr 09 2021 at 19:17):

Thanks, Mason. Any other way using a function? I'm writing a package, so I guess using a macro is not the best way. I'm trying to write a wrapper to plot visualizations with D3.js. Do you think that using the "html" macro would be adequate?

view this post on Zulip Mason Protter (Apr 09 2021 at 19:21):

I'm not sure I understand the connection between not wanting to use a macro and developing a package

view this post on Zulip Mason Protter (Apr 09 2021 at 19:22):

But to answer your question, yes there is a HTML function that the html string macro will use during parse time.

julia> HTML("hi") == html"hi"
true

view this post on Zulip Mason Protter (Apr 09 2021 at 19:25):

But in case there's a confusion here, there is no reason not to use macros in package development. In many cases, a macro (when applicable) can be more efficient than a function, like with the regex string macros, because they allow the regex to be compiled at macroexpansion instead of at runtime

view this post on Zulip Davi Sales Barreira (Apr 09 2021 at 19:38):

Thanks Mason! It was a thing I read somewhere. Although I probably misinterpreted.

view this post on Zulip Mason Protter (Apr 09 2021 at 19:52):

Probably the advice you heard was that many users first learning about metaprogramming overuse it, and that beginners should not be encouraged to create their own macros

view this post on Zulip Mason Protter (Apr 09 2021 at 19:53):

I think that while it's true that many new metaprogrammers will overdo it, I think that's a good thing! Doing something a lot (even when it's not necessary) is the fastest way to learn how to do something well.

view this post on Zulip Clark C. Evans (Apr 09 2021 at 23:27):

@Davi Sales Barreira If your string needs to be informed by the Julia processing context, you might also want to look at HypertextLiteral.jl

view this post on Zulip Davi Sales Barreira (Apr 10 2021 at 10:55):

@Clark C. Evans that's an awesome package! Thanks for pointing out.


Last updated: Dec 28 2024 at 04:38 UTC