Skip to content

Commit 9d27e9c

Browse files
committed
Fixed error in old Markdown library.
1 parent b1102dd commit 9d27e9c

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

examples/testsite/scripts/tests/runTests.lua

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,24 @@ return function()
2626
return contents
2727
end
2828

29+
local function formatBytes(n)
30+
if n >= 1024^4/10 then return F("%.2f TiB", n/1024^4)
31+
elseif n >= 1024^3/10 then return F("%.2f GiB", n/1024^3)
32+
elseif n >= 1024^2/10 then return F("%.2f MiB", n/1024^2)
33+
elseif n >= 1024^1/10 then return F("%.2f KiB", n/1024^1)
34+
else return F("%d bytes", n ) end
35+
end
36+
37+
38+
2939
--[[ XML module tests.
3040
-- require"pl.xml"
3141
timerStart("our") ; tests.xmlTests(xml) ; timerEnd()
3242
-- timerStart("pl") ; tests.xmlTests(require"pl.xml") ; timerEnd()
3343
--]]
3444

45+
46+
3547
--[==[ XML parsing.
3648
local xmlStr = (
3749
readTextFile"../../local/test-wordpress-export.xml" or
@@ -63,6 +75,8 @@ return function()
6375
-- print(doc:tostring())
6476
--]==]
6577

78+
79+
6680
--[==[ HTML parsing.
6781
local htmlStr = (
6882
-- readTextFile"../../local/test-youtube-watch-page.html" or
@@ -102,6 +116,8 @@ return function()
102116
print(doc:toHtml())
103117
--]==]
104118

119+
120+
105121
-- [[ Markdown parsing.
106122
do
107123
local TEST_OUTPUT_REPLACEMENTS = {
@@ -193,7 +209,7 @@ return function()
193209
:gsub("'", "'")
194210
)
195211

196-
if html ~= test.output then
212+
if html ~= test.output and 1==1 then
197213
print(((
198214
"Error @ Test "..test.n..":\n"
199215
-- .."================================\n"
@@ -216,6 +232,8 @@ return function()
216232
end
217233
--]]
218234

235+
236+
219237
--[[ Get image dimensions.
220238
local path = "/images/sakura-trees.jpg"
221239
local w, h = assert(XXX_getImageDimensionsFast(path, true))
@@ -230,8 +248,12 @@ return function()
230248
-- print(require"socket.core".gettime()-time)
231249
--]]
232250

251+
252+
233253
print()
234254
print("TESTS COMPLETED!!!")
255+
print("Memory: "..formatBytes(collectgarbage"count"*1024))
235256
print()
257+
236258
os.exit(2)
237259
end

lib/markdownOld.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,9 @@ function strip_link_definitions(text)
11411141
local linkdb = {}
11421142

11431143
local function link_def(id, url, title)
1144-
id = id:match("%[(.+)%]"):lower()
1144+
id = id:match("%[(.+)%]")
1145+
if not id then return end
1146+
id = id:lower()
11451147
linkdb[id] = linkdb[id] or {}
11461148
linkdb[id].url = url or linkdb[id].url
11471149
linkdb[id].title = title or linkdb[id].title

src/markdown.lua2p

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ local PATTERN_LINE = "[^\n]*"
2222
local PATTERN_BLANK_LINE = "^[ \t]*$"
2323
local PATTERN_WHITESPACE_CHAR = "[ \t\n\v\f]" -- Excluding \r.
2424
local PATTERN_WHITESPACE_SEQUENCE = PATTERN_WHITESPACE_CHAR.."+"
25-
local PATTERN_UNICODE_WHITESPACE_CHAR = PATTERN_WHITESPACE_CHAR -- @Incomplete: Include Unicode Zs.
25+
local PATTERN_UNICODE_WHITESPACE_CHAR = PATTERN_WHITESPACE_CHAR -- @Incomplete: Include Unicode general category Zs.
2626
local PATTERN_NON_WHITESPACE_CHAR = "[^ \t\n\v\f]"
27-
local PATTERN_NON_UNICODE_WHITESPACE_CHAR = "[^ \t\n\v\f]" -- @Incomplete: Include Unicode Zs.
27+
local PATTERN_NON_UNICODE_WHITESPACE_CHAR = "[^ \t\n\v\f]" -- @Incomplete: Include Unicode general category Zs.
2828
local PATTERN_ASCII_PUNCTUATION_CHAR = "[\33-\47\58-\64\91-\96\123-\126]"
29-
local PATTERN_PUNCTUATION_CHAR = PATTERN_ASCII_PUNCTUATION_CHAR -- @Incomplete: Include Unicode Pc+Pd+Pe+Pf+Pi+Po+Ps.
29+
local PATTERN_PUNCTUATION_CHAR = PATTERN_ASCII_PUNCTUATION_CHAR -- @Incomplete: Include Unicode general category P (Pc+Pd+Pe+Pf+Pi+Po+Ps).
3030

3131
local REPLACEMENT_CHARACTER = "\239\191\189" -- U+FFFD
3232

@@ -1847,7 +1847,7 @@ function markdown.parse(s)
18471847
local codeEl = preEl[1]
18481848

18491849
local toTrim = (preEl._contentStartColumn-1) % 4
1850-
local trimPat = toTrim > 0 and "^"..(" ?"):rep(toTrim) or nil -- :HandleTabs
1850+
local trimPat = toTrim > 0 and "^"..(" ?"):rep(toTrim) or nil -- @Incomplete: Handle tabs.
18511851

18521852
for i, emptyLine in ipairs(blankLines) do
18531853
if trimPat then emptyLine = emptyLine:gsub(trimPat, "") end
@@ -2164,7 +2164,7 @@ function markdown.parse(s)
21642164
assert(codeEl.tag == "code")
21652165

21662166
for i, emptyLine in ipairs(blankLines) do
2167-
table.insert(codeEl, emptyLine:sub(5)) -- :HandleTabs
2167+
table.insert(codeEl, emptyLine:sub(5)) -- @Incomplete: Handle tabs.
21682168
table.insert(codeEl, "\n")
21692169
blankLines[i] = nil
21702170
end

0 commit comments

Comments
 (0)