diff options
| author | bwarsaw | 2000-11-08 18:46:43 +0000 |
|---|---|---|
| committer | bwarsaw | 2000-11-08 18:46:43 +0000 |
| commit | f4be60fa0064e9c1ad06fb6e474ae3812ce70f7b (patch) | |
| tree | 86f82e9a8f9279fbfb23339108dd2c10417db6ba /admin/bin/faq2ht.py | |
| parent | 9bd74c17a973041ffec9af764373438d72a90c1a (diff) | |
| download | mailman-f4be60fa0064e9c1ad06fb6e474ae3812ce70f7b.tar.gz mailman-f4be60fa0064e9c1ad06fb6e474ae3812ce70f7b.tar.zst mailman-f4be60fa0064e9c1ad06fb6e474ae3812ce70f7b.zip | |
Diffstat (limited to 'admin/bin/faq2ht.py')
| -rwxr-xr-x | admin/bin/faq2ht.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/admin/bin/faq2ht.py b/admin/bin/faq2ht.py new file mode 100755 index 000000000..84d2659f7 --- /dev/null +++ b/admin/bin/faq2ht.py @@ -0,0 +1,101 @@ +#! /usr/bin/env python + +"""Convert the plain text FAQ file to its .ht template. + +Requires Python 2.0 +""" + +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 + + <h3>Mailman Frequently Asked Questions</h3> +''' + 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('<li>') + line = line.replace('*', '', 1) + # substitute <...> + line = re.sub(r'<(?P<var>[^>]+)>', + '<em>\g<var></em>', + line) + # make links active + line = re.sub(r'(?P<url>http://\S+)', + '<a href="\g<url>">\g<url></a>', + line) + answer.append(line) + + lineno += 1 + faq.append((question, answer)) + + for question, answer in faq: + print >> out, '<b>', + for line in question: + print >> out, line + print >> out, '</b><br>', + for line in answer: + if not line: + print >> out, '<p>', + else: + print >> out, line + + if closep: + out.close() + + + +if __name__ == '__main__': + main() |
