From f293f4f8e4f01389a231e0b08a43348c44e2491f Mon Sep 17 00:00:00 2001 From: "Alexander V. Hopp" Date: Fri, 23 Feb 2024 14:40:43 +0100 Subject: [PATCH 1/3] Add line wrap for examples in documentation --- docs/scripts/utils.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/scripts/utils.py b/docs/scripts/utils.py index 83e8dd18c..8a4dc564b 100644 --- a/docs/scripts/utils.py +++ b/docs/scripts/utils.py @@ -2,6 +2,7 @@ import pathlib import shutil +import textwrap from subprocess import DEVNULL, STDOUT, check_call from tqdm import tqdm @@ -158,11 +159,21 @@ 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 len(line) > 88 and "](" not in line: + wrapped = textwrap.wrap(line, width=88) + wrapped_lines.extend(wrapped) + else: + wrapped_lines.append(line) + + lines = "\n".join(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] From 39f31af71e71f31bacb81fec9189e764ab626b8d Mon Sep 17 00:00:00 2001 From: "Alexander V. Hopp" Date: Fri, 23 Feb 2024 15:26:34 +0100 Subject: [PATCH 2/3] Fix handling of lines that should not be contained --- docs/scripts/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/scripts/utils.py b/docs/scripts/utils.py index 8a4dc564b..bcdd3f935 100644 --- a/docs/scripts/utils.py +++ b/docs/scripts/utils.py @@ -167,18 +167,18 @@ def create_example_documentation(example_dest_dir: str, ignore_examples: bool): content = markdown_file.read() wrapped_lines = [] for line in content.splitlines(): + if "![svg]" in line or "![png]" in line or "
88 and "](" not in line: wrapped = textwrap.wrap(line, width=88) wrapped_lines.extend(wrapped) else: wrapped_lines.append(line) - lines = "\n".join(wrapped_lines) + # 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 "
Date: Fri, 23 Feb 2024 15:27:49 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b4241de..36ceee5bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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