<commit_before><commit_msg>HTML helpers in a separate module.<commit_after>(in-package :cl-smaw)

(defun generate-embed-html (uri &key (width 300) (height 380))
  "Generate HTML markup for embedding spotify widgets."
  (format nil "<iframe src=\"https://embed.spotify.com/?uri=~a\" width=\"~d\" height=\"~d\"
frameborder=\"0\" allowtransparency=\"true\"></iframe>" uri width height))

(defun format-plist (plist &optional (include-keys? t) &rest keys-to-include)
  "Recursive function to pretty-print the plist returned by searches and lookups."
  (loop for (key value) on plist by #'cddr
     when (member key
		  (if keys-to-include
		      keys-to-include
		      plist) :test #'equal)
     collect (cond
	       ((member key '(:album :availability) :test #'equal)
		(if include-keys?
		    (format nil "~a:~a" (string key) (format-plist value include-keys?))
		    (format nil "~a" (format-plist value include-keys?))))

	       ((member key '(:external-ids :artists :tracks :albums) :test #'equal)
		(if include-keys?
		    (format nil "~a:~a" (string key)
			    (mapcar #'(lambda (each) (format-plist each include-keys?)) value))
		    (format nil "~a" (mapcar #'(lambda (each) (format-plist each include-keys?)) value))))

	       (t
		(if include-keys?
		    (format nil "~a:~a" key value)
		    (format nil "~a" value))))))

(defun markup-plist (plist)
  (loop for (key value) on plist by #'cddr collect
       (who:with-html-output-to-string (*standard-output* nil)
	 (:b (who:str (concatenate 'string (string-downcase (string key)) " : ")))
	 (:i (who:str value)))))
{'fraction_non_alphanumeric': 0.17110266159695817, 'fraction_numerical': 0.004435994930291508, 'mean_word_length': 3.5768115942028986, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2683212', 'n_tokens_mistral': 576, 'n_tokens_neox': 513, 'n_words': 162}