-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See this PR from which the fix was taken: https://github.com/executablebooks/sphinx-comments/pull/18/files
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This is intended to implement the fix to sphinx-comments in | ||
# https://github.com/executablebooks/sphinx-comments/pull/18/ | ||
# This is a temporary fix until the PR is merged and released. | ||
# | ||
# The fix enables us to use utterances comments in Jupyter Book. | ||
|
||
import re | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
|
||
def fix_utterances_script(html_path): | ||
with open(html_path, 'r') as f: | ||
notebook = f.read() | ||
|
||
new_notebook = notebook.replace("div.section", "section") | ||
new_notebook = new_notebook.replace( | ||
"sections !== null", | ||
"sections !== null && sections.length > 0" | ||
) | ||
if new_notebook != notebook: | ||
print(f"Fixing {html_path}") | ||
with open(html_path, 'w') as f: | ||
f.write(new_notebook) | ||
|
||
|
||
def main(path): | ||
for html_path in Path(path).glob('**/*.html'): | ||
fix_utterances_script(html_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser(description='Fix Jupyter Book comments') | ||
parser.add_argument('path', help='Path to the Jupyter Book build directory', | ||
type=str, default='_build/html') | ||
args = parser.parse_args() | ||
main(args.path) |