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

Refactor external link handling #259

Open
caleywoods opened this issue Sep 26, 2024 · 0 comments
Open

Refactor external link handling #259

caleywoods opened this issue Sep 26, 2024 · 0 comments

Comments

@caleywoods
Copy link
Member

caleywoods commented Sep 26, 2024

On the standards website we use the USWDS usa-link--external class to render an icon to denote that the link in question leaves the .gov top level domain. This class is applied through a small amount of client-side JavaScript once the DOM content is loaded. This approach was originally used for developer speed but a better approach is to move this code into the markdown rendering process so that there's no client-side JS involved which will save a bit a few bytes on the wire.

The markdown parser in use is called markdown-it which implements the CommonMark spec and there are a few times during the rendering process that we need to supply code to make sure that we get all links checked and the class applied. These scenarios/areas are:

  • The link_open rendering step which happens when the renderer encounters the beginning an anchor element in the token stream. This code alone gets most links but there's a couple of cases it doesn't handle. [18F site example code]
  • The next scenario happens when the renderer encounters an HTML block inside of a markdown document. The renderer rule for this is named html_block. [18F site example code]
  • The final scenario happens when the renderer encounters some inline HTML which is a rule named html_inline.[18F site example code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Next
Development

No branches or pull requests

1 participant