Skip to content

danieldop/lua-gumbo

 
 

Repository files navigation

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

Installation

To install the latest release via LuaRocks, first ensure the requirements listed above are installed, then use the command:

luarocks install gumbo

Note: Installing on Windows is not supported.

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: https://craigbarnes.gitlab.io/lua-gumbo/.

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.

local gumbo = require "gumbo"
local document = gumbo.parse('<div id="foo">Hello World</div>')
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: https://craigbarnes.gitlab.io/lua-gumbo/#examples.

About

Lua HTML5 parser and DOM API (mirrored from https://gitlab.com/craigbarnes/lua-gumbo)

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 46.4%
  • Lua 18.1%
  • C++ 16.4%
  • Ragel 15.7%
  • Makefile 2.0%
  • HTML 0.8%
  • Other 0.6%