all repos — archive/microformats @ cba956458645f10a83d9f44f40b30e422de8ec63

Incomplete Clojure microformats library

src/microformats/parser.clj (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(ns microformats.parser
  (:require [net.cgrand.enlive-html :as html]))

;;; Turn string into stream

(defn parse-p
  "Parse p-* classes within HTML element."
  [element]
  (hash-map :properties (hash-map :name (first (:content (first (html/select element [:.p-name])))))))

(defn parse-h
  "Parse h-* classes within a HTML document."
  [html]
  (mapv parse-p (html/select html [:.h-card])))

(defn parse
  "Parse a HTML string with microformats"
  [html]
  (let [document (html/html-snippet html)]
    {:items (parse-h document) :rels {}}))