@@ -83,6 +83,7 @@ function parse_html_tables()
83
83
while cursor < len do
84
84
-- find the first table start tag
85
85
local i , j = string.find (el .text , start , cursor )
86
+ print (len , cursor , i , j )
86
87
if i == nil then
87
88
-- no more tables
88
89
break
@@ -95,7 +96,9 @@ function parse_html_tables()
95
96
while cursor_2 < len do
96
97
local k1 , l1 = string.find (el .text , start , cursor_2 )
97
98
local k2 , l2 = string.find (el .text , finish , cursor_2 )
99
+ print (" nesting" , nesting , k1 , l1 , k2 , l2 )
98
100
if k1 == nil and k2 == nil then
101
+ cursor = len
99
102
break
100
103
end
101
104
if k1 and (k2 == nil or k1 < k2 ) then
@@ -106,7 +109,6 @@ function parse_html_tables()
106
109
nesting = nesting - 1
107
110
cursor_2 = l2 + 1
108
111
if nesting == 0 then
109
- found = true
110
112
local tableHtml = string.sub (el .text , i , l2 )
111
113
-- Pandoc's HTML-table -> AST-table processing does not faithfully respect
112
114
-- `th` vs `td` elements. This causes some complex tables to be parsed incorrectly,
@@ -135,15 +137,16 @@ function parse_html_tables()
135
137
end
136
138
end ,
137
139
})
140
+ cursor = l2 + 1
138
141
if # tableDoc .blocks ~= 1 then
139
142
warn (" Unable to parse table from raw html block: skipping." )
140
143
skip = true
141
- cursor = l2 + 1
142
144
end
143
145
if found and not skip then
144
146
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
147
150
blocks :insert (tableDoc .blocks [1 ])
148
151
end
149
152
break
@@ -152,12 +155,14 @@ function parse_html_tables()
152
155
end
153
156
end
154
157
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
156
161
end
157
162
if # blocks == 0 then
158
163
return nil
159
164
end
160
- return blocks
165
+ return pandoc . Div ( blocks )
161
166
end
162
167
163
168
local filter
0 commit comments