From 7644be5e3beff7ee986aa77dc47e27aac0f22e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asko=20N=C3=B5mm?= Date: Mon, 20 Oct 2025 00:42:50 +0300 Subject: [PATCH 1/2] #7: Fixes an issue where `!doctype` would be left out when creating nodes due to it being a void element, and adds a full HTML page test case. --- src/dompa/coordinates.cljc | 11 +-- test/dompa/html/michiel_borkent.html | 118 +++++++++++++++++++++++++++ test/dompa/round_trip_test.cljc | 14 ++++ 3 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 test/dompa/html/michiel_borkent.html create mode 100644 test/dompa/round_trip_test.cljc diff --git a/src/dompa/coordinates.cljc b/src/dompa/coordinates.cljc index 2388fcd..dbb4e0e 100644 --- a/src/dompa/coordinates.cljc +++ b/src/dompa/coordinates.cljc @@ -117,7 +117,7 @@ {:coord-type :text, :coord-name :dompa/text}))) (def ^:private void-elements - #{"area" "base" "br" "col" "embed" "hr" "img" + #{"!DOCTYPE" "!doctype" "area" "base" "br" "col" "embed" "hr" "img" "input" "link" "meta" "param" "source" "track" "wbr"}) (defn- handle-opening-tag [{:keys [stack unified coord coord-name start]}] @@ -201,9 +201,7 @@ "Parses a given HTML node attribute string into a key-value pair." [attr] - (->> (partition-by #(= % \=) attr) - (filter #(not= (-> % first) \=)) - (map #(reduce str %)))) + (str/split attr #"=" 2)) (defn- normalize-html-attr-str "Normalizes a given HTML attribute string. If it @@ -221,9 +219,8 @@ treated as boolean attributes, and are always `true`." [html-attr-str] (let [[k v] (html-attr-str->k-v html-attr-str) - k (keyword k) - v (if (nil? v) true (normalize-html-attr-str v))] - {k v})) + k (keyword k)] + {k (if (nil? v) true (normalize-html-attr-str v))})) (defn- html->str->node-attrs-reducer-fn "Returns a reducer function with initial state of `attrs-html`." diff --git a/test/dompa/html/michiel_borkent.html b/test/dompa/html/michiel_borkent.html new file mode 100644 index 0000000..a3f1c22 --- /dev/null +++ b/test/dompa/html/michiel_borkent.html @@ -0,0 +1,118 @@ + + + + Welkom op de homepagina van Michiel Borkent + + + + + + +
+
+
+
+

Michiel Borkent
Software developer, speaker, Clojure professional

+
+ +
+

Business info

+
+
    +
  • Michiel Borkent - Clojure development
  • +
    +
  • michielborkent@gmail.com
  • +
    +
  • Netherlands Chamber of Commerce / Kamer van Koophandel: 66357454
  • +
+
+
+ +
+

Curriculum vitae

+ +
+ +
+

Open source projects

+
+
    +
  • Babashka: a fast-starting scripting environment for Clojure
  • +
  • Clj-kondo: a linter for Clojure that sparks joy
  • +
  • Small Clojure Interpreter
  • +
  • Jet: CLI to transform between JSON, EDN and Transit
  • +
  • Edamame: configurable EDN/Clojure parser with location metadata
  • +
  • Re-find: find functions using spec
  • +
+
+
+ +
+

Talks

+
+
    +
  • Babashka and GraalVM; taking Clojure to new places - video, slides and code July 11th 2020, Clojure/NYC
  • +
  • Babashka and the Small Clojure Interpreter: using Clojure in new contexts - video, slides and code February 2020, ClojureD, Berlin Germany
  • +
  • Clj-kondo: a linter for Clojure that sparks joy - video, slidescode September 27th 2019, ClojuTRE, Helsinki Finland
  • +
  • Re-find: discover functions with spec - video, slides and demo April 6th 2019, Dutch Clojure Days
  • +
  • Functional Programming in Practice - repo and slides May 9th 2016, Hogeschool Utrecht
  • Full stack Clojure - repo and slides October 1 2015, Hogeschool Arnhem-Nijmegen
  • +
  • Functional programming in the browser with ClojureScript - repo and slides July 29 2015, Sytac Devjam
  • +
  • ClojureScript <3 React - video, slides and code May 26 2015, DomCode meetup
  • +
  • Reagent - ClojureScript interface to React - slides and code Feb. 12 2015, React Amsterdam
  • +
  • ClojureScript interfaces to React - video, slides and code Nov. 6 2014, Øredev, Malmö Sweden
  • +
  • ClojureScript for the web - video, slides and code Nov. 6 2014, Øredev, Malmö Sweden
  • +
  • ClojureScript/Om/Reagent - video and slides Oct. 16 2014, FP AMS, Amsterdam Netherlands
  • Immutable Stack (clojure workshop) - slides and code Oct. 10 2014, Devnology, Leusden Netherlands
  • +
  • Clojure introductie - slides Jun. 20 2013, Dec. 19 2013, May 5 2014, Hogeschool Arnhem-Nijmegen Netherlands
  • +
+
+
+ +
+

Writings

+ +
+ +
+

Courses

+
+ +
+
+ + +
+
+

Michiel

+

View Michiel Borkent's profile on Github

+

Stackoverflow

+

+
+
+
+ + \ No newline at end of file diff --git a/test/dompa/round_trip_test.cljc b/test/dompa/round_trip_test.cljc new file mode 100644 index 0000000..9413988 --- /dev/null +++ b/test/dompa/round_trip_test.cljc @@ -0,0 +1,14 @@ +(ns dompa.round-trip-test + #?(:clj (:require [clojure.test :refer [deftest is testing]] + [dompa.nodes :as nodes] + [dompa.html :as html])) + #?(:cljs (:require [cljs.test :refer-macros [deftest testing is]] + [dompa.nodes :as nodes] + [dompa.html :as html]))) + +(deftest round-trip-test + (testing "michiel borkent website" + (let [input-html (slurp "test/dompa/html/michiel_borkent.html") + nodes (html/->nodes input-html) + output-html (nodes/->html nodes)] + (is (= input-html output-html))))) \ No newline at end of file From 325f4300292b8895838b1b8e3fd2b8dd735d311f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asko=20N=C3=B5mm?= Date: Mon, 20 Oct 2025 00:46:16 +0300 Subject: [PATCH 2/2] #7: Have the round trip test run only in server-side (cljs has no slurp) --- test/dompa/round_trip_test.clj | 11 +++++++++++ test/dompa/round_trip_test.cljc | 14 -------------- 2 files changed, 11 insertions(+), 14 deletions(-) create mode 100644 test/dompa/round_trip_test.clj delete mode 100644 test/dompa/round_trip_test.cljc diff --git a/test/dompa/round_trip_test.clj b/test/dompa/round_trip_test.clj new file mode 100644 index 0000000..0e5d1fa --- /dev/null +++ b/test/dompa/round_trip_test.clj @@ -0,0 +1,11 @@ +(ns dompa.round-trip-test + (:require [clojure.test :refer [deftest is testing]] + [dompa.nodes :as nodes] + [dompa.html :as html])) + +(deftest round-trip-test + (testing "michiel borkent website" + (let [input-html (slurp "test/dompa/html/michiel_borkent.html") + nodes (html/->nodes input-html) + output-html (nodes/->html nodes)] + (is (= input-html output-html))))) \ No newline at end of file diff --git a/test/dompa/round_trip_test.cljc b/test/dompa/round_trip_test.cljc deleted file mode 100644 index 9413988..0000000 --- a/test/dompa/round_trip_test.cljc +++ /dev/null @@ -1,14 +0,0 @@ -(ns dompa.round-trip-test - #?(:clj (:require [clojure.test :refer [deftest is testing]] - [dompa.nodes :as nodes] - [dompa.html :as html])) - #?(:cljs (:require [cljs.test :refer-macros [deftest testing is]] - [dompa.nodes :as nodes] - [dompa.html :as html]))) - -(deftest round-trip-test - (testing "michiel borkent website" - (let [input-html (slurp "test/dompa/html/michiel_borkent.html") - nodes (html/->nodes input-html) - output-html (nodes/->html nodes)] - (is (= input-html output-html))))) \ No newline at end of file