<commit_before>(ns braid.server.markdown
  (:require [instaparse.core :as insta]
            [clojure.java.io :as io]))

(def markdown-parser
  "Simple markdown parser. Only parsing enough to handle CHANGELOG.md, so lots
  is probably missing"
  (insta/parser
    "S ::= ( <#'^'> LINE <#'\\n|$'> )*
    <LINE> ::= ( ( HEADER | LIST ) / PLAIN_LINE )
    DOT ::= #'.'
    TEXT ::= #'.*'
    HEADER ::= #'\\#+' TEXT
    LIST ::= ( LIST_LINE <'\\n'> ) +
    LIST_LINE ::= <#'\\s*(-|\\*)'> TEXT
    PLAIN_LINE ::= TEXT (* TODO: add inline things *)
    "))

(defn markdown->hiccup
  "Parse markdown into hiccup."
  [md-str]
  (->> (markdown-parser md-str)
       (insta/transform {:HEADER (fn [delim rst]
                                   [(keyword (str "h" (count delim)))
                                    rst]
                                   )
                         :TEXT identity
                         :LIST (fn [& args]
                                 (vec (cons :ul args)))
                         :LIST_LINE (fn [txt] [:li txt])
                         ; TODO: group plain lines into paragraphs
                         :PLAIN_LINE identity
                         :S (fn [& args]
                              (vec (cons :div args)))
                         })))

(defn generate-changelog
  []
  (let [changelog-hiccup (markdown->hiccup (slurp "CHANGELOG.md"))]
    (with-open [out-f (io/writer "src/braid/client/ui/views/pages/changelog.cljs")]
      (.write out-f "; THIS FILE IS AUTOMATICALLY GENERATED FROM CHANGELOG.md\n")
      (.write out-f "; DO NOT EDIT DIRECTLY\n\n")
      (.write out-f (str '(ns braid.client.ui.views.pages.changelog) "\n"))
      (.write out-f (str (list 'defn 'changelog-view []
                           [:div.page.changelog
                            [:div.title "Changelog"]
                            [:div.content
                             changelog-hiccup]]))))))<commit_msg>give markdown ns -main so can be lein run'd<commit_after>(ns braid.server.markdown
  (:require [instaparse.core :as insta]
            [clojure.java.io :as io]))

(def markdown-parser
  "Simple markdown parser. Only parsing enough to handle CHANGELOG.md, so lots
  is probably missing"
  (insta/parser
    "S ::= ( <#'^'> LINE <#'\\n|$'> )*
    <LINE> ::= ( ( HEADER | LIST ) / PLAIN_LINE )
    DOT ::= #'.'
    TEXT ::= #'.*'
    HEADER ::= #'\\#+' TEXT
    LIST ::= ( LIST_LINE <'\\n'> ) +
    LIST_LINE ::= <#'\\s*(-|\\*)'> TEXT
    PLAIN_LINE ::= TEXT (* TODO: add inline things *)
    "))

(defn markdown->hiccup
  "Parse markdown into hiccup."
  [md-str]
  (->> (markdown-parser md-str)
       (insta/transform {:HEADER (fn [delim rst]
                                   [(keyword (str "h" (count delim)))
                                    rst]
                                   )
                         :TEXT identity
                         :LIST (fn [& args]
                                 (vec (cons :ul args)))
                         :LIST_LINE (fn [txt] [:li txt])
                         ; TODO: group plain lines into paragraphs
                         :PLAIN_LINE identity
                         :S (fn [& args]
                              (vec (cons :div args)))
                         })))

(defn generate-changelog
  []
  (let [changelog-hiccup (markdown->hiccup (slurp "CHANGELOG.md"))]
    (with-open [out-f (io/writer "src/braid/client/ui/views/pages/changelog.cljs")]
      (.write out-f "; THIS FILE IS AUTOMATICALLY GENERATED FROM CHANGELOG.md\n")
      (.write out-f "; DO NOT EDIT DIRECTLY\n\n")
      (.write out-f (str '(ns braid.client.ui.views.pages.changelog) "\n"))
      (.write out-f (str (list 'defn 'changelog-view []
                           [:div.page.changelog
                            [:div.title "Changelog"]
                            [:div.content
                             changelog-hiccup]]))))))

(defn -main [& args]
  (generate-changelog))
{'fraction_non_alphanumeric': 0.15511133603238866, 'fraction_numerical': 0.0, 'mean_word_length': 1.4281326781326782, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5912024', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1222, 'n_words': 293}