craigbarnes / lua-gumbo

Moved to https://gitlab.com/craigbarnes/lua-gumbo

Home Page:https://gitlab.com/craigbarnes/lua-gumbo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 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: 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

Moved to https://gitlab.com/craigbarnes/lua-gumbo

https://gitlab.com/craigbarnes/lua-gumbo

License:Apache License 2.0


Languages

Language:C 63.1%Language:Lua 18.7%Language:Ragel 15.5%Language:Makefile 1.8%Language:HTML 0.8%Language:Shell 0.1%Language:sed 0.1%Language:Awk 0.0%