Commits

dirkbaechle committed 9834a6c

- added improved support for URLs/ links/xrefs (Docbook style)
- updated manual

  • Participants
  • Parent commits 9a44d3a

Comments (0)

Files changed (2)

 
 == Current version == version
 
-~[[xmlwiko.zip xmlwiko]]||Archive with the Python script and the $$*.wiki$$
+~[[xmlwiko.zip xmlwiko]]||Archive with the Python script (v1.3) and the $$*.wiki$$
 source for this page.
 
 == Usage ==
 \blank@author: Whowrote This
 
 The markups for the text can be divided into the categories:
-sections, simple paragraphs, lists and environments.
+((sections)), ((para simple paragraphs)), ((links)), ((lists))
+and ((environments)).
 
 == Sections == sections
 
 because we want to add special attributes like %%vlink%% or %%width%%.
 First, let's have a look at the basic forms:
 
-~$$[\blank[href text]\blank]$$||Creates a link to the URL %%href%% with %%text%% as the link text.
+~$$[\blank[href text]\blank]$$||Creates a link to the external URL %%href%% with %%text%% as the link text.
+~$$(\blank(id text)\blank)$$||Creates a link within the document to the %%id%% with %%text%% as the link text.
+The %%id%% can point to a section or a defined anchor (see ((para Paragraphs))).
+~$$&&id text&&$$||Creates an xref entry to the %%id%% within the document. Although Docbook
+does not require a link %%text%% for this element, you have to provide a fallback for the
+Forrest output.
 ~$$<<href>>$$||Places an %%img%% tag (or $$inlinemediaobject$$) for the image %%href%% at the current position.
 ~$$Figure:$$||A \\figure\\ is an image that stands on its own line, it can have a title and is specified
 like an environment.</p>
 <p>While the $$href$$ is mandatory, you can leave out the title. This results in a simple image without any description
 (a.k.a $$mediaobject$$ in Docbook).
 
-Now when you want to give some special attributes to these three tags, you can split the $$text$$ for the link and the
-$$href$$ for the images into two parts by a %%||%%. The first part is recognized as list of attributes then, while the
-rest is used as text or link to the actual image.
+Now when you want to give some special attributes to these five tags, you can split the $$text$$ for the link/xref and the
+$$href$$ for the images into two parts by a %%||%%. Like this, the first token is always recognized as 
+the link target (or image source). Then, the list of optional attributes follow
+and the link text is found at the end of the expression.
 
 Some examples:
 
 Code:
 [[index.html vlink="#C0C0C0"||Visit this page!]]
 &lt;&lt;test.png||alt="test" width="80%">>
+((examples xrefstyle="template: the examples in ch. %n"||the examples))
 Figure: er2.png||alt="er2" width="100%"
 The parallel computer ER2.
 
 
 Note:
 When using the $$Code$$ environment, you still have to escape the %%&lt;%%
-as %%&amp;lt;%%!
+as %%&amp;lt;%% and the %%&amp;%% as %%&amp;amp;%%!
 
 == Special stuff ==
 
 # this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 """
-xmlwiko v1.2: This script generates XML files as input to ApacheForrest or Docbook from Wiki like input.
+xmlwiko v1.3: This script generates XML files as input to ApacheForrest or Docbook from Wiki like input.
               Inspired by WiKo (the WikiCompiler, http://wiko.sf.net) it tries to simplify
               the setup and editing of web pages (for Forrest) or simple manuals and descriptions (Docbook).
 """
 import os.path
 import re
 import sys
-import subprocess
-import urllib
 import codecs
 
 def processVerbatim(txt, language):
 code = re.compile(r"\$\$([^\$]*)\$\$")
 quotedcode = re.compile(r"%%([^\%]*)%%")
 url = re.compile(r"\[\[([^\s]*)\s+([^\]]*)\]\]")
+xref = re.compile(r"&&([^\s]*)\s+([^&]*)&&")
+link = re.compile(r"\(\(([^\s]*)\s+([^\)]*)\)\)")
+urls = re.compile(r"\[\[([^\s]*?)\]\]")
+links = re.compile(r"\(\(([^\s]*?)\)\)")
 anchor = re.compile(r"@@([^@]*)@@")
 img = re.compile(r"<<([^>]*)>>")
 
               'quote' : ['&quot;', '&quot;'],
               'code' : ['<code>', '</code>'],
               'quotedcode' : ['&quot;<code>', '</code>&quot;'],
-              'anchor' : ['<a id="', '"/>']}
+              'anchor' : ['<anchor id="', '"/>']}
 dictTagsForrest = {'ulink' : '<a href="%(url)s"%(atts)s>%(linktext)s</a>',
+                   'link' : '<a href="#%(url)s">%(linktext)s</a>',
+                   'xref' : '<a href="#%(url)s">%(linktext)s</a>',
                    'inlinemediaobject' : '<img src="%(fref)s"%(atts)s/>',
                    'mediaobject' : '<figure src="%(fref)s"%(atts)s/>',
                    'figure' : '<figure src="%(fref)s"%(atts)s/><p><strong>Figure</strong>: %(title)s</p>'
 envTagsDocbook = {
            'Section' : ['<section id="%(id)s"><title>%(title)s</title>', '</section>', True],
            'Para' : ['<para>', '</para>', False],
-           'Code' : ['<screen xml:space="preserve">', '</screen>', False],
+           'Code' : ['<screen>', '</screen>', False],
            'Figure' : ['', '', False],
            'Abstract' : ['<abstract>', '</abstract>', True],
            'Remark'  : ['<remark>', '</remark>', True],
 listTagsDocbook = {'#' : ['<orderedlist>', '</orderedlist>'],
             '*' : ['<itemizedlist>', '</itemizedlist>'],
             '~' : ['<variablelist>', '</variablelist>'],
-            'olItem' : ['<listitem>', '</listitem>'],
-            'ulItem' : ['<listitem>', '</listitem>'],
+            'olItem' : ['<listitem><para>', '</para></listitem>'],
+            'ulItem' : ['<listitem><para>', '</para></listitem>'],
             'dtItem' : ['<varlistentry><term>', '</term>'],
-            'ddItem' : ['<listitem>', '</listitem></varlistentry>'],
+            'ddItem' : ['<listitem><para>', '</para></listitem></varlistentry>'],
            }
 inlineTagsDocbook = {'em' : ['<emphasis>', '</emphasis>'],
               'strong' : ['<emphasis role="bold">', '</emphasis>'],
               'quote' : ['<quote>', '</quote>'],
-              'code' : ['<code>', '</code>'],
-              'quotedcode' : ['<quote><code>', '</code></quote>'],
-              'anchor' : ['<a id="', '"/>']}
-dictTagsDocbook = {'ulink' : '<ulink url="%(url)s">%(linktext)s</ulink>',
+              'code' : ['<literal>', '</literal>'],
+              'quotedcode' : ['<quote><literal>', '</literal></quote>'],
+              'anchor' : ['<anchor id="', '"/>']}
+dictTagsDocbook = {'ulink' : '<ulink url="%(url)s"%(atts)s>%(linktext)s</ulink>',
+                   'link' : '<link linkend="%(url)s"%(atts)s>%(linktext)s</link>',
+                   'xref' : '<xref linkend="%(url)s"%(atts)s/>',
                    'inlinemediaobject' : '<inlinemediaobject><imageobject><imagedata fileref="%(fref)s"%(atts)s/></imageobject></inlinemediaobject>',
                    'mediaobject' : '<mediaobject><imageobject><imagedata fileref="%(fileref)s"%(atts)s/></imageobject></mediaobject>',
                    'figure' : '<figure><title>%(title)s</title><mediaobject><imageobject><imagedata fileref="%(fref)s"%(atts)s/></imageobject></mediaobject></figure>'
                     sectionTitle = headerMatch.group(2).rstrip()
                     sectionId = headerMatch.group(3)
                     if sectionId.strip() == "":
-                        sectionId = '_'.join([f.lower() for f in sectionTitle.split()])
+                        sectionId = '_'.join([f.lower().strip('"') for f in sectionTitle.split()])
         
         # Step 2: Close old envs, based on block type and current indents
         if blockType == "Section":
         # Step 6: Add text to result
         self.result += text
 
+    def replaceLinks(self, text, rex, tkey):
+        lMatch = rex.search(text)
+        while lMatch:
+            href = lMatch.group(1)
+            atxt = lMatch.group(2)
+            urlatts = ""
+            seppos = atxt.find("||")
+            if seppos > 0:
+                urlatts = ' '+atxt[:seppos]
+                atxt = atxt[seppos+2:]
+            text = (text[:lMatch.start()] + 
+                    self.dictTags[tkey] % {'url' : href,
+                                           'atts' : urlatts,
+                                           'linktext' : atxt} + 
+                    text[lMatch.end():])
+            lMatch = rex.search(text)
+            
+        return text
+
+    def replaceSimpleLinks(self, text, rex, tkey):
+        lMatch = rex.search(text)
+        while lMatch:
+            href = lMatch.group(1)
+            atxt = href
+            urlatts = ""
+            text = (text[:lMatch.start()] + 
+                    self.dictTags[tkey] % {'url' : href,
+                                           'atts' : urlatts,
+                                           'linktext' : atxt} + 
+                    text[lMatch.end():])
+            lMatch = rex.search(text)
+        
+        return text
+
     def replaceAll(self, text, regex, starttag, endtag):
         match = regex.search(text)
         while match:
                 
             iMatch = img.search(text)
         
-        # Find and replace URLs
-        uMatch = url.search(text)
-        while uMatch:
-            href = uMatch.group(1)
-            atxt = uMatch.group(2)
-            urlatts = ""
-            seppos = atxt.find("||")
-            if seppos > 0:
-                urlatts = ' '+atxt[:seppos]
-                atxt = atxt[seppos+2:]
-            text = (text[:uMatch.start()] + 
-                    self.dictTags['ulink'] % {'url' : href,
-                                              'atts' : urlatts,
-                                              'linktext' : atxt} + 
-                    text[uMatch.end():])
-            uMatch = url.search(text)
-                    
+        # Find and replace link tags
+        text = self.replaceSimpleLinks(text, urls, 'ulink')
+        text = self.replaceSimpleLinks(text, links, 'link')
+        text = self.replaceLinks(text, url, 'ulink')
+        text = self.replaceLinks(text, xref, 'xref')
+        text = self.replaceLinks(text, link, 'link')
+                        
         # Apply non-greedy inline substitutions to the joined block
         text = self.replaceAll(text, em, self.inlineTags["em"][0], self.inlineTags["em"][1])
         text = self.replaceAll(text, strong, self.inlineTags["strong"][0], self.inlineTags["strong"][1])