From 92b749cfa26fafb3765aeb0be5486a16f9faa83d Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 29 Jun 2010 20:28:47 -0700 Subject: Fixing bug with splitting fragments --- pocco.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pocco.py b/pocco.py index 559e38b..40e4691 100644 --- a/pocco.py +++ b/pocco.py @@ -81,7 +81,7 @@ def highlight(source, sections): output = output.replace(highlight_start, "").replace(highlight_end, "") fragments = re.split(language["divider_html"], output) for i, section in enumerate(sections): - section["code_html"] = highlight_start + fragments[i] + highlight_end + section["code_html"] = highlight_start + shift(fragments, "") + highlight_end section["docs_html"] = markdown(section["docs_text"]) section["num"] = i @@ -137,7 +137,7 @@ for ext, l in languages.items(): # The mirror of `divider_text` that we expect Pygments to return. We can split # on this to recover the original sections. - l["divider_html"] = re.compile(r'\n*' + l["symbol"] + 'DIVIDER\n*') + l["divider_html"] = re.compile(r'\n*' + l["symbol"] + 'DIVIDER\n*') # Get the Pygments Lexer for this language. l["lexer"] = lexers.get_lexer_by_name(l["name"]) @@ -152,6 +152,14 @@ def destination(filepath): name = filepath.replace(filepath[ filepath.rindex("."): ], "") return "docs/" + path.basename(name) + ".html" +# Shift items off the front of the `list` until it is empty, then return +# `default`. +def shift(list, default): + try: + return list.pop(0) + except IndexError: + return default + # Ensure that the destination directory exists. def ensure_directory(): Popen(["mkdir", "-p", "docs"]).wait() -- cgit v1.2.3