Skip to content

Commit 7adf3f6

Browse files
committed
Formatting cleanup
1 parent 9a5d8da commit 7adf3f6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.jenkins/custom_pandoc_filter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def to_markdown(item, skip_octicon=False):
2525
else:
2626
return ''
2727

28+
2829
def process_admonitions(key, value, format, meta):
2930
# Replace admonitions with proper HTML.
3031
if key == 'Div':
@@ -59,7 +60,7 @@ def process_admonitions(key, value, format, meta):
5960
note_content_md = ''.join(to_markdown(item) for item in note_content)
6061
html_content = markdown.markdown(note_content_md)
6162

62-
return [{'t': 'RawBlock', 'c': ['html', f'<div style="background-color: {color}; color: #fff; font-weight: 700; padding-left: 10px; padding-top: 5px; padding-bottom: 5px">{label}</div>']}, {'t': 'RawBlock', 'c': ['html', '<div style="background-color: #f3f4f7; padding-left: 10px; padding-top: 10px; padding-bottom: 10px; padding-right: 10px">']}, {'t': 'RawBlock', 'c': ['html', html_content]}, {'t': 'RawBlock', 'c': ['html', '</div>']}]
63+
return [{'t': 'RawBlock', 'c': ['html', f'<div style="background-color: {color}; color: #fff; font-weight: 700; padding-left: 10px; padding-top: 5px; padding-bottom: 5px"><strong>{label}</strong></div>']}, {'t': 'RawBlock', 'c': ['html', '<div style="background-color: #f3f4f7; padding-left: 10px; padding-top: 10px; padding-bottom: 10px; padding-right: 10px">']}, {'t': 'RawBlock', 'c': ['html', html_content]}, {'t': 'RawBlock', 'c': ['html', '</div>']}]
6364
elif key == 'RawBlock':
6465
# this is needed for the cells that have embedded video.
6566
# We add a special tag to those: ``` {python, .jupyter-code-cell}
@@ -93,9 +94,10 @@ def process_images(key, value, format, meta):
9394
if src.startswith('/_static'):
9495
src = src[1:]
9596
src = 'https://pytorch.org/tutorials/' + src
96-
97+
9798
return {'t': 'Image', 'c': [[ident, classes, keyvals], caption, [src, title]]}
9899

100+
99101
def process_grids(key, value, format, meta):
100102
# Generate side by side grid cards. Only for the two-cards layout
101103
# that we use in the tutorial template.

.jenkins/post_process_notebooks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# Pattern to search ``` {.python .jupyter-code-cell}
1515
pattern = re.compile(r'(.*?)``` {.python .jupyter-code-cell}\n\n(from IPython.display import display, HTML\nhtml_code = """\n.*?\n"""\ndisplay\(HTML\(html_code\)\))\n```(.*)', re.DOTALL)
1616

17+
1718
def process_video_cell(notebook_path):
1819
"""
1920
This function finds the code blocks with the
@@ -60,6 +61,7 @@ def process_video_cell(notebook_path):
6061

6162
nbf.write(notebook, notebook_path)
6263

64+
6365
def remove_html_tag(content):
6466
"""
6567
Pandoc adds an extraneous ```{=html} ``` to raw HTML blocks which
@@ -74,6 +76,7 @@ def remove_html_tag(content):
7476
content = re.sub(r'</p>\n```', '</p>', content)
7577
return content
7678

79+
7780
def walk_dir(downloads_dir):
7881
"""
7982
Walk the dir and process all notebook files in
@@ -83,9 +86,12 @@ def walk_dir(downloads_dir):
8386
for filename in files:
8487
if filename.endswith('.ipynb'):
8588
process_video_cell(os.path.join(root, filename))
89+
90+
8691
def main():
8792
downloads_dir = './docs/_downloads'
8893
walk_dir(downloads_dir)
8994

95+
9096
if __name__ == "__main__":
9197
main()

0 commit comments

Comments
 (0)