1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#!/usr/bin/lua
-- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE.
-- Rename *.lua.doc to *.lua so LuaDoc detects them.
local lfs = require 'lfs'
for file in lfs.dir('../core') do
if file:match('^%..-%.luadoc$') then
os.rename('../core/'..file, '../core/'..file:match('^%..-%.lua'))
end
end
-- Generate LuaDoc.
os.execute('rm -rf ../doc/modules/')
os.execute('cd ../; luadoc -d doc/ --nofiles modules/ core/ lexers/lexer.lua')
-- Revert to *.lua.doc
for file in lfs.dir('../core') do
if file:match('^%..-%.lua$') then
os.rename('../core/'..file, '../core/'..file..'doc')
end
end
-- Insert Markdown in modules into LuaDoc.
local p = io.popen('grep -r "\\-\\- Markdown:" ../*')
for file in p:lines() do
local module
-- Open the Lua file and extract the Markdown lines.
local f = io.open(file:match('^[^:]+'))
local markdown, flag = {}, false
for line in f:lines() do
if flag and line:match('^%-%-') then
local match = line:match('^%-%- ([^\n]+)')
markdown[#markdown + 1] = match or ''
elseif flag then -- markdown ended
break
elseif line:match('^%-%- Markdown:') then
flag = true
elseif line:match('^module') then
module = line:match("^module%('([^']+)")
end
end
f:close()
-- Convert the Markdown into HTML.
markdown = table.concat(markdown, '\n')
f = io.open('tmp', 'w')
f:write(markdown)
f:close()
f = io.popen('perl ../doc/Markdown.pl tmp')
markdown = f:read('*all')
f:close()
os.execute('rm tmp')
-- Insert the Marked down HTML in the LuaDoc HTML file.
local filename = '../doc/modules/'..module..'.html'
f = io.open(filename)
local contents = f:read('*all')
f:close()
local s = contents:find('<h2>Functions</h2>')
if not s then s = contents:find('<h2>Tables</h2>') end
contents = contents:sub(1, s - 1)..markdown..contents:sub(s)
f = io.open(filename, 'w')
f:write(contents)
f:close()
end
p:close()
-- Generate the Manual.
p = io.popen('ls -1 ../doc/manual/*.md')
for mdfile in p:lines() do
local htmlfile = mdfile:match('^(.+).md$')..'.html'
html = [[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Textadept Manual</title>
<link rel="stylesheet" href="luadoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="main">
<div id="navigation">
%sidebar%
</div>
<div id="content">
%content%
</div>
</div>
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
</div>
</div>
</body>
</html>
]]
local sidebar_md = io.popen('../doc/Markdown.pl ../doc/sidebar.md')
html = html:gsub('%%sidebar%%', sidebar_md:read('*all'))
sidebar_md:close()
local content_md = io.popen('../doc/Markdown.pl '..mdfile)
local md = content_md:read('*all'):gsub('%%', '%%%%')
md = md:gsub('(<h%d>)([^<]+)(</h%d>)',
function(s, text, e)
return string.format('%s<a name="%s"></a>%s%s', s,
text:gsub(' ', '_'):lower(), text, e)
end)
html = html:gsub('%%content%%', md)
content_md:close()
local f = io.open(htmlfile, 'w')
f:write(html)
f:close()
end
p:close()
os.execute("sed -i 's/pre.example/pre, pre.example/;' ../doc/luadoc.css")
os.execute('cd ../; doxygen Doxyfile')
|