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

Do not HTML-escape and use Markdown inline code for defaults #161

Merged
merged 6 commits into from
Jul 18, 2023

Conversation

fmeum
Copy link
Contributor

@fmeum fmeum commented Jul 8, 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

@fmeum fmeum force-pushed the code-escaping branch 11 times, most recently from db8b8bb to b79d934 Compare July 9, 2023 09:45
@fmeum
Copy link
Contributor Author

fmeum commented Jul 9, 2023

@tetromino Could you review this PR? I created it when I noticed that updating Stardoc from 0.5.0 to 0.5.6 for Bzlmod compatibility broke my rulesets' docs (e.g. angle brackets in code blocks). I would really like to see Stardoc docs behave more similarly to other well-known Markdown contexts such as GitHub READMEs.

CC @illicitonion @adam-azarchs

@fmeum fmeum marked this pull request as ready for review July 9, 2023 09:55
@tetromino
Copy link
Collaborator

tetromino commented Jul 12, 2023

I agree with the PR in principle, but before reviewing and merging this, I want to move the markdown renderer java code here from the bazel repo and finally delete renderer_binary.jar instead of needing to keep updating it.

Work is in progress, give me (and my reviewers) a few days.

@fmeum
Copy link
Contributor Author

fmeum commented Jul 12, 2023

Sounds good! I updated the PR to point to Bazel master and will happily make further changes post-move. Just mention me.

@fmeum
Copy link
Contributor Author

fmeum commented Jul 13, 2023

@tetromino I rebased onto master including the move commit.

Copy link
Collaborator

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. I do see an odd change with extra whitespace in some default values cells, but I think that can be fixed in a separate PR (we have bad whitespace discipline in general).

@tetromino tetromino merged commit 6b6acb3 into bazelbuild:master Jul 18, 2023
@fmeum fmeum deleted the code-escaping branch July 18, 2023 15:10
@fmeum
Copy link
Contributor Author

fmeum commented Jul 18, 2023

@tetromino Thanks! It would be great if this could be included in a release soon to unblock rulesets that need to update for repo mapping support.

@tetromino
Copy link
Collaborator

tetromino commented Jul 18, 2023

@tetromino Thanks! It would be great if this could be included in a release soon to unblock rulesets that need to update for repo mapping support.

This release will break all existing golden markdown tests for Stardoc users. In order to minimize the frequency of such breakage, I want to additionally land the following breaking changes before cutting a release:

tetromino added a commit to tetromino/stardoc that referenced this pull request Jul 25, 2023
… apply it properly

Since bazelbuild#161 removed HTML escaping for defaults and function docstrings,
we should do the same for attribute and param docs in table cells.

The only limitations Markdown places on table cells are:
* no pipe characters (they must be escaped with a backslash)
* no newlines (they must be transformed into <br> or an HTML entity)

The latter restriction makes it impossible to have a fenced code block
inside a table cell.

Therefore:
* we do not escape HTML or Markdown markup outside a fenced code block
* we keep existing logic for escaping newlines outside a fenced code
  block
* we fix fence detection (e.g. allowing more than 3 fence characters to
  support embedded code blocks in code blocks, allowing tildes as fence
  characters, properly handling language names, etc.);
* in code block content, we escape HTML, and we escape newlines as HTML
  entities (since <br> does not work in a <pre><code> block) - finally
  fixing code block newlines in table cells.

This is a followup to bazelbuild#161.
tetromino added a commit to tetromino/stardoc that referenced this pull request Jul 25, 2023
… apply it properly

Since bazelbuild#161 removed HTML escaping for defaults and function docstrings,
we should do the same for attribute and param docs in table cells.

The only limitations Markdown places on table cells are:
* no pipe characters (they must be escaped with a backslash)
* no newlines (they must be transformed into <br> or an HTML entity)

The latter restriction makes it impossible to have a fenced code block
inside a table cell.

Therefore:
* we do not escape HTML or Markdown markup outside a fenced code block
* we keep existing logic for escaping newlines outside a fenced code
  block
* we fix fence detection (e.g. allowing more than 3 fence characters to
  support embedded code blocks in code blocks, allowing tildes as fence
  characters, properly handling language names, etc.);
* in code block content, we escape HTML, and we escape newlines as HTML
  entities (since <br> does not work in a <pre><code> block) - finally
  fixing code block newlines in table cells.

This is a followup to bazelbuild#161.
tetromino added a commit that referenced this pull request Aug 1, 2023
… apply it properly (#167)

In Markdown table cells, apply HTML escaping only to code blocks, and apply it properly

Since #161 removed HTML escaping for defaults and function docstrings, we should do the same for attribute and param docs in table cells.

The only limitations Markdown places on table cells are:
* no pipe characters (they must be escaped with a backslash)
* no newlines (they must be transformed into `<br>` or an HTML entity)

The latter restriction makes it impossible to have a fenced code block inside a table cell.

Therefore:
* we do not escape HTML or Markdown markup outside a fenced code block
* we keep existing logic for escaping newlines outside a fenced code block
* we fix fence detection (e.g. allowing more than 3 fence characters to support embedded code blocks in code blocks, allowing tildes as fence characters, properly handling language names, etc.);
* in code block content, we escape HTML, and we escape newlines as HTML entities (since `<br>` does not work in a `<pre><code>` block) - finally fixing code block newlines in table cells.
    
This is a followup to #161.

Partially addresses #118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants