@@ -474,172 +474,8 @@ Writer.Block.RawBlock = function(el)
474474 end
475475end
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.
554477Writer .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" )
643479end
644480
645481Writer .Block .Div = function (el )
0 commit comments