@@ -31,12 +31,19 @@ class Cell {
3131 if ( [ 'boolean' , 'number' , 'string' ] . indexOf ( typeof content ) !== - 1 ) {
3232 this . content = String ( content ) ;
3333 } else if ( ! content ) {
34- this . content = '' ;
34+ this . content = this . options . href || '' ;
3535 } else {
3636 throw new Error ( 'Content needs to be a primitive, got: ' + typeof content ) ;
3737 }
3838 this . colSpan = options . colSpan || 1 ;
3939 this . rowSpan = options . rowSpan || 1 ;
40+ if ( this . options . href ) {
41+ Object . defineProperty ( this , 'href' , {
42+ get ( ) {
43+ return this . options . href ;
44+ } ,
45+ } ) ;
46+ }
4047 }
4148
4249 mergeTableOptions ( tableOptions , cells ) {
@@ -58,24 +65,35 @@ class Cell {
5865 this . head = style . head || tableStyle . head ;
5966 this . border = style . border || tableStyle . border ;
6067
61- let fixedWidth = tableOptions . colWidths [ this . x ] ;
62- if ( ( tableOptions . wordWrap || tableOptions . textWrap ) && fixedWidth ) {
63- fixedWidth -= this . paddingLeft + this . paddingRight ;
68+ this . fixedWidth = tableOptions . colWidths [ this . x ] ;
69+ this . lines = this . computeLines ( tableOptions ) ;
70+
71+ this . desiredWidth = utils . strlen ( this . content ) + this . paddingLeft + this . paddingRight ;
72+ this . desiredHeight = this . lines . length ;
73+ }
74+
75+ computeLines ( tableOptions ) {
76+ if ( this . fixedWidth && ( tableOptions . wordWrap || tableOptions . textWrap ) ) {
77+ this . fixedWidth -= this . paddingLeft + this . paddingRight ;
6478 if ( this . colSpan ) {
6579 let i = 1 ;
6680 while ( i < this . colSpan ) {
67- fixedWidth += tableOptions . colWidths [ this . x + i ] ;
81+ this . fixedWidth += tableOptions . colWidths [ this . x + i ] ;
6882 i ++ ;
6983 }
7084 }
7185 const { wrapOnWordBoundary = true } = tableOptions ;
72- this . lines = utils . colorizeLines ( utils . wordWrap ( fixedWidth , this . content , wrapOnWordBoundary ) ) ;
73- } else {
74- this . lines = utils . colorizeLines ( this . content . split ( '\n' ) ) ;
86+ return this . wrapLines ( utils . wordWrap ( this . fixedWidth , this . content , wrapOnWordBoundary ) ) ;
7587 }
88+ return this . wrapLines ( this . content . split ( '\n' ) ) ;
89+ }
7690
77- this . desiredWidth = utils . strlen ( this . content ) + this . paddingLeft + this . paddingRight ;
78- this . desiredHeight = this . lines . length ;
91+ wrapLines ( computedLines ) {
92+ const lines = utils . colorizeLines ( computedLines ) ;
93+ if ( this . href ) {
94+ return lines . map ( ( line ) => utils . hyperlink ( this . href , line ) ) ;
95+ }
96+ return lines ;
7997 }
8098
8199 /**
@@ -382,6 +400,7 @@ let CHAR_NAMES = [
382400 'right-mid' ,
383401 'middle' ,
384402] ;
403+
385404module . exports = Cell ;
386405module . exports . ColSpanCell = ColSpanCell ;
387406module . exports . RowSpanCell = RowSpanCell ;
0 commit comments