Commit 077fffa8 authored by Fred Drake's avatar Fred Drake

The letter headings must be requested explicitly with --letters.

parent aa3f9fb7
...@@ -151,7 +151,7 @@ def split_letters(nodes): ...@@ -151,7 +151,7 @@ def split_letters(nodes):
# need a function to separate the nodes into columns... # need a function to separate the nodes into columns...
def split_columns(nodes, columns=1): def split_columns(nodes, columns=1):
if columns <= 1: if columns <= 1:
return (nodes,) return [nodes]
# This is a rough height; we may have to increase to avoid breaks before # This is a rough height; we may have to increase to avoid breaks before
# a subitem. # a subitem.
colheight = len(nodes) / columns colheight = len(nodes) / columns
...@@ -176,7 +176,7 @@ def split_columns(nodes, columns=1): ...@@ -176,7 +176,7 @@ def split_columns(nodes, columns=1):
start = i * colheight start = i * colheight
end = start + colheight end = start + colheight
cols.append(nodes[start:end]) cols.append(nodes[start:end])
return tuple(cols) return cols
DL_LEVEL_INDENT = " " DL_LEVEL_INDENT = " "
...@@ -249,7 +249,7 @@ def format_letter(letter): ...@@ -249,7 +249,7 @@ def format_letter(letter):
% (letter, lettername) % (letter, lettername)
def format_html(nodes, columns=1): def format_html_letters(nodes, columns=1):
letter_groups = split_letters(nodes) letter_groups = split_letters(nodes)
items = [] items = []
for letter, nodes in letter_groups: for letter, nodes in letter_groups:
...@@ -261,6 +261,9 @@ def format_html(nodes, columns=1): ...@@ -261,6 +261,9 @@ def format_html(nodes, columns=1):
s.append(format_nodes(nodes, columns)) s.append(format_nodes(nodes, columns))
return string.join(s, '') return string.join(s, '')
def format_html(nodes, columns):
return format_nodes(nodes, columns)
def collapse(nodes): def collapse(nodes):
"""Collapse sequences of nodes with matching keys into a single node. """Collapse sequences of nodes with matching keys into a single node.
...@@ -289,12 +292,16 @@ def main(): ...@@ -289,12 +292,16 @@ def main():
ifn = "-" ifn = "-"
ofn = "-" ofn = "-"
columns = 1 columns = 1
opts, args = getopt.getopt(sys.argv[1:], "c:o:", ["columns=", "output="]) letters = 0
opts, args = getopt.getopt(sys.argv[1:], "c:lo:",
["columns=", "letters", "output="])
for opt, val in opts: for opt, val in opts:
if opt in ("-o", "--output"): if opt in ("-o", "--output"):
ofn = val ofn = val
elif opt in ("-c", "--columns"): elif opt in ("-c", "--columns"):
columns = string.atoi(val) columns = string.atoi(val)
elif opt in ("-l", "--letters"):
letters = 1
if not args: if not args:
args = [ifn] args = [ifn]
nodes = [] nodes = []
...@@ -302,7 +309,10 @@ def main(): ...@@ -302,7 +309,10 @@ def main():
nodes = nodes + load(open(fn)) nodes = nodes + load(open(fn))
nodes.sort() nodes.sort()
collapse(nodes) collapse(nodes)
html = format_html(nodes, columns) if letters:
html = format_html_letters(nodes, columns)
else:
html = format_html(nodes, columns)
if ofn == "-": if ofn == "-":
sys.stdout.write(html) sys.stdout.write(html)
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment