-
Notifications
You must be signed in to change notification settings - Fork 45
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
In Markdown table cells, apply HTML escaping only to code blocks, and apply it properly #167
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.
I have refactored markdownCellFormat to make it feasible to extend it later for formatting lists etc. inside markdown tables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments on the parsing logic but didn't go through the whole algorithm with a fine-toothed comb.
src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
Outdated
Show resolved
Hide resolved
resultString = replaceWithTag(resultString, "`", "<code>", "</code>"); | ||
// See https://github.github.com/gfm | ||
private static final class MarkdownCellFormatter { | ||
private final ImmutableList<String> lines; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add one-line comments to doc the invariant for these fields. (Especially that currentLine is 0-indexed.)
src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/skydoc/rendering/MarkdownUtil.java
Outdated
Show resolved
Hide resolved
\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
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