Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for syntax highlighting in PEPs #1063

Closed
wants to merge 2 commits into from

Conversation

@ilevkivskyi
Copy link

@ilevkivskyi ilevkivskyi commented Mar 16, 2017

Fixes #889

This PR provides two options for syntax highlighting in PEPs:

  • Automatic highlighting of all literal blocks using Python syntax for PEPs in PURE_PYTHON_PEPS. I added few examples there just to illustrate the idea.
  • Now there is support for reST .. code:: your_favourite_language. Such literal blocks will be highlighted using the corresponding syntax.

This PR requires Pygments 2.1.3.

I added a CSS based on Pygments default (I made very few modifications, to match the "general spirit" of the site).

@Mariatta
Copy link
Member

@Mariatta Mariatta commented Mar 23, 2017

Thanks @ilevkivskyi , this seems to work well :)
I tested this locally, using the change made in python/peps#229

Here's how the colors look like
screen shot 2017-03-22 at 5 37 48 pm

@Mariatta Mariatta requested a review from berkerpeksag Mar 23, 2017
Copy link
Member

@berkerpeksag berkerpeksag left a comment

Thanks for the PR! How hard would be to add some tests?

@@ -25,6 +25,7 @@
{% endblock %}
.
{% block content %}
<link rel="stylesheet" type="text/css" href="/static/stylesheets/pygments_default.css" />

This comment has been minimized.

@berkerpeksag

berkerpeksag Mar 23, 2017
Member

We should use {{ STATIC_URL }} instead of hardcoding /static/.

@@ -44,3 +44,5 @@ uWSGI==2.0.10
raven==5.2.0
django-waffle==0.11.1
sqlparse<0.2 #TODO: delete this when we switch to Django 1.8 and DDT 1.5

pygments==2.1.3

This comment has been minimized.

@berkerpeksag

berkerpeksag Mar 23, 2017
Member

Could you add a comment so we won't forget to remove the dependency when we move PEPs to RtD?

@@ -160,6 +165,21 @@ def convert_pep_page(pep_number, content):
# Fix PEP links
pep_content = BeautifulSoup(data['content'])
body_links = pep_content.find_all("a")
# Fix hihglighting code

This comment has been minimized.

@berkerpeksag

berkerpeksag Mar 23, 2017
Member

Typo: hihglighting

from pages.models import Page, Image

PEP_TEMPLATE = 'pages/pep-page.html'
pep_url = lambda num: 'dev/peps/pep-{}/'.format(num)

PURE_PYTHON_PEPS = [483, 484, 526]

This comment has been minimized.

@berkerpeksag

berkerpeksag Mar 23, 2017
Member

This is probably not important to have a constant. I'd say either inline it or add a comment to explain why we need it.

@@ -160,6 +165,21 @@ def convert_pep_page(pep_number, content):
# Fix PEP links
pep_content = BeautifulSoup(data['content'])
body_links = pep_content.find_all("a")
# Fix hihglighting code
code_blocks = pep_content.find_all("pre", class_="code")

This comment has been minimized.

@berkerpeksag

berkerpeksag Mar 23, 2017
Member

Nitpick: I know we are already pretty inconsistent with this, but please use single quotes where possible.

@ilevkivskyi
Copy link
Author

@ilevkivskyi ilevkivskyi commented Mar 23, 2017

@berkerpeksag Thank you for review! I addressed your comments (including a simple test) in a new commit.

@ilevkivskyi
Copy link
Author

@ilevkivskyi ilevkivskyi commented Apr 26, 2017

This is still marked as "Changes requested", although I think I had implemented the required changes a month ago. Should anything more be changed here?

@berkerpeksag
Copy link
Member

@berkerpeksag berkerpeksag commented Apr 26, 2017

Yeah, that's because I haven't had a chance to look at the new version of the PR yet.

@berkerpeksag
Copy link
Member

@berkerpeksag berkerpeksag commented Jun 3, 2017

Thanks for the PR again, @ilevkivskyi. Your changes look good to me, but unfortunately I have to reject this PR. Our ultimate goal is to move PEPs from python.org to Read the Docs so my preference is only fixing bugs in python.org infrastructure and save feature requests to the new infrastructure (also, note that we are going to get this feature for free when we move to RtD)

@brettcannon
Copy link
Member

@brettcannon brettcannon commented Dec 4, 2017

Maybe we should open this again since getting the PEPs over to Read the Docs is moving at the speed of mud?

@ilevkivskyi
Copy link
Author

@ilevkivskyi ilevkivskyi commented Dec 4, 2017

Maybe we should open this again since getting the PEPs over to Read the Docs is moving at the speed of mud?

I am fine with both possibilities: if it stays closed -- less works for me, if it is reopened -- we will have syntax highlighting sooner :-)

@hugovk
Copy link
Contributor

@hugovk hugovk commented Sep 21, 2020

Maybe we should open this again since getting the PEPs over to Read the Docs is moving at the speed of mud?

Three years on: I agree, it'd be great get colouring in whilst waiting on RtD (this big recent effort has stalled: python/peps#1385). I find highlighted code much easier to read.

I've rebased and re-opened this as PR #1638.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.