New Release! Now uses lexbor_erl
A library to do pipeable transformations on html strings with CSS selectors, e.g. find(), prepend(), append(), replace() etc.
Elixir wrapper for lexborisov's Modest Lexbor C Library.
Lexbor browser engine crafted entirely in C (there's no school like the old school)
All Lexbor-related features are implemented as a port binding through the Erlang lexbor_erl library.
For news and updates please check out the forum discussion.
Total 16 features implemented. See complete feature list.
Build transformation pipelines...
test "build up a complete DOM" do
result = ""
|> ModestEx.serialize()
|> ModestEx.append("body", "<div>")
|> ModestEx.set_attribute("div", "class", "col-md-12")
|> ModestEx.append("div", "<div>")
|> ModestEx.set_attribute("div.col-md-12 div", "class", "col-md-6")
|> ModestEx.append("div.col-md-12 div", "<a></a>")
|> ModestEx.set_text("a", "Hello")
copy = ModestEx.find(result, "div.col-md-12 div")
|> ModestEx.set_text("a", "World")
result = ModestEx.insert_after(result, "div.col-md-12 div", copy)
|> ModestEx.set_attribute("div.col-md-6:first-of-type a", "href", "https://elixir-lang.org")
|> ModestEx.set_attribute("div.col-md-6:last-of-type a", "href", "https://google.de")
assert result == "<div class=\"col-md-12\"><div class=\"col-md-6\"><a href=\"https://elixir-lang.org\">Hello</a></div><div class=\"col-md-6\"><a href=\"https://google.de\">World</a></div></div>"
endPlease note, after migrating to lexbor_erl not all features are supported. See CHANGELOG
All common CSS Selectors are supported. Total 38 selector patterns implemented. See complete list of supported CSS selectors.
Available on hex.
def deps do
[
{:modest_ex, "~> 2.1.0"}
]
end- CMake 3.10+
- Lexbor C library
macOS:
brew install lexborUbuntu/Debian:
sudo apt-get install liblexbor-devFrom source:
git clone https://github.com/lexbor/lexbor.git
cd lexbor && mkdir build && cd build
cmake .. && make && sudo make installmix deps.get
mix compile
mix test
See CHANGELOG.
- Bindings
-
Call as C-Node(removed in 2x) - Call via lexbor_erl port
-
- Tests
- Feature tests
- GitHub Actions CI (Ubuntu, macOS)
- Features
- Find nodes using a CSS selector
- Serialize any string with valid or broken html
- Get attribute with optional CSS selector
- Set attribute with optional CSS selector
- Get text with optional CSS selector
- Set text with optional CSS selector
- Remove a node from html
- Append node to another node
- Prepend node to another node
- Insert node before another node
- Insert node after another node
- Replace node with another node
- Slice html to a subset of nodes
- Get position of node in relation to its parent
- Wrap node with another node
- Streaming of large documents
- Pretty print html
- Compare two html strings
- Transform html string by list of actions
-
Custom CSS selector for pseudo class(not supported by Lexbor):contains(text) - Scope flag to control serialization (supported to be backwards compatible with Modest)
- List of supported CSS Selectors
- Documentation
- Publish as hex package
ModestEx is under LGPL license. Check the LICENSE file for more details.
humble by Eliricon from the Noun Project