blob: c903165bb805a12511126c59b062429c0631f969 (
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
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
|
(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 "665 3rd St. Suite 207"
(->> "<p class=\"h-adr\">
<span class=\"p-street-address\">665 3rd St.</span>
<span class=\"p-extended-address\">Suite 207</span>
</p>"
snippet :content
(#'microformats.parser/node-to-text)))
(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>"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User") :url '("http://example.com")}}] :rels {}}
(parse "<a class=\"h-card\" href=\"http://example.com\">Example User</a>"))
(expect {:items [{:type ["h-card"] :properties {:name '("Example User")
:photo '("http://example.com/me.png")}}] :rels {}}
(parse "<img class=\"h-card\" alt=\"Example User\" src=\"http://example.com/me.png\"></img>"))
(expect
{:items [{:type ["h-adr"],
:properties {:street-address '("665 3rd St."),
:extended-address '("Suite 207"),
:locality '("San Francisco"),
:region '("CA"),
:postal-code '("94107"),
:country-name '("U.S.A."),
:name '("665 3rd St. Suite 207 San Francisco, CA 94107 U.S.A.")}}]
:rels {}}
(parse "<p class=\"h-adr\">
<span class=\"p-street-address\">665 3rd St.</span>
<span class=\"p-extended-address\">Suite 207</span>
<span class=\"p-locality\">San Francisco</span>,
<span class=\"p-region\">CA</span>
<span class=\"p-postal-code\">94107</span>
<span class=\"p-country-name\">U.S.A.</span>
</p>"))
|