matthewsinclair
I have a couple of (relative) newb questions about Nimble Publisher that I can’t quite work out.
I have it (more or less) working but two questions remain:
-
What is the best way to handle a markdown file with an image ref in it? For example, let’s say that the original markdown file was in a directory called
dir/and in that directory is an image calleddir/image.png. If the markdown file is in the same directory (iedir/markdown.mdI could use the standard markdown image reference tagand the markdown viewer or renderer would create an<img src="./image.png">…tag from the markdown. However, because of the way that the routes are set up, that image url ends up being interpreted as an id for a blog post, which of course it can’t find. I can’t be the first person to ever try to do this so there must be an idiomatic way to handle URIs embedded in the markdown file or a way to configure the routes so that markdown is handled by nimble by images are and other content are treated as normal urls. -
I want to control the way that the HTML is emitted from the markdown processor so that I can style it. At the moment, a markdown
# Headingis being rendered simply as<h1>Heading</h1>. But what I need to do is control the styling of the emitted HTML. Again, I can’t be the first person who has ever needed to do this, but I can’t find from the docs what the best way to handle this would be.
Any ideas or even a link to an example or some docs for either problem would be very helpful. Thanks.
PS: I originally posted this on GitHub to the NimblePublisher repo here, but was asked to cross-post here by @josevalim.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
matthewsinclair
Ok, so for what it’s worth, I changed the standard NimblePublisher
Postmodule to look like this:The
inject_style/2function is a bit of a mess, but what it does is add aclass="…"attribute for each HTML tag it finds in the raw blog post content where the value of the class is taken from the map of HTML elements onto class strings kept in@style_map.I know that it is far from robust, but as a PoC, it serves my purpose for now.
billylanchantin
Here’s my approach for 2 (but with your styles substituted).
I’ve added the following to my
post.ex:Then the following to my
use NimblePublisherinvocation:The
postprocessoroption gives you a hook which lets you work with the AST.I also had to add this to my
tailwind.config.js:So it would pickup the new classes.
matthewsinclair
That’s a neat way to solve this (and more robust than my ropey attempt). Thanks!
adamu
I don’t know if it’s the best way, but I store the images one directory below the markdown and serve them with
Plug.Static.My markdown is saved in
priv/postsand rendered on the/blog/:titleroute.I made
priv/posts/imagesto store the images, and then set up a newPlug.Staticin the endpoint to serve them on the same/blogscope:Then in your markdown:
If we place the image in
priv/posts/images/lovely.jpg, it should load.You can also use an
<img>tag directly in the markdown if you need to control the width/height:It’s worth mentioning that unfortunately we can’t get the benefits of Phoenix verified routes or
mix.digestfor the images, because the markdown is injected as raw HTML and not rendered by Phoenix, so unable to get the route information (theoretically it might be possible to do it, because both the markdown and HEEX templates are parsed at compile-time, but I didn’t try it…). This means that we have to directly link to the image and won’t get warnings for invalid image paths and may end up with broken images (like this dashbit post at the time of writing).