Skip to content
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

Add line wrap for examples in documentation #139

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Unhandled exception in telemetry when username could not be inferred on Windows
- Metadata is now correctly updated for hybrid spaces
- Unintended deactivation of telemetry due to import problem
- Line wrapping in examples

## [0.7.3] - 2024-02-09
### Added
Expand Down
25 changes: 18 additions & 7 deletions docs/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Scienfitz marked this conversation as resolved.
Show resolved Hide resolved
import pathlib
import shutil
import textwrap
AVHopp marked this conversation as resolved.
Show resolved Hide resolved
Scienfitz marked this conversation as resolved.
Show resolved Hide resolved
from subprocess import DEVNULL, STDOUT, check_call

from tqdm import tqdm
Expand Down Expand Up @@ -158,16 +159,26 @@ def create_example_documentation(example_dest_dir: str, ignore_examples: bool):
)

# CLEANUP
# Remove all lines that try to include a png file
markdown_path = file.with_suffix(".md")
# We wrap lines which are too long as long as they do not contain a link.
# To discover whether a line contains a link, we check if the string "]("
# is contained.
with open(markdown_path, "r", encoding="UTF-8") as markdown_file:
lines = markdown_file.readlines()

content = markdown_file.read()
wrapped_lines = []
for line in content.splitlines():
if "![svg]" in line or "![png]" in line or "<Figure size" in line:
continue
if len(line) > 88 and "](" not in line:
wrapped = textwrap.wrap(line, width=88)
wrapped_lines.extend(wrapped)
else:
wrapped_lines.append(line)

# Add a manual new line to each of the lines
lines = [line + "\n" for line in wrapped_lines]
# Delete lines we do not want to have in our documentation
lines = [line for line in lines if "![svg]" not in line]
lines = [line for line in lines if "![png]" not in line]
lines = [line for line in lines if "<Figure size" not in line]

# lines = [line for line in lines if "![svg]" not in line]
# We check whether pre-built light and dark plots exist. If so, we append
# corresponding lines to our markdown file for including them.
light_figure = pathlib.Path(sub_directory / (file_name + "_light.svg"))
Expand Down