Commits

dirkbaechle committed 9a44d3a

Version v1.2: First officially released version.

  • Participants
  • Parent commits 9889bd3

Comments (0)

Files changed (2)

 @author: Dirk Baechle
 @title: xmlwiko
 
-Fundamentally lazy, I always try to minimize work...even when
+Fundamentally lazy, I always try to minimize my efforts to get work done...even when
 editing homepages. So when I planned to rewrite this site, I did not want
-to fiddle with ApacheForrest XML allday long. Inspired by [[http://wiko.sf.net
+to fiddle with ApacheForrest XML the whole day. Instead, inspired by [[http://wiko.sf.net
 WiKo (the Wiki Compiler)]] I hacked together this little script.
 
 It is not pretty, nor complete...but it does a good job in keeping me
 
 == Basics == basic
 
-An xmlwiko file ($$*.wiki$$) consists of text blocks. These blocks
+An xmlwiko file ($$*.wiki$$) is an UTF8 encoded file that consists of text blocks. These blocks
 are separated by one or more blank lines (2+ newlines). A text block itself
-does not contain blank lines.
+can not contain blank lines.
 
 At the start of each file you should place a header with the %%title%%
 and %%author%% variables as follows:
 
 Code:
-@title: Title of the document
-@author: Whowrote This
+\blank@title: Title of the document
+\blank@author: Whowrote This
 
 The markups for the text can be divided into the categories:
 sections, simple paragraphs, lists and environments.
 Emphasis (em)
 
 Code:
-This is an //emphasis//.
+This is an \\emphasis\\.
 
 Bold (strong)
 
 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.
-~$$$$||
-We might need to give
-HTML link
+~$$<<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>
+<source xml:space="preserve">
+Figure: href
+Title/description of the figure.
+</source>
+<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.
+
+Some examples:
 
 Code:
-[[URL text]]
-
-
-Images
-
-Code:
-&lt;&lt;URL>>
-or
-&lt;&lt;URL||alt="alt" name="" width=""...>>
-
-
+[[index.html vlink="#C0C0C0"||Visit this page!]]
+&lt;&lt;test.png||alt="test" width="80%">>
+Figure: er2.png||alt="er2" width="100%"
+The parallel computer ER2.
 
 
 == Lists ==
 
 You may wonder why all the markers for environments are doubled up. The reason behind
 this is, that we might want to print a ''%\blank%'' in the middle of our text
-(uh, oh...there it happened already).
+(uh, oh...there it happened already). And if there is a real %%quoted%% environment in the same text block, the script gets confused easily.
 
-For this case the %%\bl\blankank%% marker was introduced as a special ''escape sequence''.
+For this case, the %%\bl\blankank%% marker was introduced as a special ''escape sequence''.
 It gets replaced with a string of zero length for the final output (after
 all other processing work was done).
 
 So if you want a  ''%\blank%'' in your text you can type:
 
 Code:
-''%\blank%''
+''%\bl\blankank%''
 
 Final question: ''What do you have to type in order to get %%\bl\blankank%% in
-the output?'' $$;-)$$
+the output?'' $$:)$$
 
 # this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 """
-xmlwiko v1.1: This script generates XML files as input to ApacheForrest or Docbook from Wiki like input.
+xmlwiko v1.2: 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).
 """
 header = re.compile(r"^==(\+|-*|-?[0-9]+)\s*([^=]+)\s*=*\s*(.*)$")
 
 # Regular expressions
-em = re.compile(r"//([^/]*)//")
+em = re.compile(r"\\\\([^\\]*)\\\\")
 strong = re.compile(r"!!([^!]*)!!")
 quote = re.compile(r"''([^']*)''")
 code = re.compile(r"\$\$([^\$]*)\$\$")
             if listMatch and listMatch.start() == 0:
                 blockType = "List"
             else:
-                varMatch = var.match(text)
-                if varMatch and varMatch.start() == 0:
-                    blockType = "Var"
-                    for l in block:
-                        varMatch = var.match(l)
-                        if varMatch:
-                            self.vars[varMatch.group(1)] = varMatch.group(2)
-                    return
-                else:
-                    # Is it a section header?
-                    headerMatch = header.match(block[0])
-                    if headerMatch and headerMatch.start() == 0:
-                        blockType = "Section"
-                        addIndent = headerMatch.group(1)
-                        sectionTitle = headerMatch.group(2).rstrip()
-                        sectionId = headerMatch.group(3)
-                        if sectionId.strip() == "":
-                            sectionId = '_'.join([f.lower() for f in sectionTitle.split()])
+                # Is it a section header?
+                headerMatch = header.match(block[0])
+                if headerMatch and headerMatch.start() == 0:
+                    blockType = "Section"
+                    addIndent = headerMatch.group(1)
+                    sectionTitle = headerMatch.group(2).rstrip()
+                    sectionId = headerMatch.group(3)
+                    if sectionId.strip() == "":
+                        sectionId = '_'.join([f.lower() for f in sectionTitle.split()])
         
         # Step 2: Close old envs, based on block type and current indents
         if blockType == "Section":
         if blockType == "Section":
             self.openBlocks.append('Section')
             self.sectionIndent += 1
-            self.result += "%s\n" % (self.envTags['Section'][0] % {'title':sectionTitle, 'id':sectionId})
+            text = "%s\n" % (self.envTags['Section'][0] % {'title':sectionTitle, 'id':sectionId})
+            self.result += self.inlineReplace(text)
             return
         
         # Step 4: Process block=
         # Step 4b: Replace inline expressions
         if blockType != "Code":
             text = self.inlineReplace(text)
-
+        else:
+            # Replace \blank escape sequences
+            text = text.replace("\\blank","")
+            
         # Step 5: Wrap block in environment tags
         if envStarted:
             text = "%s\n%s" % (self.envTags[self.currentEnvironment][0],text)
         return text
         
     def inlineReplace(self, 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 images
         iMatch = img.search(text)
         while iMatch:
                 
             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)
+                    
         # 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])