diff options
author | Zach Smith <zd@zdsmith.com> | 2018-04-25 21:07:36 -0400 |
---|---|---|
committer | Zach Smith <zd@zdsmith.com> | 2018-04-25 21:07:36 -0400 |
commit | 1b536d0b910c73ba298587bf28060ef8aaac0403 (patch) | |
tree | e11ae9e5ef00ceaaac324aef465999ef02cb5833 | |
parent | c815be6017bbe884ce88bb41f7ec0369ca77914d (diff) | |
download | pycco-1b536d0b910c73ba298587bf28060ef8aaac0403.tar.gz |
Fix multicomment Python
-rw-r--r-- | pycco/languages.py | 3 | ||||
-rw-r--r-- | pycco/main.py | 16 |
2 files changed, 13 insertions, 6 deletions
diff --git a/pycco/languages.py b/pycco/languages.py index 48288f0..f1ec64b 100644 --- a/pycco/languages.py +++ b/pycco/languages.py @@ -11,6 +11,7 @@ SLASH_STAR = "/*" STAR_SLASH = "*/" SLASH_SLASH = "//" DASH_DASH = "--" +TRIPLE_QUOTE = '"""' def lang(name, comment_symbol, multistart=None, multiend=None): result = { @@ -46,7 +47,7 @@ supported_languages = { ".rb": lang("ruby", HASH, "=begin", "=end"), - ".py": lang("python", HASH, '"""', '""'), + ".py": lang("python", HASH, TRIPLE_QUOTE, TRIPLE_QUOTE), ".scm": lang("scheme", ";;", "#|", "|#"), diff --git a/pycco/main.py b/pycco/main.py index 9e4a3c9..b82cadb 100644 --- a/pycco/main.py +++ b/pycco/main.py @@ -257,19 +257,25 @@ def highlight(sections, language, preserve_paths=True, outdir=None): ) lexer = language["lexer"] html_formatter = formatters.get_formatter_by_name("html") - output = pygments.highlight(joined_text, lexer, html_formatter) + divider_html = language["divider_html"] + + output = pygments.highlight( + joined_text, lexer, html_formatter + ).replace( + highlight_start, "" + ).replace( + highlight_end, "" + ) + fragments = re.split(divider_html, output) - 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 + shift(fragments, "") + highlight_end - docs_text = section['docs_text'] try: docs_text = unicode(section["docs_text"]) except UnicodeError: docs_text = unicode(section["docs_text"].decode('utf-8')) except NameError: - pass + docs_text = section['docs_text'] section["docs_html"] = markdown(preprocess(docs_text, preserve_paths=preserve_paths, outdir=outdir)) |