diff --git a/peps/converters.py b/peps/converters.py index 0d8c6e6f6..24877f817 100644 --- a/peps/converters.py +++ b/peps/converters.py @@ -181,7 +181,14 @@ def convert_pep_page(pep_number, content): data['content'] = str(pep_content) - source_link = "https://github.com/python/peps/blob/master/pep-{0}.txt".format(pep_number) + pep_ext = '.txt' + pep_rst_source = os.path.join(settings.PEP_REPO_PATH, + 'pep-{}.rst'.format(pep_number)) + if os.path.exists(pep_rst_source): + pep_ext = '.rst' + + source_link = 'https://github.com/python/peps/blob/master/pep-{}{}'.format( + pep_number, pep_ext) data['content'] += """Source: {0}""".format(source_link) return data diff --git a/peps/tests/fake_pep_repo/pep-0012.html b/peps/tests/fake_pep_repo/pep-0012.html new file mode 100644 index 000000000..e341e82f5 --- /dev/null +++ b/peps/tests/fake_pep_repo/pep-0012.html @@ -0,0 +1,53 @@ + + +++ + + + + + + + + + + + + + + + + + +
PEP:12
Title:Sample reStructuredText PEP Template
Author:David Goodger <goodger at python.org>, +Barry Warsaw <barry at python.org>
Status:Active
Type:Process
Content-Type:text/x-rst
Created:05-Aug-2002
Post-History:30-Aug-2002
+
+
+

Contents

+ +
+
+

Abstract

+

This PEP provides a boilerplate or sample template for creating your +own reStructuredText PEPs.

+
+ + diff --git a/peps/tests/fake_pep_repo/pep-0012.rst b/peps/tests/fake_pep_repo/pep-0012.rst new file mode 100644 index 000000000..92a90835e --- /dev/null +++ b/peps/tests/fake_pep_repo/pep-0012.rst @@ -0,0 +1,33 @@ +PEP: 12 +Title: Sample reStructuredText PEP Template +Author: David Goodger , + Barry Warsaw +Status: Active +Type: Process +Content-Type: text/x-rst +Created: 05-Aug-2002 +Post-History: 30-Aug-2002 + + +Abstract +======== + +This PEP provides a boilerplate or sample template for creating your +own reStructuredText PEPs. + + +Copyright +========= + +This document has been placed in the public domain. + + + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + coding: utf-8 + End: diff --git a/peps/tests/test_converters.py b/peps/tests/test_converters.py index 6802742aa..aa79527cb 100644 --- a/peps/tests/test_converters.py +++ b/peps/tests/test_converters.py @@ -24,6 +24,16 @@ def test_source_link(self): pep.content.rendered ) + @override_settings(PEP_REPO_PATH=FAKE_PEP_REPO) + def test_source_link_rst(self): + pep = get_pep_page('0012') + self.assertEqual(pep.title, 'PEP 12 -- Sample reStructuredText PEP Template') + self.assertIn( + 'Source: https://github.com/python/peps/blob/master/pep-0012.rst', + pep.content.rendered + ) + @override_settings(PEP_REPO_PATH=FAKE_PEP_REPO) def test_invalid_pep_number(self): with captured_stdout() as stdout: