Skip to content

Commit

Permalink
Enable focus + keyboard scroll on all code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Feb 1, 2023
1 parent 9fda6da commit 193f37f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
12 changes: 11 additions & 1 deletion lib/marked-renderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const { marked } = require('marked')

/** A custom renderer that avoids wrapping `<img>` tags in `<p>` tags */
/**
* Custom markdown renderer that avoids wrapping `<img>` image
* tags (or code with syntax highlighting) in `<p>` paragraphs
*/
class DesignSystemRenderer extends marked.Renderer {
code (code, language, isEscaped) {
return !language
? super.html(code)
: super.code(code, language, isEscaped)
.replace('<code', '<code tabindex="0"')
}

paragraph (text) {
return text.trim().startsWith('<img')
? super.html(`${text}\n`)
Expand Down
14 changes: 7 additions & 7 deletions src/get-started/updating-your-code/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the skip link by rendering your own,
which can include custom <code>text</code>
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block skipLink %}
{{ govukSkipLink({ text: "custom text" }) }}
{% endblock %}{% endraw %}</code></pre>
Expand All @@ -83,7 +83,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the header component by rendering your own,
which can include custom <code>classes</code>
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block header %}
{{ govukHeader({ classes: "app-custom-classes" }) }}
{% endblock %}{% endraw %}</code></pre>
Expand All @@ -99,7 +99,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the header component by rendering your own,
which can include custom <code>homepageUrl</code>
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block header %}
{{ govukHeader({ homepageUrl: "/custom-url" }) }}
{% endblock %}{% endraw %}</code></pre>
Expand All @@ -121,7 +121,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the header component by rendering your own,
which can include a custom <code>serviceName</code>
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block header %}
{{ govukHeader({ serviceName: "Custom service name" }) }}
{% endblock %}{% endraw %}</code></pre>
Expand All @@ -137,7 +137,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the header component by rendering your own,
which can include a custom <code>navigation</code>
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block header %}
{{ govukHeader({ navigation: [] }) }}
{% endblock %}{% endraw %}</code></pre>
Expand Down Expand Up @@ -174,7 +174,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the footer component by rendering your own,
which can include a custom <code>navigation</code>
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block header %}
{{ govukFooter({ navigation: [] }) }}
{% endblock %}{% endraw %}</code></pre>
Expand All @@ -190,7 +190,7 @@ The main change is changing variables from [snake_case](https://en.wikipedia.org
You can now entirely replace the footer component by rendering your own,
which can include custom <code>meta</code> links
</p>
<pre><code>{% raw %}
<pre><code tabindex="0">{% raw %}
{% block header %}
{{ govukFooter({ meta: [] }) }}
{% endblock %}{% endraw %}</code></pre>
Expand Down
9 changes: 0 additions & 9 deletions src/stylesheets/components/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,4 @@
outline: 1px solid transparent;
color: $govuk-text-colour;
background-color: govuk-colour("light-grey");

&:focus {
border: $govuk-focus-width solid $govuk-input-border-colour;
outline: $govuk-focus-width solid $govuk-focus-colour;
}

.js-enabled & {
padding-top: 45px; // Allow extra space for the copy code button
}
}
9 changes: 9 additions & 0 deletions src/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ pre code {
background-color: $app-light-grey;
font-size: 16px;
@include govuk-responsive-margin(4, "bottom");

&:focus {
border: $govuk-focus-width solid $govuk-input-border-colour;
outline: $govuk-focus-width solid $govuk-focus-colour;
}

.js-enabled [data-module="app-copy"] & {
padding-top: 45px; // Allow extra space for the copy code button
}
}

.app-prose-scope {
Expand Down

0 comments on commit 193f37f

Please sign in to comment.