blob: 05cc05220421d85eb519de336bdd7ac43ed6db63 (
plain)
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
|
(ns microformats.parser-expectations
(:require [expectations :refer :all]
[microformats.parser :refer :all]
[net.cgrand.enlive-html :refer [html-snippet]]))
(defn- snippet
[html]
(first (html-snippet html)))
(expect [:location]
(into [] ((classes-to-props "p-") ["someclass" "p-location" "someotherclass"])))
(expect [:location :name]
(into [] ((classes-to-props "p-") ["someclass" "p-location" "someotherclass" "p-name"])))
(expect "Foo <strong>bar</strong>"
(apply str (#'microformats.parser/node-to-html '("Foo " {:tag :strong, :attrs nil, :content ("bar")}))))
(expect {:name '("Name")}
(parse-p (snippet "<p class=\"p-name\"><span class=\"value\">Name</span></p>")))
(expect {:name '("Name Endname")}
(parse-p (snippet "<p class=\"p-name\"><span class=\"value\">Name</span> (this should not be included) <span class=\"value\">Endname</span></p>")))
(expect {:name '("Example User")}
(parse-p (snippet "<p class=\"p-name\">Example User</p>")))
(expect {:nickname '("exuser")}
(parse-p (snippet "<p class=\"p-nickname\">exuser</p>")))
(expect {:name '("Example User")}
(parse-p (snippet "<img class=\"p-name\" alt=\"Example User\">")))
(expect {:name '("Example User")}
(parse-p (snippet "<abbr class=\"p-name\" title=\"Example User\">@example</abbr>")))
(expect {:name '("@example")}
(parse-p (snippet "<abbr class=\"p-name\">@example</abbr>")))
(expect {:name '("Example User")}
(parse-p (snippet "<data class=\"p-name\" value=\"Example User\"></data>")))
(expect {:name '("Example User")}
(parse-p (snippet "<data class=\"p-name\">Example User</data>")))
(expect {:name '("")}
(parse-p (snippet "<br class=\"p-name\"/>")))
(expect {:name '("")}
(parse-p (snippet "<hr class=\"p-name\"/>")))
(expect {:url '("http://example.com")}
(parse-u (snippet "<a class=\"u-url\" href=\"http://example.com\">Awesome example website</a>")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<img class=\"u-photo\" src=\"http://example.com/someimage.png\">")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<area class=\"u-photo\" href=\"http://example.com/someimage.png\"></area>")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<object class=\"u-photo\" data=\"http://example.com/someimage.png\"></object>")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<abbr class=\"u-photo\" title=\"http://example.com/someimage.png\"></abbr>")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<abbr class=\"u-photo\">http://example.com/someimage.png</abbr>")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<data class=\"u-photo\" value=\"http://example.com/someimage.png\"></data>")))
(expect {:photo '("http://example.com/someimage.png")}
(parse-u (snippet "<data class=\"u-photo\">http://example.com/someimage.png</data>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<time class=\"dt-start\" datetime=\"2012-08-05T14:50\"></time>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<time class=\"dt-start\">2012-08-05T14:50</time>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<ins class=\"dt-start\" datetime=\"2012-08-05T14:50\"></ins>")))
(expect {:end '("2012-08-05T18:00")}
(parse-dt (snippet "<del class=\"dt-end\" datetime=\"2012-08-05T18:00\"></del>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<abbr class=\"dt-start\" title=\"2012-08-05T14:50\"></abbr>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<abbr class=\"dt-start\">2012-08-05T14:50</abbr>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<data class=\"dt-start\" value=\"2012-08-05T14:50\"></data>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<data class=\"dt-start\">2012-08-05T14:50</data>")))
(expect {:start '("2012-08-05T14:50")}
(parse-dt (snippet "<input class=\"dt-start\" value=\"2012-08-05T14:50\">")))
(expect {:content '({:html "Here is a load of <strong>embedded markup</strong>" :value "Here is a load of embedded markup"})}
(parse-e (snippet "<div class=\"e-content\">Here is a load of <strong>embedded markup</strong></div>")))
(expect {:author ["http://example.com/a"]}
(parse-rels (html-snippet "<a rel=\"author\" href=\"http://example.com/a\">author a</a>")))
(expect {:author ["http://example.com/a" "http://example.com/b"]}
(parse-rels (html-snippet "<a rel=\"author\" href=\"http://example.com/a\">author a</a>
<a rel=\"author\" href=\"http://example.com/b\">author b</a>")))
(expect {:items [] :rels {}}
(parse ""))
(expect {:items [{:properties {:name '("Example User")} :type ["h-card"]}] :rels {}}
(parse "<div class=\"h-card\"><p class=\"p-name\">Example User</p></div>"))
(expect {:items [{:properties {:name '("Example User")} :type ["h-card"]}] :rels {}}
(parse "<div class=\"h-card\"><p class=\"p-name\"> Example User </p></div>"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")}}] :rels {}}
(parse "<p class=\"h-card\">Example User</p>"))
|