Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/craigbarnes/lua-gumbo
Moved to https://gitlab.com/craigbarnes/lua-gumbo
https://github.com/craigbarnes/lua-gumbo
dom html html-parser html5 lua parser sanitize-html
Last synced: about 2 months ago
JSON representation
Moved to https://gitlab.com/craigbarnes/lua-gumbo
- Host: GitHub
- URL: https://github.com/craigbarnes/lua-gumbo
- Owner: craigbarnes
- License: apache-2.0
- Created: 2013-08-17T04:50:04.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T21:27:02.000Z (4 months ago)
- Last Synced: 2024-05-22T22:34:06.916Z (4 months ago)
- Topics: dom, html, html-parser, html5, lua, parser, sanitize-html
- Language: C
- Homepage: https://gitlab.com/craigbarnes/lua-gumbo
- Size: 2.51 MB
- Stars: 130
- Watchers: 17
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
- awesome-resty - lua-gumbo
README
Synopsis
--------`lua-gumbo` is a [HTML5] parser and [DOM] library for [Lua]. It
originally started out as a set of Lua bindings for the Gumbo C
library, but has now absorbed an improved [fork] of it.Requirements
------------* C99 compiler
* [Lua] 5.1+ **or** [LuaJIT] 2.0+Installation
------------To install the latest release via [LuaRocks] use the command:
luarocks install gumbo
Usage
-----The `gumbo` module provides a [`parse`] function and a [`parseFile`]
function, which both return a [`Document`] node containing a tree of
[descendant] nodes. The structure and API of this tree mostly follows
the [DOM] Level 4 Core specification.For full API documentation, see: .
### Example
The following is a simple demonstration of how to find an element by ID
and print the contents of it's first child text node.```lua
local gumbo = require "gumbo"
local document = gumbo.parse('Hello World')
local foo = document:getElementById("foo")
local text = foo.childNodes[1].data
print(text) --> Hello World
```**Note:** this example omits error handling for the sake of simplicity.
Production code should wrap each step with [`assert()`] or some other,
application-specific error handling.See also: .
[Lua]: https://www.lua.org/
[LuaJIT]: http://luajit.org/
[C API]: https://www.lua.org/manual/5.2/manual.html#4
[HTML5]: https://html.spec.whatwg.org/multipage/introduction.html#is-this-html5?
[DOM]: https://dom.spec.whatwg.org/
[descendant]: https://dom.spec.whatwg.org/#concept-tree-descendant
[`parse`]: https://craigbarnes.gitlab.io/lua-gumbo/#parse
[`parseFile`]: https://craigbarnes.gitlab.io/lua-gumbo/#parsefile
[`Document`]: https://craigbarnes.gitlab.io/lua-gumbo/#document
[fork]: https://gitlab.com/craigbarnes/lua-gumbo/tree/master/lib
[LuaRocks]: https://luarocks.org/modules/craigb/gumbo
[luacov]: https://keplerproject.github.io/luacov/
[`assert()`]: https://www.lua.org/manual/5.3/manual.html#pdf-assert