diff options
author | Alan Pearce | 2014-09-28 20:57:02 +0100 |
---|---|---|
committer | Alan Pearce | 2014-09-28 20:57:02 +0100 |
commit | c773b522ebafbdfc9019898a83d74503700352e5 (patch) | |
tree | 726bec2990c3ae4778be62a271be770be724cb2a /src | |
parent | e2571e582fe302337924ecc6aea27505b94b982a (diff) | |
download | microformats-c773b522ebafbdfc9019898a83d74503700352e5.tar.lz microformats-c773b522ebafbdfc9019898a83d74503700352e5.tar.zst microformats-c773b522ebafbdfc9019898a83d74503700352e5.zip |
Use lists instead of vectors
Allows for some simplification.
Diffstat (limited to 'src')
-rw-r--r-- | src/microformats/parser.clj | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index 8d5bb10..ba07fcf 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -188,8 +188,7 @@ [element] (->> element element-to-classes - (r/filter (prefixed-by? "h-")) - (into []))) + (filter (prefixed-by? "h-")))) (defn- parse-implied-name "Get the implied name of an entity" @@ -270,13 +269,13 @@ (hash-map :type (get-mf-names element) :properties (get-mf-properties element))) -(defn select-h - "Select top-level h-* elements within a HTML element." - [loc] - (when (not (z/end? loc)) - (if (some->> loc z/node first :attrs :class (re-matcher #"(?:^|\s) h-\w")) - (z/node loc) - (recur (z/next loc))))) +(defn map-h + "Map fn to top-level h-* elements within a HTML element." + [fn loc] + (if (some->> loc z/node :attrs :class (re-matcher #"(?:^|\s) h-\w")) + (list (fn (z/node loc))) + (when (not (z/end? loc)) + (recur fn (z/next loc))))) (defn parse-rel "Parse rel attributes of an HTML link element" @@ -300,4 +299,4 @@ "Parse a HTML string with microformats" [html] (let [document (html/html-snippet (str/trim html))] - {:items (mapv parse-h (some->> document z/xml-zip select-h)) :rels (parse-rels document)})) + {:items (some->> document first z/xml-zip (map-h parse-h)) :rels (parse-rels document)})) |