Lua 到 Html |
|
[!] 版本说明: 源代码需要在 _VERSION 处理方面进行少量更改才能在 Lua 5.1 下运行。可能需要进行一些其他更改才能正确突出显示 5.1 语法。
有一个 Lua 4.0 版本 [3],以及一个 Lua 5.0 版本 [4],它与删除了所有 %
符号的相同文件。
这是一个示例网页列表 [5]
运行 Lua 4.0 版本,如下所示: lua -f lua2html.lua x.lua > x.html
以及 Lua 5.0 版本,如下所示: lua lua52html.lua x.lua > x.html
lua2html.pl
可以找到 [这里]。
$ lua Lua 5.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio > = 1 + math.sqrt(2) 2.4142135623731 > print("math.sqrt(2)") math.sqrt(2) >
{{{!LuaInteractive $ lua Lua 5.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio > = 1 + math.sqrt(2) 2.4142135623731 >}}}
use strict; use Syntax::Highlight::Engine::Kate::Lua; my $sh = Syntax::Highlight::Engine::Kate::Lua->new( substitutions => { "<" => "<", ">" => ">", "&" => "&", " " => " ", "\t" => " ", "\n" => "<BR>\n", }, format_table => { Alert => ['<span class="alert">', '</span>'], BaseN => ['<span class="basen">', '</span>'], BString => ['<span class="bstring">', '</span>'], Char => ['<cpan class="char">', '</span>'], Comment => ['<span class="comment">', '</span>'], DataType => ['<span class="datatype">', '</span>'], DecVal => ['<span class="decval">', '</span>'], Error => ['<span class="error">', '</span>'], Float => ['<span class="float">', '</span>'], Function => ['<span class="function">', '</span>'], IString => ['<span class="istring">', '</span>'], Keyword => ['<span class="keyword">', '</span>'], Normal => ['', ''], Operator => ['<span class="operator">', '</span>'], Others => ['<span class="others">', '</span>'], RegionMarker => ['<span class="regionmarker">', '</span>'], Reserved => ['<span class="reserved">', '</span>'], String => ['<span class="string">', '</span>'], Variable => ['<span class="variable">', '</span>'], Warning => ['<span class="warning">', '</span>'], }, ); my $html = $sh->highlightText(qq( local function test(y, z, ...) for x in 1,y do print(x) end -- loop local w = y * 2 + math.random() print(2, y, 'test"2', "test\"'2'", [[math.random]], #z, 3, ...) )); my $css = qq( <style type="text/css"> span.comment { color: #00a000; } span.string { color: #0000c0; } span.keyword { color: #a00000; font-weight: bold; } span.reserved { color: #a0a000; font-weight: bold; } </style> ); $html = qq( <html> <head> $css </head> <body> $html </body> ); print $html;