Lua 轉 HTML |
|
[!] 版本注意事項:原始碼在處理 Lua 5.1 時,需要針對 _VERSION 進行一些小幅更動才行。對於正確的 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;