All pastes #252502 Raw Edit

Anonymous

public text v1 · immutable
#252502 ·published 2006-11-19 17:16 UTC
rendered paste body
def toc_rows(rows):
	ldepth = 0
	tmp = ''
	for row in rows:
		if ldepth != row[0]:
			i = 1
			while i < row[0]-ldepth:
				tmp += "\n</ol>\n</li>"
				i += 1
			i = 0
			while i < row[0]-ldepth:
				if row[0]-i > 1:
					tmp += "</li>"
				tmp += "\n<ol>"
				i += 1
		else:
			tmp += '</li>'
		tmp += "\n<li><a href=\"#%s\">%s</a>" % (safe_name(row[1]), row[1])
		ldepth = row[0]
	i = 0
	while i < ldepth:
		tmp += "</li>\n</ol>"
		i += 1
	return tmp