APLCode2HTML
Contents
APLCode2HTML is part of the CategoryAplTree project.
Overview
Goal is to markup up HTML code in order to present that APL code properly. Depending on the circumstances either HTML snippets are returned (suitable for inserting them into an HTML page) or a fully-fledged HTML page with embedded CSS styles suitable as a stand-alone web page.
This goal can be achieved in two different ways:
By calling a shared method of the APLCode2HTML class which returns HTML code.
- Creating an instance of the class.
The function is very easy to use but naturally you must live with the defaults.
Using the shared method is easy and straightforward, but you have to live with the default settings. Instantiating the class is more complex but also more flexible: it comes with many properties and a number of methods which should allow you to make the HTML page look as you like it.
Note that the APL code will show up properly only if you have installed one of "APL385 Unicode", "APLX Upright" or "APL2 Unicode".
The shared method PrepareCodeForHtml
The right argument
Depending on the the right argument PrepareCodeForHtml is doing different things:
A string
A simple string is treated as the name of a function or operator or script. HTML code is returned as a (shy!) result. The HTML code is a snipped (just a <pre> tag actually) that can be inserted into any ordinary HTML page.
Example:
Prim←{{⍵/⍨2=+⌿0=⍵∘.|⍵}⍳⍵}
⎕←APLCode2HTML.PrepareCodeForHtml 'Prim'
<pre id="apl" style="font-family:'APL385 Unicode', 'APLX Upright', 'APL2 Unicode'; font-size: medium;"
∇ Prim←{{⍵/⍨2=+⌿0=⍵∘.|⍵}⍳⍵}
∇
</pre>
A vector of strings
A vector of strings is treated as APL code, so every item in the vector ends up as a line in the resulting <pre> code.
Example:
v←⊂'Prim←{{⍵/⍨2=+⌿0=⍵∘.|⍵}⍳⍵}'
v,←⊂'{{⍵/⍨2=+⌿0=⍵∘.|⍵}⍳⍵}⍳100'
⎕←APLCode2HTML.PrepareCodeForHtml v
<pre id="apl" style="font-family:'APL385 Unicode', 'APLX Upright', 'APL2 Unicode'; font-size: medium;"
Prim←{{⍵/⍨2=+⌿0=⍵∘.|⍵}⍳⍵}
{{⍵/⍨2=+⌿0=⍵∘.|⍵}⍳⍵}⍳100
</pre>
Empty vector
In case the right argument is empty, the contents of the clipboard is taken. The result is written back to the clipboard except when a left argument was specified.
The left argument
If a left argument is given this is treated as a file name. In this case the function always produces a fully-fledged HTML page.
Instantiating APLCode2Html
Generally instantiating the class has the same purpose as the shared method PrepareCodeForHtml. However, after creating an instance of the class you can set a number of properties.
This gives you much more flexibility. Here is an example that sets all properties and calls all the methods available:
MyHtml←⎕NEW #.APLCode2Html
MyHtml.title←'Simple line of code'
MyHtml.aplFonts←'APL385 Unicode'
MyHtml.printAplFontSize←20
MyHtml.backgroundColor←'Silver'
MyHtml.textFonts←'Georgia'
MyHtml.textFontSize←20
MyHtml.printTextFontSize←14
MyHtml.AddHeader 1 'APLCode2Html Example: the class'
tx←''
tx,←⊂'This function makes use of all the properties and methods available when instantiating the class "APL2CodeHtml2".'
tx,←⊂'It then reads the resulting HTML page and compares it''s code with what what we expect to see.'
MyHtml.AddText tx
MyHtml.AddHeader 2 'Header level 2'
MyHtml.AddHeader 3 'Header level 3'
MyHtml.AddHeader 4 'Header level 4'
MyHtml.AddHeader 5 'Header level 5'
MyHtml.AddHeader 6 'Header level 6'
MyHtml.AddHeader 2 'Example for "AddCode"'
MyHtml.AddCode'Prim←{⍵/⍨{2=+⌿0=⍵∘.|⍵}⍳⍵}'
MyHtml.AddHeader 2 'Example for "AddBody"'
MyHtml.AddBody'Prim'
MyHtml.AddHeader 2 'Example for "AddScript"'
MyHtml.AddScript #.SampleClass
MyHtml.AddHeader 2 'Example for adding code via the clipboard'
'cl'⎕WC'Clipboard'
cl.Text←⎕VR'Between'
MyHtml.AddClipboard
MyHtml.AddHeader 3 'Copyright'
MyHtml.AddText'Author: Kai Jaeger * APL Team Ltd * http://aplteam.com'
filename←'APLCode2HTMLTest.html'
MyHtml.WriteHtml2File filenameThat's how the result looks like: The HTML page
Project Page
For bug reports, future enhancements and a full version history see APLCode2HTML/ProjectPage.
Version Information
Original author: |
|
Responsible: |
|
Email: |
APLTree downloads
Whether you are interested in ...
- the latest stable version or...
- any older version or...
- the full project including development stuff and test cases or...
- the current development trunk, again with development stuff and test cases...
... all downloads are available at http://download.aplwiki.com/apltree
APL Wiki