Skip to content

gui-ying233/Bricks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bricks:一个用于解析 HTML 的 Lua 模块

Bricks 是一个解析 HTML 的 Lua 模块,整体类似于JS。

半成品,心血来潮瞎写的。

喵一喵

local b = require('bricks')

local document = b:new([['<h1 id="top" class="heading heading-1">Hello!</h1>
<div style="margin: 0 auto;" class="container">
	<p>
		My name is <dfn>Bricks</dfn>, a module for parsing HTML.<br>
		Thank you for your visit.
	</p>
	<p>visitors:</p>
	<ul>
		<li>ACandy</li>
		<li>Bricks</li>
		<li>Catgirl</li>
		<li>...</li>
	</ul>
</div>']])


local h1 = document:getElementById('top')
print(h1.id, h1.className)

local div = document:getElementsByClassName('container')[1]
print(div.style.margin)

local p = div:getElementsByTagName('p')[1]
print(p.innerHTML)

local dfn = p.children[1]
print(dfn.outerHTML)

输出:

top     heading heading-1
0 auto

                My name is <dfn>Bricks</dfn>, a module for parsing HTML.<br>
                Thank you for your visit.

<dfn>Bricks</dfn>

支持

初始化b:new()

获取元素document:getElementsByTagName()document:getElementById()document:getElementsByClassName()

元素属性ele.tagNameele.outerHTMLele.innerHTMLele.attributesele.idele.classListele.classNameele.styleele.datasetele.childrenele.parentElement

友情推荐

ACandy: a sugary Lua module for building HTML

About

一个用于解析 HTML 的 Lua 模块

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages