fix: fix issue with clean_text_nodes modifying arrary while iterating on it
							parent
							
								
									08e1ec95b8
								
							
						
					
					
						commit
						8e55396981
					
				
							
								
								
									
										13
									
								
								html.lua
								
								
								
								
							
							
						
						
									
										13
									
								
								html.lua
								
								
								
								
							| 
						 | 
					@ -3,6 +3,13 @@ local function trim(str)
 | 
				
			||||||
	return str:match("^%s*(.-)%s*$")
 | 
						return str:match("^%s*(.-)%s*$")
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local function shallow_copy(t)
 | 
				
			||||||
 | 
					  local t2 = {}
 | 
				
			||||||
 | 
					  for k,v in pairs(t) do
 | 
				
			||||||
 | 
					    t2[k] = v
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  return t2
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local M = {}
 | 
					local M = {}
 | 
				
			||||||
| 
						 | 
					@ -407,7 +414,7 @@ function M.parse_tokens_into_document( TOKENS )
 | 
				
			||||||
		i = i+1
 | 
							i = i+1
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DOCUMENT = M.clean_text_nodes( DOCUMENT )
 | 
						M.clean_text_nodes( DOCUMENT )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return DOCUMENT
 | 
						return DOCUMENT
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					@ -420,7 +427,7 @@ function M.clean_text_nodes(node)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for _, child in ipairs(node.children) do
 | 
							for _, child in ipairs( shallow_copy(node.children) ) do
 | 
				
			||||||
			M.clean_text_nodes( child )
 | 
								M.clean_text_nodes( child )
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
| 
						 | 
					@ -432,7 +439,7 @@ function M.clean_text_nodes(node)
 | 
				
			||||||
			error("Text node without a parent; should be impossible !")
 | 
								error("Text node without a parent; should be impossible !")
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for i, child in ipairs(node.parent.children) do
 | 
							for i, child in ipairs( shallow_copy(node.parent.children) ) do
 | 
				
			||||||
			if child == node then
 | 
								if child == node then
 | 
				
			||||||
				table.remove( node.parent.children, i )
 | 
									table.remove( node.parent.children, i )
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue