Skip to content

Commit

Permalink
inline style in table and auto wrap
Browse files Browse the repository at this point in the history
deal inline style in table.

use text block to auto wrap text in cell:

        T{
        long text...
        will be wrap.
        ...
        }T
  • Loading branch information
gholk committed Dec 8, 2016
1 parent 9f67f7d commit 7b5933b
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions lib/marked-man.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,46 +290,55 @@ Parser.prototype.roff_tok = function() {
* use **tbl** macro format table in man page.
*/
case 'table': {
var tblTable = [];
tblTable.push('.TS'); // table start

tblTable.push('tab(|) box;');
/* set `|` as seperator,
* set table border
* command need end by `;`h
*/
var tblText = [], // troff tbl macro text.
rowArray = []; // tmp array store cells in a table row.

tblText.push('.TS'); // table start

/* for 4 column table, there should be
tblText.push('tab(|) expand box;');
/* set `|` as seperator.
*
* set table border.
*
* .TS
* tab(|) box;
* l l l l.
* h1|h2|h3|h4
* _
* c1|c2|c3|c4
* .TE
* set expand to full screen. without expand,
* tbl sometimes mistake terminal width.
* but expand is ugly sometimes...
*
* at 4 `l` at header.
* command need end by `;`.
*/

var columnNumberRow = 'l';
for (var i=0; i<this.token.header.length-1; i++)
columnNumberRow += ' l';
var columnNumberRow = '';

for (var i=0; i<this.token.header.length; i++) {
columnNumberRow += ' l';
rowArray.push(
'T{\n' +
this.inline.output(this.token.header[i]) +
'\nT}'
);
}
columnNumberRow += '.';
tblTable.push(columnNumberRow);
tblText.push(columnNumberRow);
tblText.push(rowArray.join('|'));

tblText.push('_'); // add an horizantle line after header


tblTable.push(this.token.header.join('|'));
tblTable.push('_'); // add an horizantle line after header
/* run each row */
for (var i=0; i<this.token.cells.length; i++) {
rowArray = []; // new array store cells in a row.
var thisRow = this.token.cells[i]; // pointer to old array.

for (var i=0; i<this.token.cells.length; i++)
tblTable.push(this.token.cells[i].join('|'));
/* run each cell */
for (var j=0; j<thisRow.length; j++)
rowArray.push('T{\n' + this.inline.output(thisRow[j]) + '\nT}');

tblText.push(rowArray.join('|'));
}

tblTable.push('.TE');
tblText.push('.TE');

return tblTable.join('\n') + '\n';
return tblText.join('\n') + '\n';
}
}
};
Expand Down

0 comments on commit 7b5933b

Please sign in to comment.