<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Modularizing</title><link>https://sourceforge.net/p/pretty-markup/wiki/Modularizing/</link><description>Recent changes to Modularizing</description><atom:link href="https://sourceforge.net/p/pretty-markup/wiki/Modularizing/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 14 May 2012 15:37:07 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/pretty-markup/wiki/Modularizing/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage Modularizing modified by OmniMark Code</title><link>https://sourceforge.net/p/pretty-markup/wiki/Modularizing/</link><description>&lt;pre&gt;--- v1 
+++ v2 
@@ -5,46 +5,49 @@
 
 If you want to keep your OmniMark scripts robust, the only way to scrap your boilerplate it to modularize it  away. Beginning with OmniMark 9.1, all the code we have seen so far has been packaged in two reusable library  modules shipped with OmniMark: `omxmlwrite.xmd` and `beta/omsgmlwrite.xmd`. The interface for the former library  is described in the [OmniMark  documentation](http://developers.omnimark.com/login/docs/html/library/129.htm). A typical  use would look somewhat like this:  
 
-    import "omxmlwrite.xmd" prefixed by xml.
-    
-    process
-       do xml-parse scan #main-input
-          output xml.written from "%c"
-       done
-      
-
-
+&lt;div class="codehilite"&gt;&lt;pre&gt;
+&lt;span class="kr"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"omxmlwrite.xmd"&lt;/span&gt; &lt;span class="kr"&gt;prefixed&lt;/span&gt; &lt;span class="kr"&gt;by&lt;/span&gt; xml.
+&amp;nbsp;
+&lt;span class="kr"&gt;process&lt;/span&gt;
+   &lt;span class="kr"&gt;do&lt;/span&gt; &lt;span class="kr"&gt;xml-parse&lt;/span&gt; &lt;span class="kr"&gt;scan&lt;/span&gt; &lt;span class="nb"&gt;#main-input&lt;/span&gt;
+      &lt;span class="kr"&gt;output&lt;/span&gt; xml.written &lt;span class="kr"&gt;from&lt;/span&gt; &lt;span class="s"&gt;"%c"&lt;/span&gt;
+   &lt;span class="kr"&gt;done&lt;/span&gt;
+  
+&lt;/pre&gt;&lt;/div&gt;
+
 There is a catch, however: your rules that used to output XML markup now need to emit markup events instead. So  rather than something like this:  
 
-    element #implied
-       output "&lt;%q"
-       repeat over specified attributes as a
-          output " " || key of attribute a || "=%"" || attribute a || "%""
-       again
-       output "&gt;%c&lt;/%q&gt;"
-    
-    element "graphical-object"
-       output "&lt;figure&gt;&lt;image href=%"%v(object-location)%"/&gt;%c&lt;/figure&gt;"
-
+&lt;div class="codehilite"&gt;&lt;pre&gt;
+&lt;span class="kr"&gt;element&lt;/span&gt; &lt;span class="nb"&gt;#implied&lt;/span&gt;
+   &lt;span class="kr"&gt;output&lt;/span&gt; &lt;span class="s"&gt;"&amp;lt;%q"&lt;/span&gt;
+   &lt;span class="kr"&gt;repeat&lt;/span&gt; &lt;span class="kr"&gt;over&lt;/span&gt; &lt;span class="kr"&gt;specified&lt;/span&gt; &lt;span class="kr"&gt;attributes&lt;/span&gt; &lt;span class="kr"&gt;as&lt;/span&gt; a
+      &lt;span class="kr"&gt;output&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kr"&gt;key&lt;/span&gt; &lt;span class="kr"&gt;of&lt;/span&gt; &lt;span class="kr"&gt;attribute&lt;/span&gt; a &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s"&gt;"=%""&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kr"&gt;attribute&lt;/span&gt; a &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s"&gt;"%""&lt;/span&gt;
+   &lt;span class="kr"&gt;again&lt;/span&gt;
+   &lt;span class="kr"&gt;output&lt;/span&gt; &lt;span class="s"&gt;"&gt;%c&amp;lt;/%q&gt;"&lt;/span&gt;
+&amp;nbsp;
+&lt;span class="kr"&gt;element&lt;/span&gt; &lt;span class="s"&gt;"graphical-object"&lt;/span&gt;
+   &lt;span class="kr"&gt;output&lt;/span&gt; &lt;span class="s"&gt;"&amp;lt;figure&gt;&amp;lt;image href=%"%v(object-location)%"/&gt;%c&amp;lt;/figure&gt;"&lt;/span&gt;
+&lt;/pre&gt;&lt;/div&gt;
 
 your rules should look like this:   
 
-    element #implied
-       signal throw #markup-start #current-markup-event
-       output "%c"
-       signal throw #markup-end #current-markup-event
-    
-    element "graphical-object"
-       local markup-element-event figure initial { create-element-event (declared-elements of target-dtd){"figure"} }
-       local markup-element-event image  initial { create-element-event (declared-elements of target-dtd){"image"}
-                                                             attributes { attribute "object-location" with key "href" } }
-    
-       signal throw #markup-start figure
-       signal throw #markup-start image
-       signal throw #markup-end image
-       output "%c"
-       signal throw #markup-end figure
-
+&lt;div class="codehilite"&gt;&lt;pre&gt;
+&lt;span class="kr"&gt;element&lt;/span&gt; &lt;span class="nb"&gt;#implied&lt;/span&gt;
+   &lt;span class="kr"&gt;signal&lt;/span&gt; &lt;span class="kr"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;#markup-start&lt;/span&gt; &lt;span class="nb"&gt;#current-markup-event&lt;/span&gt;
+   &lt;span class="kr"&gt;output&lt;/span&gt; &lt;span class="s"&gt;"%c"&lt;/span&gt;
+   &lt;span class="kr"&gt;signal&lt;/span&gt; &lt;span class="kr"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;#markup-end&lt;/span&gt; &lt;span class="nb"&gt;#current-markup-event&lt;/span&gt;
+&amp;nbsp;
+&lt;span class="kr"&gt;element&lt;/span&gt; &lt;span class="s"&gt;"graphical-object"&lt;/span&gt;
+   &lt;span class="kr"&gt;local&lt;/span&gt; markup-element-event figure &lt;span class="kr"&gt;initial&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kr"&gt;create-element-event&lt;/span&gt; (&lt;span class="kr"&gt;declared-elements&lt;/span&gt; &lt;span class="kr"&gt;of&lt;/span&gt; target-dtd)&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"figure"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
+   &lt;span class="kr"&gt;local&lt;/span&gt; markup-element-event image  &lt;span class="kr"&gt;initial&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kr"&gt;create-element-event&lt;/span&gt; (&lt;span class="kr"&gt;declared-elements&lt;/span&gt; &lt;span class="kr"&gt;of&lt;/span&gt; target-dtd)&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"image"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
+                                                         &lt;span class="kr"&gt;attributes&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kr"&gt;attribute&lt;/span&gt; &lt;span class="s"&gt;"object-location"&lt;/span&gt; &lt;span class="kr"&gt;with&lt;/span&gt; &lt;span class="kr"&gt;key&lt;/span&gt; &lt;span class="s"&gt;"href"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
+&amp;nbsp;
+   &lt;span class="kr"&gt;signal&lt;/span&gt; &lt;span class="kr"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;#markup-start&lt;/span&gt; figure
+   &lt;span class="kr"&gt;signal&lt;/span&gt; &lt;span class="kr"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;#markup-start&lt;/span&gt; image
+   &lt;span class="kr"&gt;signal&lt;/span&gt; &lt;span class="kr"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;#markup-end&lt;/span&gt; image
+   &lt;span class="kr"&gt;output&lt;/span&gt; &lt;span class="s"&gt;"%c"&lt;/span&gt;
+   &lt;span class="kr"&gt;signal&lt;/span&gt; &lt;span class="kr"&gt;throw&lt;/span&gt; &lt;span class="nb"&gt;#markup-end&lt;/span&gt; figure
+&lt;/pre&gt;&lt;/div&gt;
 
 Besides the ability to use the `omxmlwrite` library and get rid of the boilerplate, this style of coding has the  benefit of easy pipeline construction, but you can find more on that topic  [elsewhere](http://developers.omnimark.com/markup-pipelines.html). 
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">OmniMark Code</dc:creator><pubDate>Mon, 14 May 2012 15:37:07 -0000</pubDate><guid>https://sourceforge.net9689f64f68a2be58fac6cfe169c682312b3ecb74</guid></item><item><title>WikiPage Modularizing modified by OmniMark Code</title><link>https://sourceforge.net/p/pretty-markup/wiki/Modularizing/</link><description>Modularizing 
=============

You may be wondering at this point if every OmniMark program that outputs SGML or XML markup really has to  contain over fifty lines of boilerplate code. Of course it doesn't. You may not want the processing instructions  and comments from the input reproduced in the output. And perhaps your input markup never contains any escaped  newline characters in attribute values. On the other hand, maybe you just haven't encountered them yet.  

If you want to keep your OmniMark scripts robust, the only way to scrap your boilerplate it to modularize it  away. Beginning with OmniMark 9.1, all the code we have seen so far has been packaged in two reusable library  modules shipped with OmniMark: `omxmlwrite.xmd` and `beta/omsgmlwrite.xmd`. The interface for the former library  is described in the [OmniMark  documentation](http://developers.omnimark.com/login/docs/html/library/129.htm). A typical  use would look somewhat like this:  

    import "omxmlwrite.xmd" prefixed by xml.
    
    process
       do xml-parse scan #main-input
          output xml.written from "%c"
       done
      


There is a catch, however: your rules that used to output XML markup now need to emit markup events instead. So  rather than something like this:  

    element #implied
       output "&lt;%q"
       repeat over specified attributes as a
          output " " || key of attribute a || "=%"" || attribute a || "%""
       again
       output "&gt;%c&lt;/%q&gt;"
    
    element "graphical-object"
       output "&lt;figure&gt;&lt;image href=%"%v(object-location)%"/&gt;%c&lt;/figure&gt;"


your rules should look like this:   

    element #implied
       signal throw #markup-start #current-markup-event
       output "%c"
       signal throw #markup-end #current-markup-event
    
    element "graphical-object"
       local markup-element-event figure initial { create-element-event (declared-elements of target-dtd){"figure"} }
       local markup-element-event image  initial { create-element-event (declared-elements of target-dtd){"image"}
                                                             attributes { attribute "object-location" with key "href" } }
    
       signal throw #markup-start figure
       signal throw #markup-start image
       signal throw #markup-end image
       output "%c"
       signal throw #markup-end figure


Besides the ability to use the `omxmlwrite` library and get rid of the boilerplate, this style of coding has the  benefit of easy pipeline construction, but you can find more on that topic  [elsewhere](http://developers.omnimark.com/markup-pipelines.html). 

</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">OmniMark Code</dc:creator><pubDate>Fri, 11 May 2012 18:43:12 -0000</pubDate><guid>https://sourceforge.netf8f8c69f2e48792a255360aa5d15d9bcfcb0aa9e</guid></item></channel></rss>