Skip to content

Escape raw rule documentation text for HTML #326

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

Merged
merged 1 commit into from
Jan 19, 2022
Merged

Escape raw rule documentation text for HTML #326

merged 1 commit into from
Jan 19, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Jan 18, 2022

Some the rule config text is intended for use in both tool output and in the reference, so can't be formatted at the source as the Markdown consumed by the MkDocs website generation system.

This raw text may contain incidental Markdown markup, which would result in it being incorrectly rendered in the website, so it must be escaped. Despite much searching at the time the rule documentation website generation system was created, I could not find a good Go package for Markdown escaping of text. I did find an excellent package for Markdown escaping of HTML, and so I used that instead.

However, this is not sufficient to completely escape the text. The reason is that Markdown is a partial superset of HTML. The github.com/JohannesKaufmann/html-to-markdown/escape package intentionally does not escape HTML. So it is necessary to do HTML escaping of the raw text in addition to Markdown escaping.

HTML escaping was not done previously, which resulted in raw text which incidentally had the angle bracket enclosed form of HTML tags not being rendered in the website.

For example, the "brief" text of rule PF009:

use of compiler.<pattern type>.extra_flags

was rendered as:

use of compiler..extra_flags

image

The raw text is now escaped both for HTML and for Markdown during the generation of the rule documentation website content.

Some the rule config text is intended for use in both tool output and in the reference, so can't be formatted at the
source as the Markdown consumed by the MkDocs website generation system.

This raw text may contain incidental Markdown markup, which would result in it being incorrectly rendered in the
website, so it must be escaped. Despite much searching at the time the rule documentation website generation system was
created, I could not find a good Go package for Markdown escaping of text. I did find an excellent package for Markdown
escaping of HTML, and so I used that instead.

However, this is not sufficient to completely escape the text. The reason is that Markdown is a partial superset of
HTML. The `github.com/JohannesKaufmann/html-to-markdown/escape` package intentionally does not escape HTML. So it is
necessary to do HTML escaping of the raw text in addition to Markdown escaping.

HTML escaping was not done previously, which resulted in raw text which incidentally had the angle bracket enclosed form
of HTML tags not being rendered in the website.

For example, the "brief" text of rule PF009:

```
use of compiler.<pattern type>.extra_flags
```

was rendered as:

```
use of compiler..extra_flags
```

The raw text is now escaped both for HTML and for Markdown during the generation of the rule documentation website
content.
@per1234 per1234 added topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project labels Jan 18, 2022
@per1234 per1234 self-assigned this Jan 18, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 18, 2022

Codecov Report

Merging #326 (3b05382) into main (d1ac9e7) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #326   +/-   ##
=======================================
  Coverage   90.01%   90.01%           
=======================================
  Files          44       44           
  Lines        6770     6770           
=======================================
  Hits         6094     6094           
  Misses        553      553           
  Partials      123      123           
Flag Coverage Δ
unit 90.01% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
ruledocsgen/main.go 83.95% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7c0a9a...3b05382. Read the comment docs.

@per1234 per1234 merged commit ee40282 into arduino:main Jan 19, 2022
@per1234 per1234 deleted the html-escape-ruledocs branch January 19, 2022 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants