diff options
-rw-r--r-- | pycco/main.py | 50 | ||||
-rw-r--r-- | tests/test_pycco.py | 22 |
2 files changed, 63 insertions, 9 deletions
diff --git a/pycco/main.py b/pycco/main.py index eeaf816..bfce2ea 100644 --- a/pycco/main.py +++ b/pycco/main.py @@ -48,6 +48,7 @@ def generate_documentation(source, outdir=None, preserve_paths=True, code = open(source, "rb").read().decode(encoding) return _generate_documentation(source, code, outdir, preserve_paths, language) +<<<<<<< HEAD def _generate_documentation(file_path, code, outdir, preserve_paths, language): """ @@ -58,6 +59,18 @@ def _generate_documentation(file_path, code, outdir, preserve_paths, language): highlight(sections, language, preserve_paths=preserve_paths, outdir=outdir) return generate_html(file_path, sections, preserve_paths=preserve_paths, outdir=outdir) +======= + +def _generate_documentation(file_path, code, outdir, preserve_paths, language): + """ + Helper function to allow documentation generation without file handling. + """ + language = get_language(file_path, code, language=language) + sections = parse(code, language) + highlight(sections, language, preserve_paths=preserve_paths, outdir=outdir) + return generate_html(file_path, sections, preserve_paths=preserve_paths, outdir=outdir) + +>>>>>>> bbeee06f1222fa47439717d2e4b642a41e9d7f4b def parse(code, language): """ @@ -94,10 +107,13 @@ def parse(code, language): # Setup the variables to get ready to check for multiline comments multi_line = False + multi_string = False multistart, multiend = language.get("multistart"), language.get("multiend") comment_matcher = language['comment_matcher'] for line in lines: + process_as_code = False + # Only go into multiline comments section when one of the delimiters is # found to be at the start of a line if multistart and multiend and \ @@ -110,16 +126,28 @@ def parse(code, language): and len(line.strip()) > len(multiend)): multi_line = False - # Get rid of the delimiters so that they aren't in the final docs - line = line.replace(multistart, '') - line = line.replace(multiend, '') - docs_text += line.strip() + '\n' - indent_level = re.match("\s*", line).group(0) - if has_code and docs_text.strip(): - save(docs_text, code_text[:-1]) - code_text = code_text.split('\n')[-1] - has_code = docs_text = '' + if((not line.strip().startswith(multistart) and not multi_line) or multi_string): + + process_as_code = True + + if(multi_string): + multi_line = False + multi_string = False + else: + multi_string = True + + else: + # Get rid of the delimiters so that they aren't in the final docs + line = line.replace(multistart, '') + line = line.replace(multiend, '') + docs_text += line.strip() + '\n' + indent_level = re.match("\s*", line).group(0) + + if has_code and docs_text.strip(): + save(docs_text, code_text[:-1]) + code_text = code_text.split('\n')[-1] + has_code = docs_text = '' elif multi_line: # Remove leading spaces @@ -135,6 +163,10 @@ def parse(code, language): docs_text += re.sub(comment_matcher, "", line) + "\n" else: + process_as_code = True + + if(process_as_code): + if code_text and any(line.lstrip().startswith(x) for x in ['class ', 'def ', '@']): if not code_text.lstrip().startswith("@"): diff --git a/tests/test_pycco.py b/tests/test_pycco.py index 7248a1a..2cc2b15 100644 --- a/tests/test_pycco.py +++ b/tests/test_pycco.py @@ -120,3 +120,25 @@ def test_generate_documentation(): def test_process(preserve_paths, choice): lang_name = choice([l["name"] for l in p.languages.values()]) p.process([PYCCO_SOURCE], preserve_paths=preserve_paths, outdir=tempfile.gettempdir(), language=lang_name) +<<<<<<< HEAD + + +def test_ensure_multiline_string_support(): + code = '''x = """ +how about this? +""" + +y = z # is this where it should be? + +# how did this get so *BIG!* + +def x(): + """how would you fix? + """''' + + docs_code_tuple_list = p.parse(code,PYTHON) + + assert docs_code_tuple_list[0]['docs_text'] == '' + assert "#" not in docs_code_tuple_list[1]['docs_text'] +======= +>>>>>>> bbeee06f1222fa47439717d2e4b642a41e9d7f4b |