-
Couldn't load subscription status.
- Fork 19
Add tooling to create Dash docset for RSMTool and other minor changes. #375
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
Merged
Parent:
Merge `master` into `stable`.
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
59e78c0
Add script to insert Dash TOC anchors in HTML files.
desilinguist ee5c6a6
Add doc2dash to requirements.
desilinguist 1be0c0b
Add icon for dash docset
desilinguist 86dfab7
Exclude `deprecated_positional_argument()` method from autodoc.
desilinguist f88e1cc
Clean up `doc/conf.py`
desilinguist 45a4275
Add Dash docset building to Makefile.
desilinguist 2365a08
Fix broken link.
desilinguist 74d8e7e
Fix some indentation issues.
desilinguist 4d14919
Add instructions for Dash docset building
desilinguist 90a282d
Add notes about Dash to repo README and documentation.
desilinguist 1084adf
Tweak dash instructions.
desilinguist 1e27fe8
Reorganize static assets
desilinguist ac61643
Add comment to `conf.py`.
desilinguist 2971425
Tweak Dash message.
desilinguist 82f72d0
Remove extra line.
desilinguist 7d264cb
Merge branch 'fix-broken-rtd-builds' into integrate-dash
desilinguist 631d96a
Add note about dash to contributing section.
desilinguist 839ddb7
Merge branch 'master' into integrate-dash
desilinguist e8e621d
Fix ref link
desilinguist f255800
Fix filepath
desilinguist daba121
Make Dash step last so that there's no depenency on actual release pa…
desilinguist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """ | ||
| Add Dash-style anchors to already-generated HTML documentation. | ||
|
|
||
| This script iterates over pre-specified HTML files generated via | ||
| sphinx-build, finds all of the sections, and adds Dash-style anchors | ||
| so that when those HTML files are displayed in the Dash macOS app, | ||
| the sections are displayed in a Dash TOC on the right. | ||
|
|
||
| :author: Nitin Madnani (nmadnani@ets.org) | ||
| :organization: ETS | ||
| """ | ||
|
|
||
| import argparse | ||
| import logging | ||
| import re | ||
| import pathlib | ||
| import unicodedata | ||
| from urllib.parse import quote | ||
|
|
||
| from bs4 import BeautifulSoup | ||
|
|
||
| # pre-define the list of HTML files we want to miodify | ||
| FILES_TO_MODIFY = ["advanced_usage.html", "api.html", "contributing.html", | ||
| "custom_notebooks.html", "evaluation.html", | ||
| "getting_started.html", "pipeline.html", | ||
| "internal.html", "tutorial.html", | ||
| "usage_rsmtool.html", "utilities.html", "who.html"] | ||
| PILCROW = unicodedata.lookup('PILCROW SIGN') | ||
|
|
||
|
|
||
| def main(): # noqa: D103 | ||
|
|
||
| # set up an argument parser | ||
| parser = argparse.ArgumentParser(prog='add_dash_anchors.py') | ||
| parser.add_argument("htmldir", | ||
| type=pathlib.Path, | ||
| help="path to the already-built HTML documentation") | ||
|
|
||
| # parse given command line arguments | ||
| args = parser.parse_args() | ||
|
|
||
| # set up the logging | ||
| logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO) | ||
|
|
||
| # iterate over all the built HTML files | ||
| for htmlfile in args.htmldir.glob("**/*.html"): | ||
|
|
||
| # we only care about the pre-specified html files | ||
| if htmlfile.name in FILES_TO_MODIFY: | ||
|
|
||
| logging.info(f'Processing {htmlfile.name} ...') | ||
|
|
||
| # parse the file | ||
| with open(htmlfile, 'r') as htmlfh: | ||
| soup = BeautifulSoup(htmlfh, features='html.parser') | ||
|
|
||
| # each HTML file has a main section which we do not need | ||
| # but we need _all_ of the other sections | ||
| sections = soup.body.div.find_all("div", class_="section")[1:] | ||
| for section in sections: | ||
| section_title = section.find(re.compile(r'^h[0-9]')).text | ||
| section_title = section_title.rstrip(PILCROW) | ||
|
|
||
| # convert this title to percent-encoded format which will be | ||
| # the name of our entry | ||
| entry_name = quote(section_title) | ||
| entry_type = 'Section' | ||
| anchor_name = f"//apple_ref/cpp/{entry_type}/{entry_name}" | ||
|
|
||
| # create a new anchor tag for this subsection | ||
| anchor_tag = soup.new_tag('a', | ||
| attrs={'name': anchor_name, | ||
| 'class': "dashAnchor"}) | ||
|
|
||
| # insert this new tag right before the section | ||
| section.insert_before(anchor_tag) | ||
|
|
||
| # overwrite the original HTML file | ||
| with open(htmlfile, 'w') as outfh: | ||
| outfh.write(str(soup)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we make sure this list is up-to-date? Can we create it automatically based on directory content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried this but struggled with it. There are some auto-generated HTML files that we do not want to add Dash nchors to (for example,
genindex.html). I haven’t been able to figure out if this set is fixed and so we can just include all files except the ones in this set. I can work on this in the future.