"Fossies" - the Fresh Open Source Software Archive

Member "Tahchee-1.0.0/Sources/tahchee/plugins/_kiwi/html2kiwi.py" (22 Oct 2009, 2473 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 "html2kiwi.py" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/env python
    2 # Encoding: iso-8859-1
    3 # -----------------------------------------------------------------------------
    4 # Project           :   Kiwi
    5 # -----------------------------------------------------------------------------
    6 # Author            :   Sebastien Pierre                 <sebastien@type-z.org>
    7 # -----------------------------------------------------------------------------
    8 # Creation date     :   06-Mar-2006
    9 # Last mod.         :   06-Mar-2006
   10 # History           :
   11 #                       06-Mar-2006 First implementation
   12 #                       06-Mar-2006 First implementation
   13 #
   14 # Bugs              :
   15 #                       -
   16 # To do             :
   17 #                       -
   18 #
   19 
   20 import re, textwrap, xml.dom
   21 from templates import Processor
   22 
   23 # Text to HTML: http://bhaak.dyndns.org/vilistextum/screenshots.html
   24 # From <http://www.boddie.org.uk/python/HTML.html>
   25 from xml.dom.ext.reader import HtmlLib
   26 
   27 # We create the processor, register the rules and define the process variable
   28 processor      = Processor()
   29 
   30 #------------------------------------------------------------------------------
   31 #
   32 #  Actual element processing
   33 #
   34 #------------------------------------------------------------------------------
   35 
   36 def convertHTML(element):
   37     return process(element, "$(*)\n")
   38 
   39 def convertP(element):
   40     return "\n".join(textwrap.wrap(process(element, "$(*)"), 79)) + "\n\n"
   41 
   42 def convertPRE(element):
   43     res = "\n"
   44     for line in process(element, "$(*)").split("\n"):
   45         res += ">    %s\n" % (line)
   46     return res + "\n"
   47 
   48 def convertUL(element):
   49     res = ""
   50     for line in process(element, "$(*)").split("\n"):
   51         res += "  %s\n" % (line)
   52     return res + "\n\n"
   53 
   54 def convertLI(element):
   55     lines = process(element, "$(*)").split("\n")
   56     res = " * " + lines[0]
   57     for line in lines[1:]:
   58         res += "   %s\n" % (line)
   59     return res + "\n"
   60 
   61 def convertH1(element):
   62     res = process(element, "$(*)")
   63     return "\n" + res + "\n" + "=" * len(res) + "\n\n"
   64 
   65 def convertH2(element):
   66     res = process(element, "$(*)")
   67     return "\n" + res + "\n" + "-" * len(res) + "\n\n"
   68 
   69 
   70 name2functions = {}
   71 for symbol in filter(lambda x:x.startswith("convert"), dir()):
   72     name2functions[symbol] = eval(symbol)
   73 processor.register(name2functions)
   74 process = processor.process
   75 
   76 def convertDocument( text ):
   77     reader = HtmlLib.Reader()
   78     doc    = reader.fromString(text)
   79     return processor.generate(doc)
   80 
   81 if __name__ == "__main__":
   82     import sys
   83     fd = file(sys.argv[1], 'rt')
   84     print convertDocument(fd.read())
   85     fd.close()
   86 
   87 # EOF