From 8a55a6238fd0cccb69cb076e598c3ca806b22911 Mon Sep 17 00:00:00 2001 From: jonrsharpe Date: Mon, 19 Jan 2015 23:31:20 +0000 Subject: Handle comments that contain only cross-references --- pycco/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pycco/main.py b/pycco/main.py index 09584b3..77c7650 100644 --- a/pycco/main.py +++ b/pycco/main.py @@ -164,17 +164,17 @@ def preprocess(comment, section_nr, preserve_paths=True, outdir=None): # Check if the match contains an anchor if '#' in match.group(1): name, anchor = match.group(1).split('#') - return " [%s](%s#%s)" % (name, - path.basename(destination(name, - preserve_paths=preserve_paths, - outdir=outdir)), - anchor) + return "[%s](%s#%s)" % (name, + path.basename(destination(name, + preserve_paths=preserve_paths, + outdir=outdir)), + anchor) else: - return " [%s](%s)" % (match.group(1), - path.basename(destination(match.group(1), - preserve_paths=preserve_paths, - outdir=outdir))) + return "[%s](%s)" % (match.group(1), + path.basename(destination(match.group(1), + preserve_paths=preserve_paths, + outdir=outdir))) def replace_section_name(match): return '%(lvl)s %(name)s' % { @@ -184,7 +184,7 @@ def preprocess(comment, section_nr, preserve_paths=True, outdir=None): } comment = re.sub('^([=]+)([^=]+)[=]*\s*$', replace_section_name, comment) - comment = re.sub('[^`]\[\[(.+?)\]\]', replace_crossref, comment) + comment = re.sub('(? Date: Sun, 8 Nov 2015 16:28:09 +0000 Subject: Resynced whitespace --- pycco/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pycco/main.py b/pycco/main.py index 6d45673..eeaf816 100644 --- a/pycco/main.py +++ b/pycco/main.py @@ -172,7 +172,6 @@ def preprocess(comment, preserve_paths=True, outdir=None): # Check if the match contains an anchor if '#' in match.group(1): name, anchor = match.group(1).split('#') - return " [{}]({}#{})".format(name, path.basename(destination(name, preserve_paths=preserve_paths, -- cgit v1.2.1 From b82a8e45fa5b17ef5f15a410bfd5b694e5a07cba Mon Sep 17 00:00:00 2001 From: Jonathan Sharpe Date: Sun, 8 Nov 2015 16:46:23 +0000 Subject: Added test for parsing of comments with only cross-references --- tests/test_pycco.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_pycco.py b/tests/test_pycco.py index 5a38dd5..7248a1a 100644 --- a/tests/test_pycco.py +++ b/tests/test_pycco.py @@ -60,6 +60,13 @@ def test_multi_line_leading_spaces(): assert parsed[0]["docs_text"] == "This is a\ncomment that\nis indented\n" +def test_comment_with_only_cross_ref(): + source = '''# ==Link Target==\n\ndef test_link():\n """[[testing.py#link-target]]"""\n pass''' + sections = p.parse(source, PYTHON) + p.highlight(sections, PYTHON, outdir=tempfile.gettempdir()) + assert sections[1]['docs_html'] == '

testing.py

' + + @given(text(), text()) def test_get_language_specify_language(source, code): assert p.get_language(source, code, language="python") == p.languages['.py'] -- cgit v1.2.1