add a lua version
This commit is contained in:
		
							
								
								
									
										20
									
								
								filter.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								filter.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
function File2Block(filename)
 | 
			
		||||
    local fh = io.open(filename, "r")
 | 
			
		||||
    if not fh then
 | 
			
		||||
        io.stderr:write("Cannot open file: " .. filename .. "\n")
 | 
			
		||||
        return { pandoc.Plain { pandoc.Str("[Error: cannot read file " .. filename .. "]") } }
 | 
			
		||||
    end
 | 
			
		||||
    local contents = fh:read("*a")
 | 
			
		||||
    fh:close()
 | 
			
		||||
    return { pandoc.Plain { pandoc.Str(contents) } }
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function Div(e)
 | 
			
		||||
    local include = e.attributes["include"]
 | 
			
		||||
    if include then
 | 
			
		||||
        local blocks = File2Block(include)
 | 
			
		||||
        -- Replace the Div contents
 | 
			
		||||
        return pandoc.Div(blocks, e.attr)
 | 
			
		||||
    end
 | 
			
		||||
    return nil -- no change
 | 
			
		||||
end
 | 
			
		||||
		Reference in New Issue
	
	Block a user