├── .gitignore ├── README.md ├── project.clj ├── src └── html5_walker │ ├── core.clj │ └── walker.clj ├── test └── html5_walker │ ├── core_test.clj │ └── walker_test.clj └── tests.edn /.gitignore: -------------------------------------------------------------------------------- 1 | /.nrepl-port 2 | /target 3 | /pom.xml 4 | /pom.xml.asc 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # html5-walker 2 | 3 | A thin Clojure wrapper around 4 | [jfiveparse](https://github.com/digitalfondue/jfiveparse), this lets you find 5 | and replace in HTML5 strings. 6 | 7 | ## Install 8 | 9 | - add `[html5-walker "2023.11.21"]` to `:dependencies` in your project.clj 10 | 11 | or 12 | 13 | - add `html5-walker/html5-walker {:mvn/version "2023.11.21"}` to `:deps` in your deps.edn 14 | 15 | ## Usage 16 | 17 | html5-walker exposes these functions: 18 | 19 | ### html5-walker.walker/find-nodes 20 | 21 | Signature: `(find-nodes html-string path)` 22 | 23 | It returns a sequence of 24 | [Nodes](https://static.javadoc.io/ch.digitalfondue.jfiveparse/jfiveparse/0.6.0/ch/digitalfondue/jfiveparse/Node.html) 25 | matching the path. 26 | 27 | A path is a vector of symbols (or strings) of CSS selectors. Like this: 28 | 29 | - `'[a]` matches all anchor tags. 30 | - `'[form input]` matches all input tags nested inside a form. 31 | - `'[form > input]` matches all input tags that are direct children of a form. 32 | - `'[div.foo]` matches all div tags with "foo" in its class name. 33 | - `'[.button]` matches all elements with the "button" class. 34 | - `'[div#content]` matches the div with "content" as its id. 35 | - `'[:first-child]` matches any element that is the first child. 36 | - `'[:last-child]` matches any element that is the last child. 37 | - `'["meta[property]"]` matches all meta tags with the `property` attribute. 38 | - `'["meta[property=og:title]"]` matches all meta tags with the `property` 39 | attribute set to "og:title". 40 | 41 | The following additional attribute selectors are also supported, and work like 42 | they do in CSS: `*=`, `$=`, `~=` and `^=`. 43 | 44 | So running: 45 | 46 | ```clj 47 | (require '[html5-walker.walker :as walker]) 48 | 49 | (walker/find-nodes "