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

Stardoc over-escapes angle brackets in docstrings. #137

Closed
adam-azarchs opened this issue Oct 11, 2022 · 4 comments · Fixed by #161
Closed

Stardoc over-escapes angle brackets in docstrings. #137

adam-azarchs opened this issue Oct 11, 2022 · 4 comments · Fixed by #161

Comments

@adam-azarchs
Copy link
Contributor

Unfortunately, while #133 fixed a bunch of things, it also broke a bunch of other things. In particular, if one has a rule or respository rule with a doc attribute like

doc = """
Blah blah `<workspace_name>`
"""

it will be converted to

Blah blah `&lt;workspace_name&gt;`

which renders as

Blah blah &lt;workspace_name&gt;

The issue here, of course, is the mismatch between using HTML tags (e.g. <pre> or <code>) for formatting in some situations (e.g. tables), and native markdown formatting in others. One must use escaping in the former situation, but using it in the latter breaks stuff.

adam-azarchs added a commit to adam-azarchs/stardoc that referenced this issue Oct 11, 2022
adam-azarchs added a commit to adam-azarchs/stardoc that referenced this issue Oct 11, 2022
adam-azarchs added a commit to adam-azarchs/stardoc that referenced this issue Oct 11, 2022
@alexeagle
Copy link
Contributor

I think the &lt;p&gt;
here

| <a id="my_repo-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |

is another case of this bug?

@adam-azarchs
Copy link
Contributor Author

I think the &lt;p&gt; here

is another case of this bug?

This is somewhat different, as it's arguable that this is a bug in the source of that documentation rather than in the translation thereof, though the backwards-compatibility argument for saying it's a bug on this end is pretty strong. It's also a bit of an oddball case, since the docstring there is defined in Java rather than Starlark.

At any rate, we can't really expect it to be able to guess whether <p> means "I want a new paragraph" or "I want a <p> in the text"; we can only expect it to be consistent as to whether it's treating the input as markdown or as html.

@alexeagle
Copy link
Contributor

Hm that's interesting that the two newlines in that doc string get lost as well. The paragraph tag shouldn't be needed if docs are markdown and there is a blank line in between.

@adam-azarchs
Copy link
Contributor Author

I opened #138 to add some (failing) test cases demonstrating some of these problems. However unless I'm mistaken the code to fix this issue lives somewhere in the java code of https//github.com/bazelbuild/bazel, so it can't be fixed via a PR in this repo.

fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
Examples to demonstrate
bazelbuild#137.

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
Examples to demonstrate
bazelbuild#137.

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
Examples to demonstrate
bazelbuild#137.

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
Examples to demonstrate
bazelbuild#137.

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
Examples to demonstrate
bazelbuild#137.

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
fmeum pushed a commit to fmeum/stardoc that referenced this issue Jul 9, 2023
Examples to demonstrate
bazelbuild#137.

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
tetromino pushed a commit that referenced this issue Jul 18, 2023
Reverts #133 so that HTML escaping is not applied to Markdown. Instead, Markdown content such as docstrings can use HTML formatting and escape angle brackets with backslashes, HTML entities or inline code segments. Default values are embedded in inline code segments instead of `<code>` tags, which does not require escaping.

As a result, docstrings behave just like regular Markdown contexts while default values are rendered without smart quotes and can contain both `<` and `` ` `` without causing escaping issues.

Also includes tests based on #138.

Fixes #137
Closes #138
Fixes #142
Closes #143

Requires bazelbuild/bazel#18867

Co-authored-by: Adam Azarchs <adam.azarchs@10xgenomics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants