<commit_before>(compojure/module html)

(defn escape-html
  "Change special characters into HTML character entities."
  [string]
  (.. (str string)
    (replaceAll "&"  "&amp;")
    (replaceAll "<"  "&lt;")
    (replaceAll ">"  "&gt;")
    (replaceAll "\"" "&quot;")))

(defn- make-attrs
  "Turn a map into a string of XML attributes."
  [attrs]
  (str-map
    (fn [[k v]]
      (str* " " k "=\"" (escape-html v) "\""))
    attrs))

(defn- make-tag
  "Create an XML tag given a name, attribute map, and seq of contents."
  [name attrs contents]
  (if contents
    (str* "<" name (make-attrs attrs) ">"
          (apply str contents)
          "</" name ">")
    (str* "<" name (make-attrs attrs) " />")))

(defn xml
  "Turn a tree of vectors into a string of XML."
  [tree]
  (if (vector? tree)
    (if-let tag (first tree)
      (apply make-tag (str* tag)
        (if (map? (second tree))
          [(second tree) (xml (rrest tree))]
          [{} (xml (rest tree))]))
      "")
    (str tree)))
<commit_msg>Changed HTML module to use vectors<commit_after>(compojure/module html)

(defn escape-html
  "Change special characters into HTML character entities."
  [string]
  (.. (str string)
    (replaceAll "&"  "&amp;")
    (replaceAll "<"  "&lt;")
    (replaceAll ">"  "&gt;")
    (replaceAll "\"" "&quot;")))

(defn- make-attrs
  "Turn a map into a string of XML attributes."
  [attrs]
  (str-map
    (fn [[k v]]
      (str* " " k "=\"" (escape-html v) "\""))
    attrs))

(def xml)

(defn- make-tag
  "Create an XML tag given a name, attribute map, and seq of contents."
  [name attrs contents]
  (if contents
    (str* "<" name (make-attrs attrs) ">"
          (str-map xml contents)
          "</" name ">")
    (str* "<" name (make-attrs attrs) " />")))

(defn xml
  "Turn a tree of vectors into a string of XML."
  [tree]
  (if (vector? tree)
    (if-let tag (first tree)
      (if (map? (second tree))
        (make-tag (str* tag) (second tree) (rrest tree))
        (make-tag (str* tag) {} (rest tree)))
      "")
    (str tree)))

{'fraction_non_alphanumeric': 0.1857843137254902, 'fraction_numerical': 0.0, 'mean_word_length': 2.512908777969019, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4379418', 'n_tokens_mistral': 728, 'n_tokens_neox': 730, 'n_words': 233}