REBOL [ Library: [ level: 'advanced platform: 'all type: [function module] domain: [html markup text text-processing] tested-under: none support: none license: 'mit see-also: none ] Title: "Qtask Markup Language - XHTML emitter" File: %xhtml-emitter.r Purpose: { This program implements a QML to XHTML converter. The input is a QML document tree (from the QML parser), and the output is XHTML text. } Author: "Gabriele Santilli" EMail: giesse@rebol.it License: { Copyright (c) 2006-2007 Prolific Publishing, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } Date: 18-Jan-2007 Version: 2.19.1 History: [ 17-Feb-2006 1.1.0 "History start" 22-Feb-2006 1.2.0 {Fixed problem with closing block commands inside paragraphs} 13-Mar-2006 1.3.0 {Now assumes output from 2-pass scanner (simplified a lot of states)} 13-Mar-2006 1.4.0 "Added handling for default argument name" 14-Mar-2006 1.5.0 "Changed =TOC" 15-Mar-2006 1.6.0 "Minor change to =example" 15-Mar-2006 1.7.0 "Changed default handling for =image" 17-Mar-2006 1.8.0 "New handling of newlines" 18-Mar-2006 1.9.0 {Numbered items are now numbered sequentially regardless of where they happen} 18-Mar-2006 1.10.0 "Added TOC linking" 18-Mar-2006 1.11.0 {Cells are now replaced instead of appended to; row 1 defaults to header} 18-Mar-2006 1.12.0 "Added args handling for =row and =column" 18-Mar-2006 1.13.0 "Changed box options" 18-Mar-2006 1.14.0 "Added = as comment, changed =1* to =1' etc." 18-Mar-2006 1.15.0 "Now =link does internal (Qwiki) links too" 18-Mar-2006 1.16.0 "Fixed a bug in table nesting" 20-Mar-2006 1.17.0 "Changed lists inside tables" 21-Mar-2006 1.18.0 "Changed =box, image is now aligned instead of text" 23-Mar-2006 1.19.0 "Changed =cell handling" 24-Mar-2006 1.20.0 "All empty cells are now shown in tables" 27-Mar-2006 1.21.0 "Changed command arguments handling" 27-Mar-2006 1.22.0 "Removed comment handling" 29-Mar-2006 1.23.0 {Minor changes to options handling, also now =box[float boxleft] is possible} 29-Mar-2006 1.24.0 {=cell, =row and =column can overwrite a previous one and merge the style} 29-Mar-2006 1.25.0 "Split =c and =center into two separate commands" 29-Mar-2006 1.26.0 "Newline eating moved to scanner" 30-Mar-2006 1.27.1 "Added position to table" 30-Mar-2006 1.28.1 "Added =left, =right, =l, =r" 30-Mar-2006 1.29.1 "Added =span and support for it in table handling" 1-Apr-2006 1.30.1 "Added =justify and =j" 5-Apr-2006 1.31.1 "Now =span moves the cursor" 5-Apr-2006 1.32.1 "No more in tables by default" 5-Apr-2006 1.33.1 "Added rounded and shadow to table" 5-Apr-2006 1.34.1 "Fixed =span=cell case" 5-Apr-2006 1.35.1 "Now =span breaks up previous overlapping spans" 5-Apr-2006 1.36.1 "Another fix for =span=cell and fixed =span=span" 5-Apr-2006 1.37.1 {Allows any arg order for =span, also fixes breaking span to single cells} 6-Apr-2006 1.38.1 {Fixed a few table bugs, improved handling of overlapping spans style} 6-Apr-2006 1.39.1 "Implemented style inheritance in table" 6-Apr-2006 1.40.1 "Fixed =span=column and =span=row bug" 6-Apr-2006 1.41.1 "Fixed bug in end-table" 13-Apr-2006 1.42.1 "Fixed a bug with money! (width/height in percents)" 18-Apr-2006 1.43.1 "Added default options for commands" 18-Apr-2006 1.44.1 "Added section numbering" 18-Apr-2006 1.45.1 "Added checklists" 21-Apr-2006 1.46.1 "Added =s and =u" 21-Apr-2006 1.47.1 "Changed =toc output" 21-Apr-2006 1.48.1 "Added support for =toc font style" 21-Apr-2006 1.49.1 "Added support for header numbers font style" 21-Apr-2006 1.50.1 "Fixed a bug with =box in =table" 22-Apr-2006 1.51.1 {Fixed a bug with unintentionally altering the default-* objects (added /copy to merge-style)} 22-Apr-2006 1.52.1 "Added =font[space]" 22-Apr-2006 1.53.1 {Added many changes from Ammon for better Qtask integration} 22-Apr-2006 1.54.1 "Added non-css color names" 24-Apr-2006 1.55.1 "Added =column. and =row." 24-Apr-2006 1.56.1 "New =image (now inline)" 24-Apr-2006 1.57.1 {Added =4, =5 and =6, changed numbering to support them} 27-Apr-2006 1.58.1 "Added initial support for =anchor" 28-Apr-2006 1.59.1 "Finished =anchor support" 28-Apr-2006 1.60.1 "=: now emits a table" 28-Apr-2006 1.61.1 {If a =box has only the header, then it is not a header} 16-May-2006 2.1.0 "Rewriting from scratch, for the new parser" 17-May-2006 2.2.0 "Added emitting unknown commands as text" 18-May-2006 2.3.0 "Initial toc support" 19-May-2006 2.4.0 "Finished toc, added 'alink" 19-May-2006 2.5.0 "Options support for bullets and enums" 20-May-2006 2.6.0 "Added options rendering for all nodes" 24-May-2006 2.7.0 "Fixed header styling" 25-May-2006 2.8.0 "Support for =table[space]" 25-May-2006 2.9.1 "Fixed =>" 29-May-2006 2.10.1 "Added boxes" 7-Jun-2006 2.11.1 "Fixed make-style with empty opts" 16-Jun-2006 2.12.1 "Changed options for =image" 16-Jun-2006 2.13.1 "Links now emit a class too" 29-Jun-2006 2.14.1 "Fixed crash with options* being none in some cases" 21-Jul-2006 2.15.1 "Fixed bug with =table[borderless]" 21-Aug-2006 2.16.1 "First public release (with rel. 2.0i of QML)" 23-Nov-2006 2.17.1 "Merged changes from Qtask" 22-Dec-2006 2.18.1 "Reduced size of indent for =>" 18-Jan-2007 2.19.1 {Changed HTML escaping: now assumes UTF-8 source text, and emits HTML-encoded ASCII} ] ] xhtml-emitter: context [ out: none qml-rule: ['qml some block-level] block-level: [ into [ 'para opts (emit [""]) [some inline-level | (emit " ")] (emit
) | 'hrule to end (emit
) | ['header1 | 'header1*] opts (emit-header 1 options options*) any inline-level (emit ) | ['header2 | 'header2*] opts (emit-header 2 options options*) any inline-level (emit ) | ['header3 | 'header3*] opts (emit-header 3 options options*) any inline-level (emit ) | 'header4 opts (emit-header 4 options options*) any inline-level (emit ) | 'header5 opts (emit-header 5 options options*) any inline-level (emit ) | 'header6 opts (emit-header 6 options options*) any inline-level (emit ) | 'bullets (emit
})
opt [into ['title opts (emit [""]) any inline-level (emit)]] (emit
|
}) string! set val string! (emit-encoded val emit "
=" emit-encoded val/1 if val/2 [ emit "[" emit-encoded mold/only val/2 emit "]" ] emit
) ] | error ] emit: func [value] [ repend out value ] emit-encoded: func [string] [ encode-entities out string ] val: none emit-header: func [level style opts] [ emit ["{ | " ] parse box/contents box-rule emit [ | |
{ | " ] parse box/contents box-rule emit [ | |
{ | " ] parse box/contents box-rule emit [ | |
{ | " ] parse box/contents box-rule emit [ | |
"] ) any inline-level (emit
) ] [into ['bullets (emit"]) any inline-level (emit
)] [into ['bullets (emit" ]) any inline-level (emit "