I'm looking for an HTML parser in Roc to use with the old Rust compiler. What's easy:
I will actually be using it to parse Zulip messages. Here is the TS code that I need to port (so ideally the Roc parser would support the handy querySelectorAll interface, but I can walk any AST):
import { parse, HTMLElement } from "node-html-parser";
function fix_src(root: HTMLElement, tag_name: string) {
const nodes = root.querySelectorAll(tag_name);
nodes.forEach((node) => {
const src = node.getAttribute("src");
if (src) {
node.setAttribute("data-src", src);
node.removeAttribute("src");
node.classList.add("lazyload");
}
});
}
export function fix_content(content: string): string {
const root = parse(content);
fix_src(root, "img");
fix_src(root, "video");
return root.toString();
}
Suggestions welcome!
Here's one https://github.com/lukewilliamboswell/roc-parser
Hasn't migrated to the new compiler yet :sweat_smile:
Though you wouldn't use it like the TS code
That's nice code! Unfortunately, I can't really program in Roc until I find a stable version of the compiler. (see #beginners > panic when just adding a new Dict)
Last updated: Mar 20 2026 at 12:28 UTC