mgdm / htmlq

Like jq, but for HTML.
MIT License
7k stars 107 forks source link

Update HTML Nodes / Attributes #54

Open Gerst20051 opened 1 year ago

Gerst20051 commented 1 year ago

I would like to do something like the following operations on an HTML file. Can you think of a way to do this?

[$]> echo "$(htmlq ".html.head.title = \"React App Title\"" $react_project_dir/index.html)" > $react_project_dir/index.html

[$]> echo "$(htmlq ".html.head.meta[name=description].content = \"React App Description\"" $react_project_dir/index.html)" > $react_project_dir/index.html

Current Options:

  1. cheerio
  2. himalaya
  3. jsdom
  4. xmltodict
  5. yq/xq

Similar Discussions:

I was able to do the following withyq/xq but it converts HTML to XML.

[$]> xq -x '.html.head.title = "Updated Title" | (.html.head.meta[] | select(."@name" == "description") | ."@content") |= "Updated Description"' index.html

vendethiel commented 6 months ago

Also interested in this use case. Being able to update a node, statically or via a command.