:Namespace HTMLInput
⎕IO ⎕ML←1 0
⎕FX 'r←CRLF' 'r←⎕UCS 13 10' ⍝ So it will be :Included
enlist←{⎕ML←2 ⋄ ∊⍵} ⍝ APL2 enlist
eis←{2>|≡⍵:,⊂⍵ ⋄ ⍵} ⍝ Enclose if simple
ine←{0∊⍴⍺:'' ⋄ ⍵} ⍝ if not empty
ischar←{0 2∊⍨10|⎕DR⍵}
∇ r←atts Enclose innerhtml;i
⍝ Put an HTML tag around some HTML
:If 1<|≡innerhtml ⋄ innerhtml←CRLF,enlist innerhtml,¨⊂CRLF ⋄ :EndIf
i←¯1+(atts←,atts)⍳' '
r←'<',atts,'>',innerhtml,'',(i↑atts),'>',CRLF
∇
∇ r←Tag tag
⍝ Make a self-closing tag
r←'<',tag,' />',CRLF
∇
Attrs←{
⍝ format name/value pairs as tag attributes
⍝ ⍵ - name/value pairs, valid forms:
⍝ 'name="value"'
⍝ [n,2⍴] 'name1' 'value1' ['name2' 'value2'...]
⍝ ('name1' 'value1') [('name2' 'value2')]
0∊⍴⍵:''
{
enlist{(×⍴⍺)/' ',⍺,(×⍴⍵)/'="',⍵,'"'}/,∘⍕¨⊃⍵
}_pifn¨,2 _box _pifn{
1=|≡⍵:⍵
2=|≡⍵:{1=⍴⍴⍵:(⌽2,0.5×⍴⍵)⍴⍵ ⋄ ⍵}⍵
↑⍵}⍵
}
Styles←{
⍝ format name/value pairs as CSS style attributes
⍝ ⍵ - name/value pairs, valid forms:
⍝ 'name: value'
⍝ [n,2⍴] 'name1' 'value1' ['name2' 'value2'...]
⍝ ('name1' 'value1') [('name2' 'value2')]
0∊⍴⍵:''
{'{',({';'=¯1↑⍵:⍵ ⋄ ⍵,';'}⍵),' }'}{
enlist{(×⍴⍺)/' ',⍺,(×⍴⍵)/': ',⍵,';'}/,∘⍕¨⊃⍵
}_pifn¨,2 _box _pifn{
1=|≡⍵:⍵
2=|≡⍵:{1=⍴⍴⍵:(⌽2,0.5×⍴⍵)⍴⍵ ⋄ ⍵}⍵
↑⍵}⍵
}
_box←{⍺←1 ⋄ (⊂⍣(⍺=|≡⍵))⍵}
_pifn←{({⍵''}⍣(1=|≡⍵))⍵}
∇ html←TextToHTML html;mask;CR
⍝ Add/insert
, replaces CR with
,CR
:If ~0∊⍴html
:If ∨/mask←html=CR←''⍴CRLF
(mask/html)←⊂'
',CR
html←enlist html
:EndIf
html,←(~∨/¯2↑mask)/'
',CRLF
:EndIf
∇
∇ html←APLToHTML APL
⍝ returns APL code formatted for HTML
:Trap 0
html←'whitespace' 'preserve'⎕XML 1 3⍴0 'x'APL
:Else
html←APL
:EndTrap
((' '=html)/html)←⊂' '
html←enlist html
∇
∇ html←{n}BRA html
⍝ (BReak After) Add n
's after html
:If 0=⎕NC'n' ⋄ n←1 ⋄ :EndIf
html,←(n{(⍺×⍴⍵)⍴⍵}'
'),CRLF
∇
∇ html←{n}BR html
⍝ (BReak) Add n
's before html
:If 0=⎕NC'n' ⋄ n←1 ⋄ :EndIf
html←(n{(⍺×⍴⍵)⍴⍵}'
'),CRLF,html
∇
∇ html←{n}SP html
⍝ (SPace) Add n non-breaking spaces before html
:If 0=⎕NC'n' ⋄ n←1 ⋄ :EndIf
html←(n{(⍺×⍴⍵)⍴⍵}' '),html
∇
∇ r←name CheckBox pars
⍝ pars: checked [attributes]
pars←pars,(⍴,pars)↓0 ''
r←Tag'input ',(2⊃pars),' type="checkbox" id="',name,'" name="',name,'"',(0≠1⊃pars)/' checked="1"'
∇
∇ r←{src}JS script
⍝ Javascript
⍝ script: javascript script if no src or filename if src=1
:If 0≠⎕NC'src' ⋄ r←'script type="text/javascript" src="',src,'"'Enclose''
:Else ⋄ r←'script type="text/javascript"'Enclose script ine CRLF,'/* */',CRLF
:EndIf
∇
∇ r←{name}DropDown pars;values;display;gv;mask
⍝ par - items selected_value(s) attributes sort
⍝ if items is 2 column matrix, [;1] is values, [;2] is display
:If 0=⎕NC'name' ⋄ name←'' ⋄ :EndIf
pars←pars,(⍴pars)↓('Item1' 'Item2')'Item1' '' 0
:If ~ischar 1⊃pars ⋄ pars[1]←⊂⍕¨1⊃pars ⋄ :EndIf
:If 1=⍴⍴1⊃pars ⋄ values display←pars[1]
:Else ⋄ values display←↓[1]1⊃pars
:EndIf
mask←values∊eis 2⊃pars
:If 4⊃pars ⋄ gv←⍒mask ⋄ values←values[gv] ⋄ display←display[gv] ⋄ mask←mask[gv] ⋄ :EndIf ⍝ Sort selected items first
r←'',CRLF
∇
∇ r←{atts}(method Form)innerhtml
:If 9=⎕NC'atts' ⋄ atts←'action="',atts.Page,'"' ⍝ MildPage calling
:ElseIf 0=⎕NC'atts' ⋄ atts←'' ⋄ :EndIf
atts,←' method="',method,'"'
atts,←('post'≡#.Strings.lc method)/' enctype="multipart/form-data"'
r←('form ',atts)Enclose innerhtml
∇
∇ r←name Edit pars
⍝ pars: [value [size [attributes]]]
pars←,eis pars
pars←pars,(⍴pars)↓'' ⍬ ''
r←Tag'input ',(3⊃pars),' type="text" size="',(⍕2⊃pars),'" id="',name,'" name="',name,'" value="',(1⊃pars),'"'
∇
∇ r←name Submit pars
⍝ pars: value [attributes]
pars←,eis pars
pars←pars,(⍴pars)↓'Submit' '' ''
r←Tag'input type="submit" ',(2⊃pars),' id="',name,'" name="',name,'" value="',(1⊃pars),'"'
∇
∇ r←name Button pars
⍝ pars: value [attributes]
pars←,eis pars
pars←pars,(⍴pars)↓'Push Me!' '' ''
r←Tag'input type="button" ',(2⊃pars),' id="',name,'" name="',name,'" value="',(1⊃pars),'"'
∇
∇ r←name File pars
⍝ pars: [value [size [attributes]]
pars←,eis pars
pars←pars,(⍴pars)↓'' ⍬ ''
r←Tag'input ',(3⊃pars),' type="file" size="',(⍕2⊃pars),'" id="',name,'" name="',name,'" value="',(1⊃pars),'"'
∇
∇ r←name Hidden pars
⍝ pars: value [attributes]
pars←,eis pars
pars←pars,(⍴pars)↓'' ''
r←Tag'input ',(2⊃pars),' type="hidden" id="',name,'" name="',name,'" value="',(1⊃pars),'"'
∇
∇ r←name Password pars
⍝ pars: size [value [attributes]]
pars←pars,(⍴pars)↓'' ⍬ ''
r←Tag'input ',(3⊃pars),' type="password" size="',(⍕2⊃pars),'" id="',name,'" name="',name,'" value="',(1⊃pars),'"'
∇
∇ r←name RadioButton pars
⍝ pars: checked [value [attributes]]
pars←pars,(⍴,pars)↓0 name''
r←Tag'input ',(3⊃pars),' type="radio" id="',name,'" name="',name,'" value="',(2⊃pars),'"',(0≠1⊃pars)/' checked'
∇
∇ r←{name}Table pars;x;data;atts;tdc;tda;thc;tha;hdrrows;z;mask
⍝ pars: data table_atts cell_attribs header_attribs header_rows
:If 0=⎕NC'name' ⋄ name←'' ⋄ :EndIf
:If 2=⍴⍴pars ⋄ pars←,⊂pars ⋄ :EndIf ⍝ Matrix of data only
pars←pars,(⍴,pars)↓(1 1⍴⊂'data')'' '' ''⍬
data atts tda tha hdrrows←pars ⋄ hdrrows←,hdrrows
x←⍕¨data
r←(⊂'