@@ -24,7 +24,7 @@ local tag_mappings = {
2424 span = {},
2525 nav = {},
2626 header = {},
27- div = {},
27+ div = { left = " \n " , right = " \n " },
2828 section = { right = " \n " },
2929 p = { right = " \n\n " },
3030 ul = { right = " \n " },
@@ -86,6 +86,9 @@ local inline_tags = {
8686
8787local skipable_tags = {
8888 " input" ,
89+ " use" ,
90+ " svg" ,
91+ " button" ,
8992
9093 -- exceptions, (parent) table -> child
9194 " tr" ,
@@ -336,14 +339,36 @@ function transpiler:eval_child(node, parent_node)
336339
337340 -- checks if there should be additional spaces/characters between two elements
338341 if sibling then
339- local c_row_end , c_col_end = node :end_ ()
340- local s_row_start , s_col_start = sibling :start ()
342+ local start_row , start_col = node :end_ ()
343+ local target_row , target_col = sibling :start ()
341344
342345 -- The <pre> HTML element represents preformatted text
343346 -- which is to be presented exactly as written in the HTML file
344347 if self :has_parent_tag (node , " pre" ) or attributes .class == " _rfc-pre" then
345- local row , col = c_row_end , c_col_end
346- while row ~= s_row_start or col ~= s_col_start do
348+ local child = sibling :named_child ()
349+
350+ -- skip all the tags to get the actual text offset, see #56
351+ while child do
352+ local child_sibling = child :next_named_sibling ()
353+ if child :type () == " start_tag" and child_sibling then
354+ local c_row , c_col = child :end_ ()
355+ local s_row , s_col = child_sibling :start ()
356+
357+ if c_row == s_row and c_col == s_col then
358+ child = child_sibling :named_child ()
359+ else
360+ start_row , start_col = c_row , c_col
361+ target_row , target_col = s_row , s_col
362+
363+ if child_sibling :type () == " text" or " entity" then break end
364+ end
365+ else
366+ break
367+ end
368+ end
369+
370+ local row , col = start_row , start_col
371+ while row ~= target_row or col ~= target_col do
347372 local char = self :get_text_range (row , col , row , col + 1 )
348373 if char ~= " " then
349374 result = result .. char
@@ -355,7 +380,7 @@ function transpiler:eval_child(node, parent_node)
355380 end
356381 else
357382 local is_inline = is_inline_tag (tag_name ) or not tag_name -- is text
358- if is_inline and c_col_end ~= s_col_start then result = result .. " " end
383+ if is_inline and start_col ~= target_col then result = result .. " " end
359384 end
360385 end
361386
0 commit comments