diff options
author | Alan Pearce | 2014-09-13 21:49:48 +0100 |
---|---|---|
committer | Alan Pearce | 2014-09-13 21:49:48 +0100 |
commit | 11c75c3e47c4afdd419c13e68fa5e0f795daa715 (patch) | |
tree | 28a74cdf54bbc4d70c2532559be880b69f88e6ce /src | |
parent | 03bc73a64af103b388f50858ad725b9fc6417782 (diff) | |
download | microformats-11c75c3e47c4afdd419c13e68fa5e0f795daa715.tar.lz microformats-11c75c3e47c4afdd419c13e68fa5e0f795daa715.tar.zst microformats-11c75c3e47c4afdd419c13e68fa5e0f795daa715.zip |
Add support for parsing rel attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/microformats/parser.clj | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/microformats/parser.clj b/src/microformats/parser.clj index 97d0376..9801515 100644 --- a/src/microformats/parser.clj +++ b/src/microformats/parser.clj @@ -32,6 +32,13 @@ :class split-ws-attribute)) +(defn element-to-rels + "Get list of rels from an element" + [el] (-> el + :attrs + :rel + split-ws-attribute)) + (defn get-p-value "Get the p-x property value of an element" [el] @@ -134,8 +141,26 @@ [element] (mapv parse-children (html/select element [(html/attr-starts :class "h-")]))) +(defn parse-rel + "Parse rel attributes of an HTML link element" + [element] + (->> element + element-to-rels + (map keyword) + (map #(hash-map % [(-> element :attrs :href)])) + (into {}))) + +(defn select-rels + "Select linking HTML elements with rel attributes" + [html] (html/select html [[#{:a :link} (html/attr? :rel)]])) + +(defn parse-rels + "Parse rel attibutes of a set of HTML link elements" + [elements] + (apply merge-with into (map parse-rel (select-rels elements)))) + (defn parse "Parse a HTML string with microformats" [html] (let [document (html/html-snippet html)] - {:items (parse-h document) :rels {}})) + {:items (parse-h document) :rels (parse-rels document)})) |