#! /usr/bin/env python # This software carries the following license: # # Modified BSD license # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Steinar Knutsen """htmltrans.py 0.1 Generates nested definition lists in HTML based on documents indenting. (Tabs only.) An empty line ends all lists, a line correctly indented with tabs, but containing only space will insert a
without affecting the list structure. The first line of the source document is taken to be a title, the second line is ignored. Lines starting with '*' (or with a number of tabs before) is assumed to an item in an unordered list. Words surrounded by '_' are assumed to be emphasized. The code has more than its share of sillinesses. """ import re, string class translator: tabcounter = re.compile(r"^(\t*)") def __init__(self, plaintext): self.plaintext = plaintext self.html = [] def indentone(self, stack, prevline): if len(stack) == 0: stack.append('
') tmpline = string.split(line, '_') tmpline2 = [tmpline[0]] for element in tmpline[1:]: if emphasis: tmpline2.append('') tmpline2.append(element) emphasis = 0 else: tmpline2.append('') tmpline2.append(element) emphasis = 1 line = string.join(tmpline2, '') prevline = line previndentlevel = currindentlevel self.html.append(prevline) stack = self.emptystack(stack) self.HTML = string.join(self.html, '') return self.HTML if __name__ == '__main__': import sys data = sys.stdin.readlines() x = translator(data) sys.stdout.write(x.translate())