forked from qiskit-community/qiskit-textbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polish postprocess HTML script and update dependencies
- Loading branch information
1 parent
cccd216
commit 5cb0e0c
Showing
4 changed files
with
38 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
jupyter-book==0.6.5 | ||
beautifulsoup4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This script santises the sympy latex in the HTML files prior to building the site | ||
import os | ||
import sys | ||
from bs4 import BeautifulSoup | ||
|
||
def sanitize_latex(filepath): | ||
''' | ||
Replace {{ with { { inside LaTeX outputs not to confuse Jekyll about what | ||
should be interpolated. | ||
''' | ||
is_modified = False | ||
soup = BeautifulSoup(open(filepath), 'html.parser') | ||
for latex in soup.find_all('div', {'class': 'output_latex'}): | ||
if r'{{' in latex.string: | ||
sanitized_latex = latex.string.replace(r'{{', '{ {') | ||
latex.string = sanitized_latex | ||
is_modified = True | ||
if is_modified: | ||
print(f'sanitize_latex: `{filepath}`') | ||
with open(filepath, 'w') as f: | ||
f.write(str(soup)) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) < 2: | ||
sys.exit('Usage: python3 postprocess_html.py <build-dir>') | ||
base_dir = sys.argv[1] | ||
for (dirpath, _, filenames) in os.walk(base_dir): | ||
for name in filenames: | ||
if not name.endswith('.html'): | ||
continue | ||
filepath = os.path.join(dirpath, name) | ||
sanitize_latex(filepath) | ||
|
This file was deleted.
Oops, something went wrong.