Himalaya is a JavaScript library designed to synchronously parse HTML documents into a structured JSON Abstract Syntax Tree (AST) and to convert that JSON AST back into HTML. Its current stable version is 1.1.1. The library maintains a steady release cadence, with minor releases adding features like source position tracking (v1.1.0) and patch releases addressing bugs, such as issues with malformed closing tags (v1.0.1) or CSS value parsing (v0.2.13). A significant breaking change occurred in v1.0.0, which dropped the older v0 specification in favor of a new, standardized v1 AST format, making the v1 spec the default. Key differentiators include its synchronous operation, robust handling of "weird HTML" edge cases (like unclosed tags, extra closing tags, void/self-closing tags, doctypes, and comments), and its ability to accurately preserve whitespace from the original HTML. It also offers a `stringify` method for converting the JSON AST back to HTML, facilitating round-trip transformations. The parser explicitly does not process the content of `<script>`, `<style>`, and `<template>` tags, treating them as raw text.
npm install himalayaVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing HTML to a JSON AST, making a simple modification to the AST, and then stringifying it back to HTML using `parse` and `stringify`.
Review the v1 AST specification (`ast-spec-v1.md`) and refactor code that processes the parsed JSON output. The `v0.3.0` release allowed opting into v1 early, providing a migration path.
Ensure custom or non-standard HTML-like tags start with an alphanumeric character. For cases requiring more permissive parsing of tag names, consider pre-processing the input HTML or using an alternative parser.
To include position data, pass an options object to `parse`: `parse(html, { ...parseDefaults, includePositions: true })`. This will add a `position` field to each node in the AST.For whitespace removal, post-process the resulting JSON AST. For parsing script/style contents, extract the `content` property of these nodes and parse them with a dedicated JavaScript or CSS parser.
Upgrade to Himalaya v1.0.1 or newer. This issue was fixed in PR #86, which ensured the parser correctly handles and recovers from such scenarios without premature termination.
Update to Himalaya v0.2.13 or newer. This patch release resolved the issue by correctly parsing the entire value of CSS attributes even when they contain multiple colons.
Upgrade to Himalaya v0.2.12 or newer. Version 0.2.11 provided a fix for `tbody`, `thead`, `tfoot`, and 0.2.12 extended it to `td` and `tr` to properly handle nested tables.
Update to Himalaya v0.2.10 or newer. This release improved whitespace parsing by recognizing any character defined by the RegExp metacharacter `\s`.
No dependency data recorded yet.