From e419d263ff585c6b4f00a7518c645b7f438e87db Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:21:57 +0200 Subject: [PATCH 1/4] check for backtick in links --- scripts/ci/mdlint.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/scripts/ci/mdlint.py b/scripts/ci/mdlint.py index 36eef75f99c9..b8018aeff407 100755 --- a/scripts/ci/mdlint.py +++ b/scripts/ci/mdlint.py @@ -199,10 +199,40 @@ def explain(): ) +class BacktickLinkError(Error): + CODE = "E004" + + def __init__(self, span: Span): + super().__init__(type(self).CODE, "link contains backtick", span) + + @staticmethod + def explain(): + return textwrap.dedent( + """ + URLs in links wrapping text should not contain backticks (`). + + Example: + ``` + [Some link](`https://github.com/rerun-io/rerun`) + ``` + + Our markdown renderer will treat the above link as a _relative path_ + instead of a URL. If the above markdown is in `examples/robotics/README.md`, + it will link to \"https://rerun.io/examples/robotics/`https://github.com/rerun-io/rerun`\". + + Solution: Remove the backticks. + ``` + [Some link](https://github.com/rerun-io/rerun) + ``` + """ + ) + + EXPLAIN = { NoClosingTagError.CODE: NoClosingTagError.explain, NoPrecedingBlankLineError.CODE: NoPrecedingBlankLineError.explain, BlankLinesError.CODE: BlankLinesError.explain, + BacktickLinkError.CODE: BacktickLinkError.explain, } @@ -314,12 +344,37 @@ def check_video_elements(content: str, errors: list[Error]) -> None: search_start = spans.element.end + 1 +def check_invalid_links(content: str, errors: list[Error]) -> None: + search_start = 0 + while True: + mid_point = content.find("](`", search_start) + if mid_point == -1: + return + + link_start = content.rfind("[", 0, mid_point) + if link_start == -1: + # TODO(jprochazk): invalid link + search_start = mid_point + continue + + link_end = content.find(")", mid_point) + if link_end == -1: + # TODO(jprochazk): invalid link + search_start = mid_point + continue + + search_start = link_end + 1 + + errors.append(BacktickLinkError(span=Span(link_start, link_end))) + + def check_file(path: str) -> str | None: errors: list[Error] = [] content = Path(path).read_text() check_picture_elements(content, errors) check_video_elements(content, errors) + check_invalid_links(content, errors) if len(errors) != 0: return "\n".join([error.render(path, content) for error in errors]) From 859e6f0178fe849012b11a66200f277298ba4d58 Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:22:01 +0200 Subject: [PATCH 2/4] break it --- examples/rust/chess_robby_fischer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rust/chess_robby_fischer/README.md b/examples/rust/chess_robby_fischer/README.md index 27a09890d44c..247a17eaaf39 100644 --- a/examples/rust/chess_robby_fischer/README.md +++ b/examples/rust/chess_robby_fischer/README.md @@ -156,7 +156,7 @@ for file in 0..14 { // The holder board has 6 files } ``` -To log the piece models we convert them from `.stl` files to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) by first reading the `.stl` files using [stl_io](https://docs.rs/stl_io/latest/stl_io/) and then convert them to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) using the function below. +To log the piece models we convert them from `.stl` files to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) by first reading the `.stl` files using [stl_io](`https://docs.rs/stl_io/latest/stl_io/`) and then convert them to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) using the function below. ```rust fn stl_to_mesh3d(mesh: &IndexedMesh, color: impl Into + Clone) -> Mesh3D { From b1ee33a4ea460bd923d9a165787e73f4e5486128 Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:24:07 +0200 Subject: [PATCH 3/4] empty From c6527abc254ecf2029a0056d07a693fe2ce76afc Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:26:47 +0200 Subject: [PATCH 4/4] unbreak it --- examples/rust/chess_robby_fischer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rust/chess_robby_fischer/README.md b/examples/rust/chess_robby_fischer/README.md index 247a17eaaf39..27a09890d44c 100644 --- a/examples/rust/chess_robby_fischer/README.md +++ b/examples/rust/chess_robby_fischer/README.md @@ -156,7 +156,7 @@ for file in 0..14 { // The holder board has 6 files } ``` -To log the piece models we convert them from `.stl` files to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) by first reading the `.stl` files using [stl_io](`https://docs.rs/stl_io/latest/stl_io/`) and then convert them to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) using the function below. +To log the piece models we convert them from `.stl` files to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) by first reading the `.stl` files using [stl_io](https://docs.rs/stl_io/latest/stl_io/) and then convert them to [`rerun::Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) using the function below. ```rust fn stl_to_mesh3d(mesh: &IndexedMesh, color: impl Into + Clone) -> Mesh3D {