Skip to content

Commit ac6b507

Browse files
authored
Merge pull request #34 from kdheepak/missing-elements
2 parents 3f6f0d7 + de1883a commit ac6b507

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

scripts/panvimdoc.lua

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ local function escape(s, in_attribute)
2929
return s
3030
end
3131

32-
function indent(s, fl, ol)
32+
local function indent(s, fl, ol)
3333
local ret = {}
3434
local i = 1
3535
for l in s:gmatch("[^\r\n]+") do
@@ -58,7 +58,7 @@ local function blocks(bs, sep)
5858
local dbuff = {}
5959
for i = 1, #bs do
6060
local el = bs[i]
61-
dbuff[#dbuff + 1] = Writer.Block[el.tag](el)
61+
dbuff[#dbuff + 1] = Writer[pandoc.utils.type(el)][el.tag](el)
6262
end
6363
return table.concat(dbuff, sep)
6464
end
@@ -77,7 +77,6 @@ local CURRENT_HEADER = nil
7777
local HEADER_COUNT = 1
7878
local toc = {}
7979
local links = {}
80-
local notes = {}
8180

8281
local function osExecute(cmd)
8382
local fileHandle = assert(io.popen(cmd, "r"))
@@ -171,10 +170,10 @@ local function renderNotes()
171170
add(string.rep("=", 78) .. "\n" .. string.format("%s%s%s", left, padding, right))
172171
add("")
173172
for i, v in ipairs(links) do
174-
add(i .. ". *" .. v[1] .. "*" .. ": " .. v[2])
173+
add(i .. ". *" .. v.caption .. "*" .. ": " .. v.src)
175174
end
176175
end
177-
return table.concat(t, "\n")
176+
return table.concat(t, "\n") .. "\n"
178177
end
179178

180179
function renderFooter()
@@ -385,7 +384,7 @@ Writer.Inline.Link = function(el)
385384
end
386385

387386
Writer.Inline.Image = function(el)
388-
return "<img src='" .. escape(src, true) .. "' title='" .. escape(tit, true) .. "'/>"
387+
links[#links + 1] = { caption = inlines(el.caption), src = el.src }
389388
end
390389

391390
Writer.Inline.Code = function(el)
@@ -446,8 +445,8 @@ Writer.Inline.Cite = function(el)
446445
end
447446
end
448447

449-
Writer.Block.Plain = function(s)
450-
return inlines(s.content)
448+
Writer.Block.Plain = function(el)
449+
return inlines(el.content)
451450
end
452451

453452
Writer.Block.RawBlock = function(el)
@@ -482,3 +481,27 @@ Writer.Block.Div = function(el)
482481
-- TODO: Add more special features here
483482
return blocks(el.content)
484483
end
484+
485+
Writer.Block.Figure = function(el)
486+
return blocks(el.content)
487+
end
488+
489+
Writer.Block.BlockQuote = function(el)
490+
local lines = {}
491+
for line in blocks(el.content):gmatch("[^\r\n]+") do
492+
table.insert(lines, line)
493+
end
494+
return "\n " .. table.concat(lines, "\n ") .. "\n"
495+
end
496+
497+
Writer.Block.HorizontalRule = function()
498+
return string.rep("-", 78)
499+
end
500+
501+
Writer.Block.LineBlock = function(el)
502+
local buffer = {}
503+
el.content:map(function(item)
504+
table.insert(buffer, table.concat({ "| ", inlines(item) }))
505+
end)
506+
return "\n" .. table.concat(buffer, "\n") .. "\n"
507+
end

test/markdown.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@testset "markdown" begin
2+
doc = test_pandoc(
3+
"""
4+
# panvimdoc
5+
6+
> Testing block quote
7+
8+
| testing line
9+
| block
10+
11+
![caption](image.png)
12+
13+
""";
14+
toc = false,
15+
)
16+
@test doc == """
17+
*test.txt* Test Description
18+
19+
==============================================================================
20+
1. panvimdoc *test-panvimdoc*
21+
22+
23+
Testing block quote
24+
25+
| testing line
26+
| block
27+
==============================================================================
28+
2. Links *test-links*
29+
30+
1. *caption*: image.png
31+
32+
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
33+
34+
vim:tw=78:ts=8:noet:ft=help:norl:
35+
"""
36+
end

0 commit comments

Comments
 (0)