Skip to content

Commit 0492eae

Browse files
authored
Merge pull request #31 from kdheepak/tables
2 parents 6ec2643 + a6068d2 commit 0492eae

File tree

4 files changed

+271
-186
lines changed

4 files changed

+271
-186
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: docs
22

33
on:
44
push:
5+
branches: main
56

67
permissions:
78
contents: write

doc/panvimdoc.txt

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -408,27 +408,58 @@ TABLE *panvimdoc-heading-table*
408408

409409
Support for markdown tables is also available:
410410

411-
****
412-
413-
│ Option │Backgr│ Default │ Description │
414-
│lightness │light│nil │Change background colors lightness. Options: 'bright', 'dim'. │
415-
│darkness │dark │nil │Change background colors darkness. Options: 'stark', 'warm'. │
416-
│solid_vert_split │both │false │Solid |hl-VertSplit| background. │
417-
│solid_line_nr │both │false │Solid |hl-LineNr| background. │
418-
│solid_float_border │both │false │Make |hl-FloatBorder| have a more distinguishable background highlight.│
419-
│darken_noncurrent_window │light│false │Make non-current window background darker than _Normal_. │
420-
│lighten_noncurrent_window │dark │false │Make non-current window background lighter than _Normal_. │
421-
│italic_comments │both │true │Make comments italicize. │
422-
│darken_comments │light│38 │Percentage to darken comments relative to Normal bg. │
423-
│lighten_comments │dark │38 │Percentage to lighten comments relative to Normal bg. │
424-
│darken_non_text │light│25 │Percentage to darken |hl-NonText| relative to Normal bg. │
425-
│lighten_non_text │dark │30 │Percentage to lighten |hl-NonText| relative to Normal bg. │
426-
│darken_line_nr │light│33 │Percentage to darken |hl-LineNr| relative to Normal bg. │
427-
│lighten_line_nr │dark │35 │Percentage to lighten |hl-LineNr| relative to Normal bg. │
428-
│darken_cursor_line │light│3 │Percentage to darken |hl-CursorLine| relative to Normal bg. │
429-
│lighten_cursor_line │dark │4 │Percentage to lighten |hl-CursorLine| relative to Normal bg. │
430-
│colorize_diagnostic_underline_text│both │false │Colorize the fg of DiagnosticUnderline*. │
431-
│transparent_background │both │false │Make background transparent. │
411+
-----------------------------------------------------------------------------------------------------
412+
Option Background Default Description
413+
------------------------------------ ------------ --------- -----------------------------------------
414+
lightness light nil Change background colors lightness.
415+
Options: 'bright', 'dim'.
416+
417+
darkness dark nil Change background colors darkness.
418+
Options: 'stark', 'warm'.
419+
420+
solid_vert_split both false Solid |hl-VertSplit| background.
421+
422+
solid_line_nr both false Solid |hl-LineNr| background.
423+
424+
solid_float_border both false Make |hl-FloatBorder| have a more
425+
distinguishable background highlight.
426+
427+
darken_noncurrent_window light false Make non-current window background darker
428+
than Normal.
429+
430+
lighten_noncurrent_window dark false Make non-current window background
431+
lighter than Normal.
432+
433+
italic_comments both true Make comments italicize.
434+
435+
darken_comments light 38 Percentage to darken comments relative to
436+
Normal bg.
437+
438+
lighten_comments dark 38 Percentage to lighten comments relative
439+
to Normal bg.
440+
441+
darken_non_text light 25 Percentage to darken |hl-NonText|
442+
relative to Normal bg.
443+
444+
lighten_non_text dark 30 Percentage to lighten |hl-NonText|
445+
relative to Normal bg.
446+
447+
darken_line_nr light 33 Percentage to darken |hl-LineNr| relative
448+
to Normal bg.
449+
450+
lighten_line_nr dark 35 Percentage to lighten |hl-LineNr|
451+
relative to Normal bg.
452+
453+
darken_cursor_line light 3 Percentage to darken |hl-CursorLine|
454+
relative to Normal bg.
455+
456+
lighten_cursor_line dark 4 Percentage to lighten |hl-CursorLine|
457+
relative to Normal bg.
458+
459+
colorize_diagnostic_underline_text both false Colorize the fg of DiagnosticUnderline*.
460+
461+
transparent_background both false Make background transparent.
462+
-----------------------------------------------------------------------------------------------------
432463

433464
MARKDOWN ONLY CONTENT *panvimdoc-heading-markdown-only-content*
434465

scripts/panvimdoc.lua

Lines changed: 1 addition & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -474,172 +474,8 @@ Writer.Block.RawBlock = function(el)
474474
end
475475
end
476476

477-
-- Position some text within a wider string (stuffed with blanks)
478-
-- 'way' is '0' to left justify, '1' for right and '2' for center
479-
function _position(txt, width, way)
480-
if way < 0 or way > 2 then
481-
return txt
482-
end
483-
local l = #txt
484-
if width > l then
485-
local b = (way == 0 and 0) or math.floor((width - l) / way)
486-
local a = width - l - b
487-
return string.rep(" ", b) .. txt .. string.rep(" ", a)
488-
else
489-
return txt
490-
end
491-
end
492-
493-
function _getNthRowLine(txt, nth, height, width)
494-
local s = ""
495-
if nth == height then
496-
s = subString(txt, (nth - 1) * width, width + 1) -- Avoid cutting last UTF8 sequence
497-
else
498-
s = subString(txt, (nth - 1) * width, width)
499-
end
500-
return s
501-
end
502-
503-
function get_1st_letter(s)
504-
local function get_1st_letter_rec(s, acc)
505-
if #s == 0 then
506-
return "", ""
507-
elseif #s == 1 then
508-
return s, ""
509-
else
510-
local m = s:match("^\27%[[0-9;]+m")
511-
512-
if m == nil then
513-
local m = s:match("^[^\27]\27%[[0-9;]+m")
514-
if m == nil then
515-
return acc .. s:sub(1, 1), s:sub(2)
516-
else
517-
return acc .. m, s:sub(#m + 1)
518-
end
519-
else
520-
return get_1st_letter_rec(s:sub(#m + 1), acc .. m)
521-
end
522-
end
523-
end
524-
return get_1st_letter_rec(s, "")
525-
end
526-
--
527-
-- Returns a substring of 's', starting after 'orig' and of length 'nb'
528-
-- Escape sequences are NOT counted as characters and thus are not cut.
529-
function subString(s, orig, nb)
530-
local col = 0
531-
local buf = ""
532-
local h
533-
534-
while #s > 0 and col < orig do
535-
h, s = get_1st_letter(s)
536-
col = col + 1
537-
end
538-
539-
col = 0
540-
while #s > 0 and col < nb do
541-
h, s = get_1st_letter(s)
542-
buf = buf .. h
543-
col = col + 1
544-
end
545-
return buf
546-
end
547-
548-
MAX_COL_WIDTH = 42
549-
MIN_COL_WIDTH = 5
550-
551-
-- Caption is a string, aligns is an array of strings,
552-
-- widths is an array of floats, headers is an array of
553-
-- strings, rows is an array of arrays of strings.
554477
Writer.Block.Table = function(el)
555-
local el = pandoc.utils.to_simple_table(el)
556-
local caption = el.caption
557-
local aligns = el.aligns
558-
local widths = el.widths
559-
local headers = el.headers
560-
local rows = el.rows
561-
local buffer = {}
562-
local table_width_for_adjust = 0
563-
local align = { ["AlignDefault"] = 0, ["AlignLeft"] = 0, ["AlignRight"] = 1, ["AlignCenter"] = 2 }
564-
local function add_row(s)
565-
table.insert(buffer, s)
566-
end
567-
-- Find maximum width for each column:
568-
local col_width = {}
569-
local row_height = {}
570-
for j, row in pairs(rows) do
571-
row_height[j] = 1
572-
end
573-
local header_height = 1
574-
local cell_width = 0
575-
local cell_height = 0
576-
table_width_for_adjust = #headers + 3 -- # of columns + 2 for borders + 1 for margin
577-
for i, header in pairs(headers) do
578-
table.insert(col_width, i, #header)
579-
for j, row in pairs(rows) do
580-
local _, n = blocks(row[i]):gsub("`", "")
581-
cell_width = #blocks(row[i]) + n
582-
if cell_width > col_width[i] then
583-
col_width[i] = cell_width
584-
end
585-
end
586-
if col_width[i] > MIN_COL_WIDTH then
587-
-- Sum of all widths for columns that could be reduced
588-
table_width_for_adjust = table_width_for_adjust + col_width[i]
589-
end
590-
end
591-
local last = #col_width
592-
local tmpl = ""
593-
for i, w in pairs(col_width) do
594-
-- Here, 'c' stands for "crossing char" and will be replaced
595-
tmpl = tmpl .. string.rep("", w) .. (i < last and "c" or "")
596-
end
597-
local CELL_SEP = ""
598-
599-
if caption ~= "" then
600-
add_row(Writer.Inline.Strong(caption))
601-
add_row("")
602-
end
603-
local header_row = {}
604-
local empty_header = true
605-
for i, h in pairs(headers) do
606-
-- Table headers have same color as document headers
607-
empty_header = empty_header and h == ""
608-
end
609-
local content = ""
610-
local s = ""
611-
if not empty_header then
612-
for k = 1, header_height do -- Break long lines
613-
content = ""
614-
s = ""
615-
for i, h in pairs(headers) do
616-
local h, _ = string.gsub(blocks(h), "`", "")
617-
s = _getNthRowLine(h, k, header_height, col_width[i])
618-
s = _position(s, col_width[i], 2)
619-
content = content .. CELL_SEP .. s
620-
end
621-
add_row(content .. CELL_SEP)
622-
end
623-
end
624-
for i, row in pairs(rows) do
625-
content = ""
626-
for k = 1, row_height[i] do -- Break long lines
627-
content = ""
628-
s = ""
629-
for j, c in pairs(row) do
630-
if col_width[j] then
631-
local c, _ = string.gsub(blocks(c), "`", "")
632-
s = _getNthRowLine(c, k, row_height[i], col_width[j])
633-
content = content .. CELL_SEP .. _position(s, col_width[j], align[aligns[j]])
634-
end
635-
end
636-
add_row(content .. CELL_SEP)
637-
end
638-
if i < #rows then
639-
end
640-
end
641-
add_row("")
642-
return table.concat(buffer, "\n")
478+
return pandoc.write(pandoc.Pandoc({ el }), "plain")
643479
end
644480

645481
Writer.Block.Div = function(el)

0 commit comments

Comments
 (0)