From b132a73f15e432eaf43310fce9196ca0c0651465 Mon Sep 17 00:00:00 2001 From: <> Date: Thu, 2 Jan 2003 05:25:50 +0000 Subject: This commit was manufactured by cvs2svn to create branch 'Release_2_1-maint'. --- admin/bin/faq2ht.py | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 admin/bin/faq2ht.py (limited to 'admin/bin/faq2ht.py') diff --git a/admin/bin/faq2ht.py b/admin/bin/faq2ht.py new file mode 100755 index 00000000..29db9ea7 --- /dev/null +++ b/admin/bin/faq2ht.py @@ -0,0 +1,102 @@ +#! /usr/bin/env python + +"""Convert the plain text FAQ file to its .ht template. +""" + +import sys +import os +import re + + + +def main(): + faqfile = sys.argv[1] + fp = open(faqfile) + lines = fp.readlines() + fp.close() + + outfile = sys.argv[2] + if outfile == '-': + closep = 0 + out = sys.stdout + else: + closep = 1 + out = open(outfile, 'w') + + # skip over cruft in FAQ file + lineno = 0 + while not lines[lineno].startswith('FREQUENTLY'): + lineno += 1 + lineno += 1 + + # skip blanks + while not lines[lineno].strip(): + lineno += 1 + + # first print out standard .ht boilerplate + print >> out, '''\ +Title: Mailman Frequently Asked Questions + +See also the Mailman +FAQ Wizard for more information. + +

Mailman Frequently Asked Questions

+''' + first = 1 + question = [] + answer = [] + faq = [] + while 1: + line = lines[lineno][:-1] + + if line.startswith('Q.'): + inquestion = 1 + if not first: + faq.append((question, answer)) + question = [] + answer = [] + else: + first = 0 + elif line.startswith('A.'): + inquestion = 0 + elif line.startswith('\f'): + break + + if inquestion: + question.append(line) + else: + # watch for lists + if line.lstrip().startswith('*'): + answer.append('
  • ') + line = line.replace('*', '', 1) + # substitute <...> + line = re.sub(r'<(?P[^>]+)>', + '\g', + line) + # make links active + line = re.sub(r'(?Phttp://\S+)', + '\g', + line) + answer.append(line) + + lineno += 1 + faq.append((question, answer)) + + for question, answer in faq: + print >> out, '', + for line in question: + print >> out, line + print >> out, '
    ', + for line in answer: + if not line: + print >> out, '

    ', + else: + print >> out, line + + if closep: + out.close() + + + +if __name__ == '__main__': + main() -- cgit v1.2.3