Skip to content

Commit eb28161

Browse files
committed
fixes
1 parent 1c64753 commit eb28161

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/resources/filters/normalize/parsehtml.lua

+11-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function parse_html_tables()
8383
while cursor < len do
8484
-- find the first table start tag
8585
local i, j = string.find(el.text, start, cursor)
86+
print(len, cursor, i, j)
8687
if i == nil then
8788
-- no more tables
8889
break
@@ -95,7 +96,9 @@ function parse_html_tables()
9596
while cursor_2 < len do
9697
local k1, l1 = string.find(el.text, start, cursor_2)
9798
local k2, l2 = string.find(el.text, finish, cursor_2)
99+
print("nesting", nesting, k1, l1, k2, l2)
98100
if k1 == nil and k2 == nil then
101+
cursor = len
99102
break
100103
end
101104
if k1 and (k2 == nil or k1 < k2) then
@@ -106,7 +109,6 @@ function parse_html_tables()
106109
nesting = nesting - 1
107110
cursor_2 = l2 + 1
108111
if nesting == 0 then
109-
found = true
110112
local tableHtml = string.sub(el.text, i, l2)
111113
-- Pandoc's HTML-table -> AST-table processing does not faithfully respect
112114
-- `th` vs `td` elements. This causes some complex tables to be parsed incorrectly,
@@ -135,15 +137,16 @@ function parse_html_tables()
135137
end
136138
end,
137139
})
140+
cursor = l2 + 1
138141
if #tableDoc.blocks ~= 1 then
139142
warn("Unable to parse table from raw html block: skipping.")
140143
skip = true
141-
cursor = l2 + 1
142144
end
143145
if found and not skip then
144146
flags.has_tables = true
145-
blocks:insert(pandoc.RawBlock(el.format, string.sub(el.text, cursor, i - 1)))
146-
cursor = l2 + 1
147+
if cursor ~= i then
148+
blocks:insert(pandoc.RawBlock(el.format, string.sub(el.text, cursor, i - 1)))
149+
end
147150
blocks:insert(tableDoc.blocks[1])
148151
end
149152
break
@@ -152,12 +155,14 @@ function parse_html_tables()
152155
end
153156
end
154157
if cursor ~= 1 then
155-
blocks:insert(pandoc.RawBlock(el.format, string.sub(el.text, cursor)))
158+
if cursor <= len then
159+
blocks:insert(pandoc.RawBlock(el.format, string.sub(el.text, cursor)))
160+
end
156161
end
157162
if #blocks == 0 then
158163
return nil
159164
end
160-
return blocks
165+
return pandoc.Div(blocks)
161166
end
162167

163168
local filter
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
function Table(table)
2-
print("huh?")
32
-- we don't want this to be ever called in our test
4-
crash_with_stack_trace()
3+
assert(false)
54
end

0 commit comments

Comments
 (0)