Skip to content

Commit 1585c3d

Browse files
committed
Code and test examples for content!
1 parent f0a907d commit 1585c3d

File tree

1 file changed

+134
-1
lines changed
  • apps/components_guide_web/lib/components_guide_web/templates/accessibility_first

1 file changed

+134
-1
lines changed

apps/components_guide_web/lib/components_guide_web/templates/accessibility_first/content.html.md

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
# Semantic Content
22

3+
<style>
4+
article figure {
5+
display: flex;
6+
flex-direction: column;
7+
text-align: center;
8+
align-items: center;
9+
}
10+
</style>
11+
12+
<script type=module>
13+
import * as DOMTesting from "https://cdn.skypack.dev/@testing-library/dom";
14+
window.DOMTesting = DOMTesting;
15+
16+
function* surroundingSourceElements(el) {
17+
let prev = el;
18+
while (prev = prev.previousElementSibling) {
19+
if (prev.matches('h1, h2, h3, h4')) break;
20+
if (prev.matches('pre.language-html')) yield { type: 'html', code: prev.textContent };
21+
if (prev.matches('pre.language-javascript')) yield { type: 'javascript', code: prev.textContent };
22+
}
23+
24+
let next = el;
25+
while (next = next.nextElementSibling) {
26+
if (next.matches('h1, h2, h3, h4')) break;
27+
if (next.matches('pre.language-html')) yield { type: 'html', code: next.textContent };
28+
if (next.matches('pre.language-javascript')) yield { type: 'javascript', code: next.textContent };
29+
}
30+
}
31+
32+
const outputEls = document.querySelectorAll('article output');
33+
console.log(outputEls);
34+
35+
for (const outputEl of outputEls.values()) {
36+
const div = outputEl.appendChild(document.createElement('div'));
37+
div.classList.add('p-4');
38+
39+
console.log('outputEl', outputEl);
40+
const sources = surroundingSourceElements(outputEl);
41+
for (const source of sources) {
42+
const { type, code } = source;
43+
44+
console.log('source', source);
45+
46+
if (type === 'html') {
47+
div.innerHTML = code;
48+
}
49+
50+
if (type === 'javascript') {
51+
const screen = DOMTesting.within(div);
52+
const testFunction = new Function('screen', `return ${code}`);
53+
testFunction(screen).style.border = '2px solid red';
54+
}
55+
}
56+
}
57+
//const htmlSourceElements = document.querySelector('article pre.language-html');
58+
</script>
59+
360
<table class="text-left table-fixed">
461
<caption class="text-3xl pb-4 text-left">Content roles cheatsheet</caption>
562
<thead>
@@ -36,18 +93,94 @@ A crawler service that visits your website on behalf of a search engine like Goo
3693

3794
Semantic HTML elements allow meaning and structure to be determined.
3895

39-
More coming soon…
96+
The better these crawlers can understand, and the more meaning they can infer, the higher they will rank you.
97+
98+
A web page that is just made of `<div>` and `<span>` elements means that the only content they have to use is the text. Which is a lossy and messy process. Better to provide precise and rich elements instead.
4099

41100
## Headings
42101

102+
```html
103+
<h1>One Thousand and One Nights</h1>
104+
```
105+
106+
<output></output>
107+
108+
```javascript
109+
screen.getByRole('heading');
110+
```
111+
43112
## Lists
44113

114+
```html
115+
<ul>
116+
<li>First
117+
<li>Second
118+
<li>Third
119+
</ul>
120+
```
121+
122+
<output></output>
123+
124+
```javascript
125+
screen.getByRole('list');
126+
```
127+
45128
## Term & Definition
46129

130+
```html
131+
<dl>
132+
<dt>Name</dt>
133+
<dd>The Lion King</dd>
134+
135+
<dt>Year Released</dt>
136+
<dd>1994</dd>
137+
138+
<dt>Runtime</dt>
139+
<dd>88 min</dd>
140+
</dl>
141+
```
142+
143+
<output></output>
144+
47145
## Images
48146

147+
```html
148+
<img
149+
alt="The HTML 5 logo"
150+
src="https://unpkg.com/[email protected]/images/svg/html5.svg"
151+
width=200
152+
>
153+
```
154+
155+
<output></output>
156+
157+
```javascript
158+
screen.getByRole('img', { name: /logo/ });
159+
```
160+
49161
## Figure
50162

163+
```html
164+
<figure>
165+
<img
166+
src="https://unpkg.com/[email protected]/images/svg/html5.svg"
167+
width=200
168+
>
169+
<figcaption>The HTML 5 logo</figcaption>
170+
</figure>
171+
```
172+
173+
<output></output>
174+
175+
```javascript
176+
screen.getByRole('figure');
177+
```
178+
51179
## Details & Summary
52180

53181
## Separator
182+
183+
<script type=module>
184+
import * as DOM from "https://cdn.skypack.dev/@testing-library/dom";
185+
console.log("DOM", Object.keys(DOM), DOM.screen);
186+
</script>

0 commit comments

Comments
 (0)