Overview of @herb-tools/browser
main@herb-tools/browser package provides a WebAssembly-based, HTML-aware ERB (Embedded Ruby) parser specifically designed for use in browser environments.repository·main·Indexed 22 days ago
https://github.com/marcoroth/herbA comprehensive toolchain for HTML+ERB (.html.erb) templates providing high-fidelity parsing, linting, formatting, and rendering. The ecosystem includes @herb-tools/formatter for ERB-aware pretty-printing, @herb-tools/language-server for LSP integration, @herb-tools/highlighter for syntax highlighting, and @herb-tools/browser for WebAssembly-based parsing in browser environments. It also features a Dev Server client for live updates and Java/JNI bindings for native integration.
@herb-tools/browser package provides a WebAssembly-based, HTML-aware ERB (Embedded Ruby) parser specifically designed for use in browser environments.Herb is a modern HTML+ERB (.html.erb) toolchain and ecosystem designed to provide precise, accurate developer tools for HTML-aware ERB templates.
At its core is the Herb Parser, a fast, portable, HTML-aware ERB parser written in C that generates a detailed syntax tree. This parser powers the entire ecosystem, including:
Herb::Engine) that is API-compatible with Erubi but adds structural awareness for features like HTML validation and security checks.libherb) is a C library designed for high-performance, portable, and HTML-aware ERB parsing. It serves as the foundational component for the entire Herb ecosystem, responsible for generating detailed and accurate syntax trees from templates that combine HTML and ERB. It is suitable for developers needing a low-level, fast parsing engine for HTML+ERB content.The Herb ecosystem provides tooling for HTML+ERB and is organized into three functional categories:
@herb-tools/node package is a native Node.js addon designed for HTML-aware ERB (Embedded Ruby) parsing using the Herb engine. It allows you to integrate Herb's parsing capabilities directly into Node.js environments.The org.herb package provides static methods via the Herb class to process HTML documents with embedded Ruby (HTML+ERB) through JNI.
Key capabilities include:
@herb-tools/node-wasm package provides a WebAssembly-based, HTML-aware ERB (Embedded Ruby) parser specifically designed for Node.js environments. It allows you to leverage Herb's parsing capabilities within a Node.js runtime using a WASM implementation.When action_view_helpers is enabled, Action View helpers are transformed into synthetic HTMLElementNode AST representations.
Key features of this transformation:
ERBOpenTagNode.<% end %> is mapped to the close_tag of the HTML element.element_source field identifies the specific helper that produced the node (e.g., ActionView::Helpers::TagHelper#tag).data: { controller: "hello" } are flattened into standard HTMLAttributeNode entries (e.g., name: "data-controller", value: "hello").The Herb Linter is automatically integrated into the Herb Language Server. This provides real-time validation and diagnostics in supported editors such as VS Code, Zed, and Neovim.
Tip: Hot Reloading Custom rules are automatically reloaded when changed in editors using the Herb Language Server, meaning you do not need to restart your editor to see changes to your custom rule logic.
When configuring specific rules in .herb.yml, you can control which files they apply to using include, only, and exclude. These follow a strict precedence order:
only: If present, the rule applies ONLY to these files. This ignores any include settings.include: If only is absent, the rule applies to these files (this is additive to the global include settings).exclude: Always applied. If a file matches an exclude pattern, the rule will not run on it (unless using the --force flag).Herb merges configuration patterns in a specific hierarchy. Patterns at every level are additive to the defaults. The order of precedence for determining the final list of patterns is:
node_modules/**/* is excluded by default).files.include/files.exclude: Patterns defined in .herb.yml under the files key.linter.include or formatter.exclude.Example logic:
If you have files.include: ['**/*.xml.erb'] and linter.include: ['**/*.custom.erb'], the linter will use the union of: Defaults + **/*.xml.erb + **/*.custom.erb.