Skip to content

Commit d8fffc5

Browse files
authored
Merge pull request #547 from cmbuckley/svg-reader-mode
SVG Reader Mode
2 parents 01b69e7 + 088a907 commit d8fffc5

12 files changed

Lines changed: 55 additions & 12 deletions

File tree

_data/fingerprints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ icons: 715715b9
33
maths: 5414f235
44
scripts: 5220ed99
55
search: b74b56ab
6-
style: 3c9360bb
6+
style: 7179d42c

_includes/figure.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</video>
1717
{%- elsif include.img or include.object %}
1818
{% if include.url %}<a href="{{ include.url }}">{%- endif -%}
19+
1920
{%- if include.img %}<img src="{{ include.img }}"
2021
{%- else %}<object role="img" data="{{ include.object }}"
2122
{%- endif %}
@@ -24,7 +25,12 @@
2425
{%- if include.alt %}{{ include.alt }}
2526
{%- elsif include.url %}{{ include.caption | default: 'View larger image' }}
2627
{%- endif -%}
27-
">{% if include.object %}</object>{%- endif %}
28+
">
29+
30+
{%- if include.object %}</object>
31+
<img src="{{ include.object }}" alt="" class="rm-only" />
32+
{%- endif -%}
33+
2834
{%- if include.url %}</a>{% endif %}
2935
{%- endif %}
3036
{%- if include.caption %}

_includes/v.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- unless site.suppress_fingerprints -%}
22
?v=
33

4-
{%- assign fingerprints = 'icons: 715715b9,maths: 5414f235,scripts: 5220ed99,search: b74b56ab,style: 3c9360bb' | split: ',' -%}
4+
{%- assign fingerprints = 'icons: 715715b9,maths: 5414f235,scripts: 5220ed99,search: b74b56ab,style: 7179d42c' | split: ',' -%}
55
{%- assign found = false -%}
66

77
{%- if jekyll.environment == 'production' -%}

_posts/2026-01-10-making-svgs-dark-mode-reading-mode-friendly.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ image:
99
meta:
1010
src: /files/2026/01/flowchart.png
1111
alt: A diagram in light and dark modes
12-
last_modified_at: 2026-01-10 23:41 +0000
12+
last_modified_at: 2026-01-12 22:39 +0000
1313
---
1414

1515
I use Scalable Vector Graphics (SVGs) on this site as they're an effective format for diagrams; they can be easily modified, styled, animated and localised.
@@ -48,7 +48,9 @@ There's no way to apply CSS to the reading mode view, so any background colour n
4848
</svg>
4949
```
5050

51-
Again, this isn't exactly a satisfying solution, but it does mean a single SVG can be used in all rendering contexts.
51+
Again, this isn't exactly a satisfying solution, but it does mean a single SVG can be used in all rendering contexts. Here's an example:
52+
53+
{% include figure.html object="/files/2026/01/example.svg" alt="A rectangle labelled 'Hello world'" %}
5254

5355
Have I missed a neater solution? Is there something I've not considered with this approach? Do other browsers run into the same (or different) problems?
5456

_sass/_custom.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ mark {
2828
@extend %sr-only;
2929
}
3030

31+
.rm-only {
32+
@extend %rm-only;
33+
left: 0.1px;
34+
}
35+
3136
.search-results:empty {
3237
@extend %loading;
3338
margin: 0 auto 1.5em;

_sass/partials/_mixins.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// Screen reader only content
22
%sr-only {
3+
@extend %rm-only;
4+
height: 1px;
5+
clip-path: inset(50%);
6+
}
7+
8+
// Reading mode only content
9+
%rm-only {
310
position: absolute;
411
margin: -1px 0 0 -1px;
512
padding: 0;
613
display: block;
714
width: 1px;
8-
height: 1px;
915
font-size: 1px;
1016
line-height: 1px;
1117
overflow: hidden;
12-
clip: rect(0,0,0,0);
1318
border: 0;
1419
outline: 0;
1520
}

files/2007/08/catenary-wheel.svg

Lines changed: 2 additions & 0 deletions
Loading

files/2007/08/catenary.svg

Lines changed: 2 additions & 0 deletions
Loading

files/2015/05/4-faces.svg

Lines changed: 7 additions & 5 deletions
Loading

files/2020/04/trrs.svg

Lines changed: 2 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)