"Fossies" - the Fresh Open Source Software Archive

Member "Tahchee-1.0.0/Sources/tahchee/plugins/markup.py" (17 Feb 2009, 2250 Bytes) of package /linux/privat/old/tahchee-1.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "markup.py" see the Fossies "Dox" file reference documentation.

    1 # vim: ts=4
    2 # -----------------------------------------------------------------------------
    3 # Project           :   Tahchee                      <http://www.ivy.fr/tachee>
    4 # -----------------------------------------------------------------------------
    5 # Author            :   Sebastien Pierre                     <sebastien@ivy.fr>
    6 # License           :   Revised BSD License
    7 # -----------------------------------------------------------------------------
    8 # Creation date     :   23-Mar-2006
    9 # Last mod.         :   26-Jul-2008
   10 # -----------------------------------------------------------------------------
   11 
   12 import os, sys, StringIO
   13 try:
   14     import kiwi.main as kiwi
   15 except ImportError:
   16     import _kiwi.main as kiwi
   17 
   18 NAME    = "kiwi"
   19 VERSION = None
   20 SUMMARY = "Kiwi markup to HTML conversion functions."
   21 
   22 class KiwiPlugin:
   23 
   24     def __init__( self, site ):
   25         self.site = site
   26 
   27     def name( self ): return NAME
   28     def summary( self ): return SUMMARY
   29     def version( self ): return VERSION
   30     def doc( self ): return __doc__
   31 
   32     def install( self, localdict ):
   33         localdict["kiwi"] = self
   34     
   35     def include( self, path ):
   36         if not path[0] == "/":
   37             path = self.site.pagesDir + "/" + path
   38         if not os.path.exists(path):
   39             self.site.error("Included file not found: "+ path)
   40         if kiwi:
   41             _, r = kiwi.run("-m --body-only " + path, noOutput=True)
   42             return r
   43         else:
   44             self.site.warn("Kiwi is not available, but you used the $site.kiwi function")
   45             self.site.info("You can get Kiwi from <http://www.ivy.fr/kiwi>")
   46             return path
   47 
   48     def process( self, text, level=0 ):
   49         """If Kiwi is available, the given text will be interpreted as Kiwi
   50         markup and HTML will be generated from it. If Kiwi is not available, a
   51         warning will be issued, and the text will be displayed as-is."""
   52         if kiwi:
   53             try:
   54                 s = StringIO.StringIO(text)
   55                 _, r = kiwi.run("-m --body-only --level=%s --" % (level), s, noOutput=True)
   56                 s.close()
   57                 return r
   58             except:
   59                 self.site.error("Can't process kiwi markup in file %s" % self.site.page)
   60                 raise
   61         else:
   62             self.site.warn("Kiwi is not available, but you used the $site.kiwi function")
   63             info("You can get Kiwi from <http://www.ivy.fr/kiwi>")
   64             return text
   65 
   66     def __call__( self, text, level=0 ):
   67         return self.process(text,level)
   68 
   69 # EOF