f34nk

f34nk

Hello!

I just published my first draft of ModestEx, a Elixir/Erlang binding to lexborisov’s Modest library.

Modest is a fast HTML renderer implemented as a pure C99 library with no outside dependencies.

ModestEx exposes features to do pipeable transformations on html strings with CSS selectors, e.g. find(), prepend(), append(), replace() etc.

iex> ModestEx.find("<p><a>Hello</a> World</p>", "p a")
{:ok, "<a>Hello</a>"}

iex> ModestEx.serialize("<div>Hello<span>World")
{:ok, "<html><head></head><body><div>Hello<span>World</span></div></body></html>"}

The binding is implemented as a C-Node following the excellent example in @Overbryd 's package nodex. If you want to learn how to set up bindings to C/C++, you should definitely check it out.

Before that I experimented with a lot of other Html parser libraries like gumbo-parser, gumbo-query and GQ. I even implemented a binding package called gumbo_query_ex.
However Modest is currently the most active and most promising.

This project is under development!
Stay tuned for more features like ModestEx.remove, ModestEx.prepend, ModestEx.append

Tell me what you think :relaxed:

Best, F34nk

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

Ah it looks like a C-based variant of Meeseeks except it can also create HTML too, quite nice! :slight_smile:

mischov

mischov

Modest is the full project of which Alexander Borisov’s (lexborisov) myhtml, which also has an Elixir wrapper, is a part. It’s closer to being a C-varient of… maybe Servo? It’s larger in scope than just parsing HTML.

Everything I’ve seen suggests that Modest (and probably ModestEx) will be fast, with low resource usage. That’s pretty great.

f34nk

f34nk OP

Thanks guys!

I have a use case where a request reads html from a database and before rendering I need to do some changes on the html string. In my case the html is quite large and the changes are quite extensive.

The idea for ModestEx is to implement a set of features that just do transformations on a html string. Each transformation feature will be done in C.

Something like:

result ModestEx.find("<p><a>Hello</a> World</p>", "p a")
|> ModestEx.attribute("href", "https://elixir-lang.org")

will return:

{:ok,  "<a href=\"https://elixir-lang.org\">Hello</a>"}

… ready to render in a template.

Or you could also serialize it:

ModestEx.serialize(result)

and return:

{:ok,  "<html><head></head><body><a href=\"https://elixir-lang.org\">Hello</a></body></html>"}

Which is already a (more or less) valid page!

Of course, if you need further decoding htmlex, floki or Meeseeks are great!
I see ModestEx as a useful addition to the landscape of html tools in Elixir.

mischov

mischov

For sure, I have been very hesitant to try adding transformations to Meeseeks, so I’m glad somebody’s doing it. :slight_smile:

OvermindDL1

OvermindDL1

Oooo, that’s fascinating!

Yeah this looks very useful! :slight_smile:

Heh, yeah it’s quite a thing to tackle. ^.^

f34nk

f34nk OP

Hey @mischov @OvermindDL1

I just published ModestEx v0.0.2-dev.

Thanks again for your input. It’s a lot clearer now what the main strength of the library actually is!

I added a new feature ModestEx.get_attribute and ModestEx.set_attribute.

And you can actually pipe them together.

iex> ModestEx.find("<p><a>Hello</a><a>World</a></p>", "p a") |> 
...> ModestEx.set_attribute("href", ["https://elixir-lang.org", "https://google.de"])
["<html><head></head><body><a href=\"https://elixir-lang.org\">Hello</a></body></html>", "<html><head></head><body><a href=\"https://google.de\">World</a></body></html>"]
Overbryd

Overbryd

Wohoo! This is great news :slight_smile:

Will we get Elixir based end 2 end headless browser testing soon? :smiley:

Thanks for the reference and I am delighted to see a binding to Modest.

I have a few use cases where I will get back to it for sure.

f34nk

f34nk OP

Hey guys,

the first mayor release is coming soon and I hope to publish it before ElixirConf EU in April.

I also implemented a new CSS selector for :contains(text) in Modest PR#42.

I’ll keep you updated!

f34nk

f34nk OP

Release v1.0.0

This release is stable.

def deps do
  [
    {:modest_ex, "~> 1.0.0"}
  ]
end

Total 16 features implemented. See complete feature list.

Total 38 selector patterns implemented (including custom selector :contains(text)).
See complete list of supported CSS selectors.

The package includes all binding code under the folder target/modest_worker.
All Modest related features are implemented in a single C library called modest_html.

This way, all features are tested in a C environment using CMake/CTest with memory tracking enabled using a library called dmt.

Please feel invited to check it out :relaxed:

Best, F34nk

cro

cro

Greetings @f34nk , I have been trying to get modest_ex to work with Erlang 24.x. I know my C/C++ is rusty, but I’ve spent a good half-day on this without any progress. I am currently stuck looking for vec.h, which doesn’t seem to exist anywhere on my Mac or Linux boxes. Any pointers here? Thank you!

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews