<commit_before>(ns objective8.templates.objective
  (:require [net.cgrand.enlive-html :as html]
            [objective8.templates.page-furniture :as f]))   

(defn text->p-nodes
  "Turns text into a collection of paragraph nodes based on linebreaks.
   Returns nil if no text is supplied"
  [text]
  (when text
    (let [newline-followed-by-optional-whitespace #"(\n+|\r+)\s*"]
    (map (fn [p] (html/html [:p p])) (clojure.string/split text
                                                           newline-followed-by-optional-whitespace)))))

(def objective-template (html/html-resource "templates/jade/objective.html"))

(defn objective-page [context]
  (apply str
         (html/emit*
           (html/at objective-template
                    [:title] (html/content (get-in context [:doc :title]))
                    [:.clj-user-navigation-signed-out] (html/substitute (f/user-navigation-signed-in? context))
                    [:.clj-objective-title] (html/content (get-in context [:data :objective :title]))
                    [:.clj-replace-with-objective-detail] (html/substitute (text->p-nodes (get-in context [:data :objective :description])))))))<commit_msg>RS & CC | #60 | Use jsoup as enlive parser<commit_after>(ns objective8.templates.objective
  (:require [net.cgrand.enlive-html :as html]
            [net.cgrand.jsoup :as jsoup]
            [objective8.templates.page-furniture :as f]))   

(defn text->p-nodes
  "Turns text into a collection of paragraph nodes based on linebreaks.
   Returns nil if no text is supplied"
  [text]
  (when text
    (let [newline-followed-by-optional-whitespace #"(\n+|\r+)\s*"]
    (map (fn [p] (html/html [:p p])) (clojure.string/split text
                                                           newline-followed-by-optional-whitespace)))))

(def objective-template (html/html-resource "templates/jade/objective.html" {:parser jsoup/parser}))

(defn objective-page [context]
  (apply str
         (html/emit*
           (html/at objective-template
                    [:title] (html/content (get-in context [:doc :title]))
                    [:.clj-user-navigation-signed-out] (html/substitute (f/user-navigation-signed-in? context))
                    [:.clj-objective-title] (html/content (get-in context [:data :objective :title]))
                    [:.clj-replace-with-objective-detail] (html/substitute (text->p-nodes (get-in context [:data :objective :description])))))))
{'fraction_non_alphanumeric': 0.1469504707327057, 'fraction_numerical': 0.0024559967253376994, 'mean_word_length': 2.447108603667137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2874136', 'n_tokens_mistral': 772, 'n_tokens_neox': 745, 'n_words': 173}