In Markdown table cells, apply HTML escaping only to code blocks, and apply it properly#167
Merged
tetromino merged 10 commits intobazelbuild:masterfrom Aug 1, 2023
Merged
Conversation
… 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.
Collaborator
Author
|
I have refactored markdownCellFormat to make it feasible to extend it later for formatting lists etc. inside markdown tables. |
brandjon
approved these changes
Aug 1, 2023
Member
brandjon
left a comment
There was a problem hiding this comment.
I left some comments on the parsing logic but didn't go through the whole algorithm with a fine-toothed comb.
| resultString = replaceWithTag(resultString, "`", "<code>", "</code>"); | ||
| // See https://github.github.com/gfm | ||
| private static final class MarkdownCellFormatter { | ||
| private final ImmutableList<String> lines; |
Member
There was a problem hiding this comment.
Please add one-line comments to doc the invariant for these fields. (Especially that currentLine is 0-indexed.)
\r\n will be normalized to \n by Bazel's Starlark interpreter, and if it somehow ends up in the input proto, it will be stripped in our String.lines() call regardless.
…540a23051b589c6ef870d0a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
<br>or an HTML entity)The latter restriction makes it impossible to have a fenced code block inside a table cell.
Therefore:
<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