From aca4301fc943aa7c5dd2ba9bb75bfc5b64f09487 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 31 Mar 2023 13:29:13 -0400 Subject: [PATCH] Apply design system styling to autolink links Extends existing ContentTypography plugin to apply standard design system styling to "autolinks", which are treated distinctly from Markdown-formatted links. --- _plugins/content_typography.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/_plugins/content_typography.rb b/_plugins/content_typography.rb index 971d766d..0258ca4a 100644 --- a/_plugins/content_typography.rb +++ b/_plugins/content_typography.rb @@ -3,9 +3,19 @@ module Parser class Kramdown prepend(Module.new do def add_link(el, *args) - el.attr['class'] = [*el.attr['class'], 'usa-link'].join(' ') if el.type == :a + add_link_class!(el) if el.type == :a super(el, *args) end + + def parse_autolink + *children, el = super + add_link_class!(el) + [*children, el] + end + + def add_link_class!(el) + el.attr['class'] = [*el.attr['class'], 'usa-link'].join(' ') + end end) end end