It was 2010 Mar.

The following was copied from Roger's post. Use it as : jhtml thh (< 2 2 $
;:'5 asd gg h') (<0;0)}": each <"0 i.2 5

boxed  =: 32 = 3!:0
mt     =: 0 e. $
boxc   =: 9!:6 ''
tcorn  =: 2  0{boxc
tint   =: 1 10{boxc
bcorn  =: 8  6{boxc
bint   =: 7 10{boxc

sh     =: (*/@}: , {:)@(1&,)@$ ($,) ]
rows   =: */\.@}:@$
bl     =: }.@(,&0)@(+/)@(0&=)@(|/ i.@{.@(,&1))
mask   =: 1&,. #&, ,.&0@>:@i.@#
mat    =: mask@bl@rows { ' ' , sh

edge   =: ,@(1&,.)@[ }.@# +:@#@[ $ ]
left   =: edge&(3 9{boxc)@>@(0&{)@[ , "0 1"2 ]
right  =: edge&(5 9{boxc)@>@(0&{)@[ ,~"0 1"2 ]
top    =: 1&|.@(tcorn&,)@(edge&tint)@>@(1&{)@[ ,"2  ]
bot    =: 1&|.@(bcorn&,)@(edge&bint)@>@(1&{)@[ ,"2~ ]
perim  =: [ top [ bot [ left right

topleft=: (4{boxc)&((<0 0)}) @ ((_2{boxc)&,.) @ ((_1{boxc)&,)
inside =: 1 1&}. @: ; @: (,.&.>/"1) @: (topleft&.>)
take   =: {. ' '"_^:mt
frame  =: [ perim {@[ inside@:(take&.>)"2 ,:^:(1=#@$)@]
rc     =: (>./@sh&.>) @: (,.@|:"2@:(0&{"1);1&{"1) @: ($&>)

thorn1 =: ":`thbox @. boxed
thbox  =: (rc frame ]) @: (mat@thorn1&.>)

nmat    =: +/&.:<:@(*/\)@}:@$                       NB. #@mat
nbsp    =: [: ; ((<' ') 32}<"0 a.) {~ a. i. ]  NB. replace space by
pad     =: '<br>' $~ 4 * *@[ * -

BOXCHARS=:  9!:6 ''     NB. box drawing characters
SPACER  =: '<tr class=spacer><td> </td></tr>',CRLF

JARRAYSTYLE=: 0 : 0
<style type="text/css">
.jarray {font-family:monospace;}
table.jarray {border-collapse:collapse;}
table.jarray td {border:solid black thin; vertical-align:top;
padding:0.4em;}
table.jarray tr.spacer td {border:none;}
</style>
)

thh=: 3 : 0  NB. "thorn" (array formatting) producing HTML output
 JARRAYSTYLE,'<div class=jarray>',(0 thh y),'</div>'
:
 if. (0 e. $y) >: 32=3!:0 y do.                 NB. y is empty or not boxed
  nbsp _4}.(,z),x pad #z=. (mat ":y),"1 '<br>'
 else.                                          NB. y is boxed
  s=. {."1 (_2{.$t) ($,) t=. ":y                NB. s is 1st column in 1st
plane in ":y
  h=. <: 2 -~/\ I. s e. 0 3 6{ (9!:6 '')          NB. height (# lines) in
each row
  z=. h thh&.>"2 ,:^:(0>.2-#$y) y               NB. format each atom
  z=. ('<td>','</td>',~])&.> z                  NB. bracket each atom
  z=. <@('<tr>','</tr>',~;)"1 z                 NB. bracket each row
  '<table class=jarray>',(;(mask bl rows y){SPACER;,z),'</table>',(_4}.x
pad nmat t),CRLF
 end.
)


On Sun, Apr 27, 2014 at 11:23 AM, Pascal Jasmin <[email protected]>wrote:

> could not find anything good.
>
> there is jhtr_jhs_ though
>
> works well for 2d data.
>
>    jhtr_jhs_"1 ": each <"0 i.2 5
> <tr><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td></tr>
> <tr><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td></tr>
>
> not so well here:
>
>    jhtr_jhs_ "1 S:1  (< 2 2 $ ;:'5 asd gg h') (<0;0)}": each <"0 i.2 5
> <tr><td>5</td><td>asd</td></tr>
> <tr><td>gg</td><td>h</td></tr>
> <tr><td>1</td></tr>
>
> <tr><td>2</td></tr>
>
> <tr><td>3</td></tr>
>
> <tr><td>4</td></tr>
>
> <tr><td>5</td></tr>
>
> <tr><td>6</td></tr>
>
> <tr><td>7</td></tr>
>
> <tr><td>8</td></tr>
>
> <tr><td>9</td></tr>
>
> though this may fix it?
>
>    b2t =: '<table border="1">' , '</table>' ,~ jhtr"1
>    jhtr =: 3 : '''<tr>'',''</tr>'',~;((<''<td>''), each b2t^:(0<L.) each
> y),each<''</td>'''
>
>    b2t  (< 2 2 $ ;:'5 asd gg h') (<0;0)}": each <"0 i.2 5
> <table border="1">
> <tr>
>
> <td>
> <table border="1">
> <tr><td>5</td><td>asd</td></tr>
> <tr><td>gg</td><td>h</td></tr>
> </table>
> </td>
> <td>1</td>
> <td>2</td>
> <td>3</td>
> <td>4</td>
> </tr>
> <tr><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td></tr>
>
>   </table>
>
>     b2t  ": each <"0 i.2 5
> <table border="1">
> <tr><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td></tr>
> <tr><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td></tr>
> </table>
>
>
>
>
>
> ----- Original Message -----
> From: June Kim (김창준) <[email protected]>
> To: Programming forum <[email protected]>
> Cc:
> Sent: Saturday, April 26, 2014 8:26:08 PM
> Subject: Re: [Jprogramming] Unicode boxed display
>
> There is a verb for translating a boxed data into a html table, though
> incomplete yet, as I remember(I haven't been using it for a while). You may
> want to search here or the jwiki.
>
> sent from an android phone
> 2014. 4. 27. 오전 8:11에 "'Pascal Jasmin' via Programming" <
> [email protected]>님이 작성:
>
> > would be nice.  I requested the same about a month ago, though that was
> > really about special treatment for latin-1 characters.
> >
> > as you may be aware, utf8 has a variable 1 or 2 character encoding
> > depending on the character, and it would be harder to box, but I am sure
> > that even with full wchars, the approach of trying to pad with spaces
> > cannot work, especially not accross jhs and jqt.
> >
> > Without resorting to OS calls for textwidth, and drawing on OS
> > canvas/pictureboxes, an approach that would be reasonable is converting
> to
> > html table, and then blaming qt, chrome and firefox if it doesn't look
> > right.
> >
> > this command in jhs looks ok: (using new editable table feature)
> >
> > jtable 'e2';'n' [ n=: ,: <"1 ] 4 u: 97 98 99 +/ 0 256 512 1024
> >
> > so it will at least look good this way?
> >
> > Converting boxed data to an html table fragment seems useful enough to
> > have been done before.  Has it? (already jhs util?)
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Henry Rich <[email protected]>
> > To: Programming forum <[email protected]>
> > Cc:
> > Sent: Saturday, April 26, 2014 5:02:12 PM
> > Subject: [Jprogramming] Unicode boxed display
> >
> > Display of boxes containing non-ASCII characters messes up the alignment
> > of the boxes.  Has anyone written a verb to format such boxes so that
> > the boxes line up?
> >
> > Henry Rich
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to