Skip to content

Commit 724c175

Browse files
authored
Merge pull request #12746 from quarto-dev/bugfix/726
a11y - provide callout type in screen-reader-only class when needed.
2 parents b278972 + 67408b3 commit 724c175

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

news/changelog-1.8.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ All changes included in 1.8:
1010

1111
### `html`
1212

13-
- ([#678](https://github.com/quarto-dev/quarto-cli/issues/678)): Provide appropriate `aria-label` to search button.
13+
- ([#678](https://github.com/quarto-dev/quarto-cli/issues/678)): a11y - Provide appropriate `aria-label` to search button.
14+
- ([#726](https://github.com/quarto-dev/quarto-cli/issues/726)): a11y - Provide `.screen-reader-only` callout type when callout text doesn't naturally include the type.
1415
- ([#10983](https://github.com/quarto-dev/quarto-cli/issues/10983)): Fix spacing inconsistency between paras and first section headings.
1516
- ([#12259](https://github.com/quarto-dev/quarto-cli/issues/12259)): Fix conflict between `html-math-method: katex` and crossref popups (author: @benkeks).
1617
- ([#12734](https://github.com/quarto-dev/quarto-cli/issues/12734)): `highlight-style` now correctly supports setting a different `light` and `dark`.

src/resources/filters/modules/callouts.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ local calloutidx = 1
191191
local function calloutDiv(node)
192192
node = decorate_callout_title_with_crossref(node)
193193

194+
local needs_screen_reader_callout_type = true
195+
if is_valid_ref_type(refType(node.attr.identifier)) then
196+
needs_screen_reader_callout_type = false
197+
end
198+
194199
-- the first heading is the title
195200
local div = pandoc.Div({})
196201
local c = quarto.utils.as_blocks(node.content)
@@ -218,6 +223,7 @@ local function calloutDiv(node)
218223

219224
if calloutAppearance == _quarto.modules.constants.kCalloutAppearanceDefault and pandoc.utils.stringify(title) == "" and not found then
220225
title = quarto.utils.as_inlines(pandoc.Plain(displayName(node.type)))
226+
needs_screen_reader_callout_type = false
221227
end
222228

223229
-- Make an outer card div and transfer classes and id
@@ -262,6 +268,12 @@ local function calloutDiv(node)
262268
-- show a titled callout
263269
if title ~= nil and (pandoc.utils.type(title) == "string" or next(title) ~= nil) then
264270

271+
if needs_screen_reader_callout_type then
272+
-- add a screen reader callout type
273+
local srCalloutType = pandoc.Span(pandoc.Str(displayName(callout_type)))
274+
srCalloutType.attr.classes:insert("screen-reader-only")
275+
title:insert(1, srCalloutType)
276+
end
265277
-- mark the callout as being titleed
266278
calloutDiv.attr.classes:insert("callout-titled")
267279

src/resources/formats/html/bootstrap/_bootstrap-rules.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,3 +2192,15 @@ a {
21922192
font-weight: $link-weight;
21932193
text-decoration: $link-decoration;
21942194
}
2195+
2196+
// screen-reader-only, cf https://github.com/quarto-dev/quarto-cli/issues/726#issuecomment-1112486100
2197+
.screen-reader-only {
2198+
position: absolute;
2199+
clip: rect(0 0 0 0);
2200+
border: 0;
2201+
height: 1px;
2202+
margin: -1px;
2203+
overflow: hidden;
2204+
padding: 0;
2205+
width: 1px;
2206+
}

tests/docs/smoke-all/2024/05/16/9701.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _quarto:
55
html:
66
ensureFileRegexMatches:
77
- []
8-
- ["Note"]
8+
- ["Note\\s+</div>"]
99
---
1010

1111
::: {.callout-note icon=false}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
format: html
3+
title: Hello
4+
_quarto:
5+
tests:
6+
html:
7+
ensureHtmlElements:
8+
- [div.callout.callout-note div.callout-title-container span.screen-reader-only]
9+
---
10+
11+
::: callout-note
12+
13+
## Title
14+
15+
This is a callout.
16+
17+
:::

0 commit comments

Comments
 (0)