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

Add the html_block rule to the markdown renderer #522

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

caleywoods
Copy link
Contributor

@caleywoods caleywoods commented Apr 3, 2024

The goal for all links within the guides is to evaluate them to see whether or not they leave the ".gov" TLD and if they do, we want to make sure that the class list of the link has usa-link--external applied so that the link gets the external link icon shown when it renders on the page.

Most of the work for link checking is handled by the link_open rendering rule which scans all of the links within the markdown documents and then another portion is handled by html_inline for instances where the HTML is placed inside the markdown document. The research for issue #348 discovered that when an HTML page is included using the 11ty include syntax that neither link_open nor html_inline parse links within the included HTML file.

This commit adds a third renderer rule which scans all chunks of HTML to see if it includes any links that leave the ".gov" domain and then attempts to make sure the usa-link--external class is applied.

Changes proposed in this pull request:

  • Add html_block rendering rule so that anchor tags discovered within HTML files have the usa-link--external class applied if their top level domain is something other than .gov

security considerations

No security considerations come to mind.

Testing

The goal for all links within the guides content is to evaluate them to see whether or not they leave the
".gov" domain and if they do, we want to make sure that the class list of the link has `usa-link--external`
applied so that the link gets the external link icon shown when it renders on the page.

Most of that work is handled by the `link_open` rendering rule which scans all of the markdown links and then
another portion is handled by `html_inline` for intances where the HTML is placed inside the markdown document.
The research for issue #348 discovered that when an HTML page is included using the 11ty `include` syntax that
neither `link_open` nor `html_inline` parse links within the included HTML file.

This commit adds a third renderer rule which scans all chunks of HTML to see if it includes any links that
leave the ".gov" domain  and then attempts to make sure the `usa-link--external` class is applied.
@caleywoods caleywoods requested a review from a team as a code owner April 3, 2024 19:56
Copy link
Contributor

@cantsin cantsin left a comment

Choose a reason for hiding this comment

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

LGTM -- tested on main, the usa-link--external links do not show up but with this PR they do 🎉

@caleywoods
Copy link
Contributor Author

I investigated using String.matchAll() which retains the capture groups when using the regex global flag but ultimately decided the code was harder to understand that way.

@caleywoods caleywoods merged commit f6ff1bd into main Apr 16, 2024
6 checks passed
@caleywoods caleywoods deleted the 348-add-icons-eng-hiring branch April 16, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants