forked from iand/microdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicrodata_test.go
More file actions
690 lines (605 loc) · 23.7 KB
/
microdata_test.go
File metadata and controls
690 lines (605 loc) · 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
package microdata
import (
"bytes"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestParseItemScope(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Person">
<p>My name is <span itemprop="name">Penelope</span>.</p>
</div>`
data := ParseData(html, t)
result := len(data.Items[0].Properties)
expected := 1
if result != expected {
t.Errorf("Result should have been \"%d\", but it was \"%d\"", expected, result)
}
}
func TestParseItemType(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Person">
<p>My name is <span itemprop="name">Penelope</span>.</p>
</div>`
data := ParseData(html, t)
result := data.Items[0].Types[0]
expected := "https://example.com/Person"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseItemRef(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Movie" itemref="properties">
<p><span itemprop="name">Rear Window</span> is a movie from 1954.</p>
</div>
<ul id="properties">
<li itemprop="genre">Thriller</li>
<li itemprop="description">A homebound photographer spies on his neighbours.</li>
</ul>`
var testTable = []struct {
propName string
expected string
}{
{"genre", "Thriller"},
{"description", "A homebound photographer spies on his neighbours."},
}
data := ParseData(html, t)
for _, test := range testTable {
if result := data.Items[0].Properties[test.propName][0].(string); result != test.expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", test.expected, result)
}
}
}
func TestParseItemProp(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Person">
<p>My name is <span itemprop="name">Penelope</span>.</p>
</div>`
data := ParseData(html, t)
result := data.Items[0].Properties["name"][0].(string)
expected := "Penelope"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseItemId(t *testing.T) {
html := `
<ul itemscope itemtype="https://example.com/Book" itemid="urn:isbn:978-0141196404">
<li itemprop="title">The Black Cloud</li>
<li itemprop="author">Fred Hoyle</li>
</ul>`
data := ParseData(html, t)
result := data.Items[0].ID
expected := "urn:isbn:978-0141196404"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseHref(t *testing.T) {
html := `
<html itemscope itemtype="https://example.com/Person">
<head>
<link itemprop="linkTest" href="https://example.com/cde">
<head>
<div>
<a itemprop="aTest" href="https://example.com/abc" /></a>
<area itemprop="areaTest" href="https://example.com/bcd" />
</div>
</div>`
var testTable = []struct {
propName string
expected string
}{
{"aTest", "https://example.com/abc"},
{"areaTest", "https://example.com/bcd"},
{"linkTest", "https://example.com/cde"},
}
data := ParseData(html, t)
for _, test := range testTable {
if result := data.Items[0].Properties[test.propName][0].(string); result != test.expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", test.expected, result)
}
}
}
func TestParseSrc(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Videocast">
<audio itemprop="audioTest" src="https://example.com/abc" />
<embed itemprop="embedTest" src="https://example.com/bcd" />
<iframe itemprop="iframeTest" src="https://example.com/cde"></iframe>
<img itemprop="imgTest" src="https://example.com/def" />
<source itemprop="sourceTest" src="https://example.com/efg" />
<track itemprop="trackTest" src="https://example.com/fgh" />
<video itemprop="videoTest" src="https://example.com/ghi" />
</div>`
var testTable = []struct {
propName string
expected string
}{
{"audioTest", "https://example.com/abc"},
{"embedTest", "https://example.com/bcd"},
{"iframeTest", "https://example.com/cde"},
{"imgTest", "https://example.com/def"},
{"sourceTest", "https://example.com/efg"},
{"trackTest", "https://example.com/fgh"},
{"videoTest", "https://example.com/ghi"},
}
data := ParseData(html, t)
for _, test := range testTable {
if result := data.Items[0].Properties[test.propName][0].(string); result != test.expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", test.expected, result)
}
}
}
func TestParseMetaContent(t *testing.T) {
html := `
<html itemscope itemtype="https://example.com/Person">
<meta itemprop="length" content="1.70" />
</html>`
data := ParseData(html, t)
result := data.Items[0].Properties["length"][0].(string)
expected := "1.70"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseValue(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Container">
<data itemprop="capacity" value="80">80 liters</data>
<meter itemprop="volume" min="0" max="100" value="25">25%</meter>
</div>`
var testTable = []struct {
propName string
expected string
}{
{"capacity", "80"},
{"volume", "25"},
}
data := ParseData(html, t)
for _, test := range testTable {
if result := data.Items[0].Properties[test.propName][0].(string); result != test.expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", test.expected, result)
}
}
}
func TestParseDatetime(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Person">
<time itemprop="birthDate" datetime="1993-10-02">22 years</time>
</div>`
data := ParseData(html, t)
result := data.Items[0].Properties["birthDate"][0].(string)
expected := "1993-10-02"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseText(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Product">
<span itemprop="price">3.95</span>
</div>`
data := ParseData(html, t)
result := data.Items[0].Properties["price"][0].(string)
expected := "3.95"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseMultiItemTypes(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Park https://example.com/Zoo">
<span itemprop="name">ZooParc Overloon</span>
</div>`
data := ParseData(html, t)
result := len(data.Items[0].Types)
expected := 2
if result != expected {
t.Errorf("Result should have been \"%d\", but it was \"%d\"", expected, result)
}
}
func TestJSON(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Person">
<p>My name is <span itemprop="name">Penelope</span>.</p>
<p>I am <date itemprop="age" value="22">22 years old.</span>.</p>
</div>`
data := ParseData(html, t)
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["https://example.com/Person"],"properties":{"age":["22 years old.."],"name":["Penelope"]},"innerHTML":{"age":["22 years old.."],"name":["Penelope"]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseHTML(t *testing.T) {
buf := bytes.NewBufferString(gallerySnippet)
_, result := ParseHTML(buf, "charset=utf-8", "https://blog.example.com/progress-report")
if result != nil {
t.Errorf("Result should have been nil, but it was \"%s\"", result)
}
}
func TestParseURL(t *testing.T) {
html := `
<div itemscope itemtype="https://example.com/Person">
<p>My name is <span itemprop="name">Penelope</span>.</p>
</div>`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(html))
}))
defer ts.Close()
data, err := ParseURL(ts.URL)
if err != nil {
t.Error(err)
}
result := data.Items[0].Properties["name"][0].(string)
expected := "Penelope"
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestNestedItems(t *testing.T) {
html := `
<div>
<div itemscope itemtype="https://example.com/Person">
<p>My name is <span itemprop="name">Penelope</span>.</p>
<p>I am <date itemprop="age" value="22">22 years old.</span>.</p>
<div itemscope itemtype="https://example.com/Breadcrumb">
<a itemprop="url" href="https://example.com/users/1"><span itemprop="title">profile</span></a>
</div>
</div>
</div>`
data := ParseData(html, t)
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["https://example.com/Person"],"properties":{"age":["22 years old.."],"name":["Penelope"]},"innerHTML":{"age":["22 years old.."],"name":["Penelope"]}},{"type":["https://example.com/Breadcrumb"],"properties":{"title":["profile"],"url":["https://example.com/users/1"]},"innerHTML":{"title":["profile"]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func ParseData(html string, t *testing.T) *Microdata {
r := strings.NewReader(html)
data, err := ParseHTML(r, "charset=utf-8", "https://example.com")
if err != nil {
t.Error(err)
}
return data
}
func TestParseW3CBookSnippet(t *testing.T) {
buf := bytes.NewBufferString(bookSnippet)
data, err := ParseHTML(buf, "charset=utf-8", "")
if err != nil {
t.Error(err)
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["https://vocab.example.net/book"],"properties":{"author":["Peter F. Hamilton"],"pubdate":["1996-01-26"],"title":["The Reality Dysfunction"]},"innerHTML":{"author":["Peter F. Hamilton"],"title":["The Reality Dysfunction"]},"id":"urn:isbn:0-330-34032-8"}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseW3CGalleySnippet(t *testing.T) {
buf := bytes.NewBufferString(gallerySnippet)
data, err := ParseHTML(buf, "charset=utf-8", "")
if err != nil {
t.Error(err)
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["https://n.whatwg.org/work"],"properties":{"license":["https://www.opensource.org/licenses/mit-license.php"],"title":["The house I found."],"work":["/images/house.jpeg"]},"innerHTML":{"title":["The house I found."]}},{"type":["https://n.whatwg.org/work"],"properties":{"license":["https://www.opensource.org/licenses/mit-license.php"],"title":["The mailbox."],"work":["/images/mailbox.jpeg"]},"innerHTML":{"title":["The mailbox."]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseW3CBlogSnippet(t *testing.T) {
buf := bytes.NewBufferString(blogSnippet)
data, err := ParseHTML(buf, "charset=utf-8", "https://blog.example.com/progress-report")
if err != nil {
t.Error(err)
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["https://schema.org/BlogPosting"],"properties":{"comment":[{"type":["https://schema.org/UserComments"],"properties":{"commentTime":["2013-08-29"],"creator":[{"type":["https://schema.org/Person"],"properties":{"name":["Greg"]},"innerHTML":{"name":["Greg"]}}],"url":["https://blog.example.com/progress-report#c1"]}},{"type":["https://schema.org/UserComments"],"properties":{"commentTime":["2013-08-29"],"creator":[{"type":["https://schema.org/Person"],"properties":{"name":["Charlotte"]},"innerHTML":{"name":["Charlotte"]}}],"url":["https://blog.example.com/progress-report#c2"]}}],"datePublished":["2013-08-29"],"headline":["Progress report"],"url":["https://blog.example.com/progress-report?comments=0"]},"innerHTML":{"headline":["Progress report"]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
// TestInnerHTML verifies that InnerHTML is captured for text-based properties
func TestInnerHTML(t *testing.T) {
html := `
<div itemscope itemtype="https://schema.org/Event">
<span itemprop="name">Test Event</span>
<div itemprop="description"><p>First paragraph.</p><p>Second paragraph.</p></div>
</div>`
data := ParseData(html, t)
// Check property value (innerText)
if data.Items[0].Properties["name"][0].(string) != "Test Event" {
t.Errorf("Expected name to be 'Test Event', got %v", data.Items[0].Properties["name"][0])
}
// Check InnerHTML for name (simple text content)
if data.Items[0].InnerHTML["name"][0] != "Test Event" {
t.Errorf("Expected name InnerHTML to be 'Test Event', got %v", data.Items[0].InnerHTML["name"][0])
}
// Check property value (innerText collapses HTML structure)
descValue := data.Items[0].Properties["description"][0].(string)
if descValue != "First paragraph.Second paragraph." {
t.Errorf("Expected description innerText to be 'First paragraph.Second paragraph.', got %v", descValue)
}
// Check InnerHTML preserves HTML structure
descHTML := data.Items[0].InnerHTML["description"][0]
if descHTML != "<p>First paragraph.</p><p>Second paragraph.</p>" {
t.Errorf("Expected description InnerHTML to be '<p>First paragraph.</p><p>Second paragraph.</p>', got %v", descHTML)
}
}
// TestInnerHTMLNotSetForAttributeBasedProperties verifies that InnerHTML is empty for attribute-based properties
func TestInnerHTMLNotSetForAttributeBasedProperties(t *testing.T) {
html := `
<div itemscope itemtype="https://schema.org/Event">
<a itemprop="url" href="https://example.com/event">Event Link</a>
<img itemprop="image" src="https://example.com/image.jpg">
<meta itemprop="startDate" content="2024-01-01">
</div>`
data := ParseData(html, t)
// URL should be from href attribute, no InnerHTML
if data.Items[0].Properties["url"][0].(string) != "https://example.com/event" {
t.Errorf("Expected url to be 'https://example.com/event', got %v", data.Items[0].Properties["url"][0])
}
if len(data.Items[0].InnerHTML["url"]) != 0 {
t.Errorf("Expected no InnerHTML for url (href-based), got %v", data.Items[0].InnerHTML["url"])
}
// Image should be from src attribute, no InnerHTML
if data.Items[0].Properties["image"][0].(string) != "https://example.com/image.jpg" {
t.Errorf("Expected image to be 'https://example.com/image.jpg', got %v", data.Items[0].Properties["image"][0])
}
if len(data.Items[0].InnerHTML["image"]) != 0 {
t.Errorf("Expected no InnerHTML for image (src-based), got %v", data.Items[0].InnerHTML["image"])
}
// Meta content should not have InnerHTML
if data.Items[0].Properties["startDate"][0].(string) != "2024-01-01" {
t.Errorf("Expected startDate to be '2024-01-01', got %v", data.Items[0].Properties["startDate"][0])
}
if len(data.Items[0].InnerHTML["startDate"]) != 0 {
t.Errorf("Expected no InnerHTML for startDate (content-based), got %v", data.Items[0].InnerHTML["startDate"])
}
}
func BenchmarkParser(b *testing.B) {
buf := bytes.NewBufferString(blogSnippet)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := ParseHTML(buf, "utf-8", "https://blog.example.com/progress-report")
if err != nil && err != io.EOF {
b.Error(err)
}
}
}
func TestParseMicrodataPersonSnippet(t *testing.T) {
buf := bytes.NewBufferString(personSnippet)
data, err := ParseHTML(buf, "charset=utf-8", "https://jsonld.com/person/")
if err != nil {
t.Error(err)
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["Person"],"properties":{"@context":["https://schema.org"],"address":[{"type":["PostalAddress"],"properties":{"addressLocality":["Colorado Springs"],"addressRegion":["CO"],"postalCode":["80840"],"streetAddress":["100 Main Street"]}}],"alumniOf":["Dartmouth"],"birthDate":["1979-10-12"],"birthPlace":["Philadelphia, PA"],"colleague":["https://www.example.com/JohnColleague.html","https://www.example.com/JameColleague.html"],"email":["info@example.com"],"gender":["female"],"height":["72 inches"],"image":["janedoe.jpg"],"jobTitle":["Research Assistant"],"memberOf":["Republican Party"],"name":["Jane Doe"],"nationality":["Albanian"],"sameAs":["https://www.facebook.com/","https://www.linkedin.com/","https://twitter.com/","https://instagram.com/","https://plus.google.com/"],"telephone":["(123) 456-6789"],"url":["https://www.example.com"]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseMicrodataRecipeSnippet(t *testing.T) {
buf := bytes.NewBufferString(recipeSnippet)
data, err := ParseHTML(buf, "charset=utf-8", "https://jsonld.com/recipe/")
if err != nil {
t.Error(err)
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["Recipe"],"properties":{"@context":["https://schema.org"],"author":["Jake Smith"],"cookTime":["PT2H"],"datePublished":["2015-05-18"],"description":["Your recipe description goes here"],"image":["https://www.example.com/images.jpg"],"interactionStatistic":[{"type":["InteractionCounter"],"properties":{"interactionType":["https://schema.org/Comment"],"userInteractionCount":["5"]}}],"name":["Rand's Cookies"],"nutrition":[{"type":["NutritionInformation"],"properties":{"calories":["1200 calories"],"carbohydrateContent":["12 carbs"],"fatContent":["9 grams fat"],"proteinContent":["9 grams of protein"]}}],"prepTime":["PT15M"],"recipeIngredient":["ingredient 1","ingredient 2","ingredient 3","ingredient 4","ingredient 5"],"recipeInstructions":["This is the long part, etc."],"recipeYield":["12 cookies"]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
func TestParseMicrodataMultipleSnippet(t *testing.T) {
buf := bytes.NewBufferString(multipleSnippet)
data, err := ParseHTML(buf, "charset=utf-8", "https://www.w3.org/TR/json-ld11/")
if err != nil {
t.Error(err)
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
result := string(b)
expected := `{"items":[{"type":["Person"],"properties":{"@context":["https://schema.org/"],"@id":["https://digitalbazaar.com/author/dlongley/"],"name":["Dave Longley"]}},{"type":["Person"],"properties":{"@context":["https://schema.org/"],"@id":["https://greggkellogg.net/foaf#me"],"name":["Gregg Kellogg"]}}]}`
if result != expected {
t.Errorf("Result should have been \"%s\", but it was \"%s\"", expected, result)
}
}
// This HTML snippet is taken from the W3C Working Group website at https://html.spec.whatwg.org/multipage/microdata.html#global-identifiers-for-items
var bookSnippet = `
<dl itemscope
itemtype="https://vocab.example.net/book"
itemid="urn:isbn:0-330-34032-8">
<dt>Title</dt>
<dd itemprop="title">The Reality Dysfunction</dd>
<dt>Author</dt>
<dd itemprop="author">Peter F. Hamilton</dd>
<dt>Publication date</dt>
<dd><time itemprop="pubdate" datetime="1996-01-26">26 January 1996</time></dd>
</dl>`
// This HTML snippet is taken from the W3C Working Group website at https://html.spec.whatwg.org/multipage/microdata.html#associating-names-with-items
var gallerySnippet = `
<!DOCTYPE HTML>
<html>
<head>
<title>Photo gallery</title>
</head>
<body>
<h1>My photos</h1>
<figure itemscope itemtype="https://n.whatwg.org/work" itemref="licenses">
<img itemprop="work" src="images/house.jpeg" alt="A white house, boarded up, sits in a forest.">
<figcaption itemprop="title">The house I found.</figcaption>
</figure>
<figure itemscope itemtype="https://n.whatwg.org/work" itemref="licenses">
<img itemprop="work" src="images/mailbox.jpeg" alt="Outside the house is a mailbox. It has a leaflet inside.">
<figcaption itemprop="title">The mailbox.</figcaption>
</figure>
<footer>
<p id="licenses">All images licensed under the <a itemprop="license"
href="https://www.opensource.org/licenses/mit-license.php">MIT
license</a>.</p>
</footer>
</body>
</html>`
// This HTML document is taken from the W3C Working Group website at https://html.spec.whatwg.org/multipage/microdata.html#json
var blogSnippet = `
<!DOCTYPE HTML>
<title>My Blog</title>
<article itemscope itemtype="https://schema.org/BlogPosting">
<header>
<h1 itemprop="headline">Progress report</h1>
<p><time itemprop="datePublished" datetime="2013-08-29">today</time></p>
<link itemprop="url" href="?comments=0">
</header>
<p>All in all, he's doing well with his swim lessons. The biggest thing was he had trouble
putting his head in, but we got it down.</p>
<section>
<h1>Comments</h1>
<article itemprop="comment" itemscope itemtype="https://schema.org/UserComments" id="c1">
<link itemprop="url" href="#c1">
<footer>
<p>Posted by: <span itemprop="creator" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">Greg</span>
</span></p>
<p><time itemprop="commentTime" datetime="2013-08-29">15 minutes ago</time></p>
</footer>
<p>Ha!</p>
</article>
<article itemprop="comment" itemscope itemtype="https://schema.org/UserComments" id="c2">
<link itemprop="url" href="#c2">
<footer>
<p>Posted by: <span itemprop="creator" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">Charlotte</span>
</span></p>
<p><time itemprop="commentTime" datetime="2013-08-29">5 minutes ago</time></p>
</footer>
<p>When you say "we got it down"...</p>
</article>
</section>
</article>`
// This HTML document is taken from the "Steal Our JSON-LD" website at https://jsonld.com/person/
var personSnippet = `<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Person",
"address": {
"@type": "PostalAddress",
"addressLocality": "Colorado Springs",
"addressRegion": "CO",
"postalCode": "80840",
"streetAddress": "100 Main Street"
},
"colleague": [
"https://www.example.com/JohnColleague.html",
"https://www.example.com/JameColleague.html"
],
"email": "info@example.com",
"image": "janedoe.jpg",
"jobTitle": "Research Assistant",
"name": "Jane Doe",
"alumniOf": "Dartmouth",
"birthPlace": "Philadelphia, PA",
"birthDate": "1979-10-12",
"height": "72 inches",
"gender": "female",
"memberOf": "Republican Party",
"nationality": "Albanian",
"telephone": "(123) 456-6789",
"url": "https://www.example.com",
"sameAs" : [ "https://www.facebook.com/",
"https://www.linkedin.com/",
"https://twitter.com/",
"https://instagram.com/",
"https://plus.google.com/"]
}
</script>`
// This HTML document is taken from the "Steal Our JSON-LD" website at https://jsonld.com/recipe/
var recipeSnippet = `<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Recipe",
"author": "Jake Smith",
"cookTime": "PT2H",
"datePublished": "2015-05-18",
"description": "Your recipe description goes here",
"image": "https://www.example.com/images.jpg",
"recipeIngredient": [
"ingredient 1",
"ingredient 2",
"ingredient 3",
"ingredient 4",
"ingredient 5"
],
"interactionStatistic": {
"@type": "InteractionCounter",
"interactionType": "https://schema.org/Comment",
"userInteractionCount": "5"
},
"name": "Rand's Cookies",
"nutrition": {
"@type": "NutritionInformation",
"calories": "1200 calories",
"carbohydrateContent": "12 carbs",
"proteinContent": "9 grams of protein",
"fatContent": "9 grams fat"
},
"prepTime": "PT15M",
"recipeInstructions": "This is the long part, etc.",
"recipeYield": "12 cookies"
}
</script>`
// This HTML document is taken from the "W3.org" website at https://www.w3.org/TR/json-ld11/
var multipleSnippet = `<p>Data describing Dave</p>
<script id="dave" type="application/ld+json">
{
"@context": "https://schema.org/",
"@id": "https://digitalbazaar.com/author/dlongley/",
"@type": "Person",
"name": "Dave Longley"
}
</script>
<p>Data describing Gregg</p>
<script id="gregg" type="application/ld+json">
{
"@context": "https://schema.org/",
"@id": "https://greggkellogg.net/foaf#me",
"@type": "Person",
"name": "Gregg Kellogg"
}
</script>`