https://github.com/rohitawate/domengine
DOM manipulation engine written in C++.
https://github.com/rohitawate/domengine
cpp11 dom-manipulation dom-tree html-parser interactive-shell interpreter
Last synced: 10 months ago
JSON representation
DOM manipulation engine written in C++.
- Host: GitHub
- URL: https://github.com/rohitawate/domengine
- Owner: RohitAwate
- License: mit
- Created: 2019-02-08T14:51:28.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-28T12:46:00.000Z (almost 7 years ago)
- Last Synced: 2025-04-10T04:05:29.268Z (10 months ago)
- Topics: cpp11, dom-manipulation, dom-tree, html-parser, interactive-shell, interpreter
- Language: C++
- Homepage:
- Size: 190 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DOM Manipulation Engine
`THIS IS A WORK IN PROGRESS`
A simple command-line program for parsing HTML files and building a DOM tree which can then be accessed and manipulated from an interactive shell or with scripts using jQuery-like selectors and commands.
This is nothing more than an effort at learning modern, idiomatic C++ and understanding the working of web browsers. Its amusing at best and useless at worst. Have fun with it!
_Check out the engine in action on ASCII Cinema:_
[](https://asciinema.org/a/227230)
## Building from source
You'll need the following installed:
- A compiler which supports at least C++11: `g++`, `clang++` or `Visual C++`
- `CMake`
- `make`
- `git`
#### Steps
```bash
# Clone the repository
git clone https://github.com/RohitAwate/DOMEngine
# Open the directory
cd DOMEngine/
# Create a new directory and open it
mkdir build/ && cd build/
# Generate the build files
cmake .. -DCMAKE_BUILD_TYPE=Release
# Build the project
make
# Open the bin/ folder
cd ../bin/
# Run interactive shell
./dom-engine
# Run script
./dom-engine
```
## Commands
- `print`\
Prints out the DOM tree.
- `$("@tagname#someId.firstClass.secondClass")`\
Selects a DOM element of type `tagname` with ID `someId` and classes `firstClass` and `secondClass`.
### Sub-commands for selected nodes:
- `parent` Prints the parent
- `children` Prints all the children
- `attrs` Prints all the attributes
- `innerhtml` Prints the innerHTML
- `return` Deselects the node and returns to shell
- `save file.html`\
Generates formatted HTML for the DOM tree and saves it to the specified file.
- `exit`\
Exits the shell.
## Writing Scripts
DOM Engine uses a simple scripting language which utilizes the commands mentioned above along with some syntactic elements such as semicolons and braces. Here is an example script.
```
$("#alertBox.alertDiv@div")
{
parent;
children;
attrs;
}
$("@div.text-field") {
parent;
attrs;
}
$("@div.text-field") { attrs; }
$("@body"){children;}
print;
```
### Selector Blocks
The first five lines demonstrate the usage of DOM Engine's selectors and running sub-commands on selected nodes. The selector is the same as you'd use in the shell with the sub-commands grouped together inside the curly braces, separated by semi-colons.
The next three selector blocks show alternative formatting.
Finally, the last line shows the `print` command terminated with a semi-colon.
Save the script in a file with the `.des` extension _(DOM Engine Script)_.
Run using: `dom-engine script.des`
## Goals and Progress
See the Kanban board [here](https://github.com/RohitAwate/DOMEngine/projects/1?fullscreen=true).
## License
MIT