BillBryson
I’m trying to customize the outputted p tag when using Earmark.as_html!/2.
For example, I’d like this input:
Earmark.as_html!("Hello world")
To return: <p style="color: #000000;">Hello world</p>. Here the color is applied dynamically. I was looking through the docs but did not see something that would fit my needs, perhaps I missed it? Any help would be appreciated.
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
outlog
I’m using the code/gist from @neuone from here Earmark - add my own class names to the default set of markdown tags - #3 by neuone to customize earmark output..
only caveat is it’s stopped working on latest earmark, so currently locked at {:earmark, “1.4.4”}, and haven’t had time to figure what the issue/solution is, most likely something trivial..
mine looks like this:
you use like this:
BillBryson
Thank you - this is interesting. I’m trying to use this too, but the
parsefunction doesn’t seem to work for me as-is. I’ve had to update it to take a 4th argument.Maybe I’m not doing something correctly.
neuone
I haven’t looked at this code for awhile.
What I remember is I want to be able to supply my own CSS class names on certain HTML tags. And this was global meaning any HTML tags that matched would get updated.
This was all so I could control the formatted output of a Markdown blog system
Examples
If it encounters an
<H1>tag just add the css class"mw7 lh-copy"to all<H1>tags.If it encounters any
<IMG>tags add the css class".lazy"to all<IMG>tags.If it encounters any
<p>tag add the css class"py-2"to all<P>tagsYour example
It looks like you want the ability to pass in some specific String “Hello World” and have it wrap itself around a specific tag
<p>with a specific css attributestyle="color: #000000;"?Is my assumption correct?
BillBryson
Yes, that’s correct.
It looks like this will work, only in my app the
parsefunction breaks unless it’s a tuple with 4 elements.neuone
Sounds like you want to pattern match for the sentence
"Hello World"and then apply some custom CSS style around that sentence. This parser is not intended to do that type of work.BillBryson
Sorry, I misread. Not a specific string of “hello world”. I want apply a style to all these
ptags. This solution works, I just required a 4 element tuple in place of a 3 element one for theparsefunction, which the example provided.Thank you for your help.
RobertDober
Sorry for blending in so late, but I needed some time to get my focus back on Earmark
As a matter of fact the split of EarmarkParser was also motivated by giving Earmark more liberties to create code that is not needed by ex_doc and its zillions of users
Therefor I have started to implement an Ast Walker and the option to integrate an Ast Postprocessor
A good starting point on how to use it is here:
https://github.com/pragdave/earmark/blob/i398_ast_post_processing/test/acceptance/postprocessor_test.exs
As this is WIP please do not hesistate to give me some input what might be better or more useful.
Sorry no doc yet, but I need the feature to be stable first.
Here is the implementation:
postprocess option
and Ast Walker
RobertDober
Starting to remove recursion from transforming the AST, first step
iterative version of
_walkjust in case someone spotted the danger in the code