Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add markdown lint rule to prevent shortcut reference link bug
Redcarpet has an issue whereby shortcut reference links [1] followed by parentheses are incorrectly parsed. [2] ``` [foo] (bar) [foo: http://example.com ``` ...would be parsed as `<a href="bar">foo</a>`. Screenshot of the issue: ![](https://user-images.githubusercontent.com/5111927/112168271-0dcb4c00-8be9-11eb-9235-026c68af1019.png) We initially worked around the issue by swapping out the markdown library Redcarpet for Markdown, but this has meant we're missing out on accessibility improvements built into tech_docs_gem, so we needed a new approach. This new linting rule - which is called as part of the lint_markdown rake task, and fails the build if occurrences are found - detects shortcut reference links followed by parentheses. It suggests a fix of converting these to collapsed reference links by appending `[]`, which removes any ambiguity for the parser. Example output: ``` source/manual/howto-find-hardcoded-markup-govspeak.html.md:12: no-parentheses-after-shortcut-reference-link No parentheses allowed after shortcut reference link (use collapsed reference link instead, e.g. `[foo]` => `[foo][]`) source/manual/architecture-deep-dive.html.md:248: no-parentheses-after-shortcut-reference-link No parentheses allowed after shortcut reference link (use collapsed reference link instead, e.g. `[foo]` => `[foo][]`) ``` This rule is an implementation of a suggestion I made to the open source project in September 2020: markdownlint/markdownlint#351 It uses a custom rule code `MY001`, as suggested in the docs. [3] Finally, I fixed up the two instances which this rule found in the repo. Future instances should be prevented from being added, via the CI process. [1]: https://github.github.com/gfm/#shortcut-reference-link [2]: vmg/redcarpet#471 [3]: https://github.com/markdownlint/markdownlint/blob/master/docs/creating_rules.md
- Loading branch information