8000 Add support for syntax highlighting in PEPs by ilevkivskyi · Pull Request #1063 · python/pythondotorg · GitHub
[go: up one dir, main page]

Skip to content

Add support for syntax highlighting in PEPs #1063

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Implement review comments, and add a test
  • Loading branch information
ilevkivskyi committed Mar 23, 2017
commit ccc4a4d5c387db7209912993e52e680308a6f5d8
11 changes: 8 additions & 3 deletions peps/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
PEP_TEMPLATE = 'pages/pep-page.html'
pep_url = lambda num: 'dev/peps/pep-{}/'.format(num)

# To simplify syntax highlighting, all literal blocks (those produced by ::)
# in the following PEPs will be automatically highlighted using Python lexer.
# PEP editors/authors could make simple PRs extending this list.
# This will be not needed when PEPs are moved to RtD and all code blocks are
# formatted using .. code:: language.
PURE_PYTHON_PEPS = [483, 484, 526]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


def check_paths():
Expand Down Expand Up @@ -165,16 +170,16 @@ 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")
# Fix highlighting code
code_blocks = pep_content.find_all('pre', class_='code')
for cb in code_blocks:
del cb['class']
div = pep_content.new_tag('div')
div['class'] = ['highlight']
cb.wrap(div)
# Highlight existing pure-Python PEPs
if int(pep_number) in PURE_PYTHON_PEPS:
literal_blocks = pep_content.find_all("pre", class_="literal-block")
literal_blocks = pep_content.find_all('pre', class_='literal-block')
for lb in literal_blocks:
block = lb.string
if block:
Expand Down
Loading
0