diff options
| author | Asko Nõmm <asko@repl.ee> | 2025-10-19 18:14:01 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-19 18:14:01 +0300 |
| commit | 35de9bc8aaaa165ec3f2efb04691bdca3dd5e446 (patch) | |
| tree | 205661db6741879a8b04c8023350fcb0a07cf0e6 /src/dompa | |
| parent | 9276f08031242c13ee25c8f89c22e4f65cff004b (diff) | |
| parent | ad98bfddb09c6be641ff6755bb8caefc50f1636d (diff) | |
Merge pull request #4 from askonomm/3-attribute-value-containing-forward-slash-breaks-parsingv1.0.1
#3: Fixes an issue where if the attribute value contained forward sla…
Diffstat (limited to 'src/dompa')
| -rw-r--r-- | src/dompa/coordinates.cljc | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/dompa/coordinates.cljc b/src/dompa/coordinates.cljc index ebe9b65..e5ca5e8 100644 --- a/src/dompa/coordinates.cljc +++ b/src/dompa/coordinates.cljc @@ -265,13 +265,16 @@ class=\"test\" ```" [html] - (->> (subs html 1) - (take-while #(not (contains? #{\> \/} %))) - (partition-by #(= % \space)) - (drop 1) - flatten - (apply str) - str/trim)) + (let [attrs-html (->> (subs html 1) + (take-while #(not (contains? #{\>} %))) + (partition-by #(= % \space)) + (drop 1) + flatten + (apply str) + str/trim)] + (if (= \/ (last attrs-html)) + (subs attrs-html 0 (dec (count attrs-html))) + attrs-html))) (defn- html-str->node-attrs "Turns a given `html` string into an attribute map, e.g: @@ -294,10 +297,10 @@ :has-attrs? false :attrs []}] (as-> (html->str->node-attrs-reducer-fn attrs-html) $ - (reduce $ default-reducer-state indexed-attrs-html) - (remove str/blank? (:attrs $)) - (map parse-html-attr-str $) - (into {} $))))) + (reduce $ default-reducer-state indexed-attrs-html) + (remove str/blank? (:attrs $)) + (map parse-html-attr-str $) + (into {} $))))) (defn- construct-node "Constructs a node map from `node-html` string and @@ -306,9 +309,9 @@ (let [node-name (html-str->node-name node-html) node-attrs (html-str->node-attrs node-html)] (cond-> {:node/name node-name} - (= node-name :dompa/text) (assoc :node/value node-html) - (not (nil? node-attrs)) (assoc :node/attrs node-attrs) - (not (nil? node-children)) (assoc :node/children node-children)))) + (= node-name :dompa/text) (assoc :node/value node-html) + (not (nil? node-attrs)) (assoc :node/attrs node-attrs) + (not (nil? node-children)) (assoc :node/children node-children)))) (defn ->nodes "Transform given `html` according to given `coordinates` into |
