summaryrefslogtreecommitdiff
path: root/utils.lisp
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2007-08-05 02:58:30 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2007-08-05 02:58:30 +0200
commitda5cba03a6f921b9ef8c1bf5d41c0d0946c0e8a8 (patch)
tree397d43c92092d8c0a563eeefbd55f81888081c0e /utils.lisp
parent6ad080f4eba61e1ee5aa5e30d4c28e2c11c47a86 (diff)
Reimplement FIXUP-MARKDOWN-OUTPUT using PPCRE:REGEX-REPLACE-ALL.
darcs-hash:08197eaffc2b8a3d32256b27c39492f1a69f8fa0
Diffstat (limited to 'utils.lisp')
-rw-r--r--utils.lisp32
1 files changed, 16 insertions, 16 deletions
diff --git a/utils.lisp b/utils.lisp
index 2bb2f1e..be08217 100644
--- a/utils.lisp
+++ b/utils.lisp
@@ -49,22 +49,22 @@
(defun fixup-markdown-output (markup)
;; No, cl-markdown is certainly not perfect.
- ;;
- ;; First, convert "<a ...> bla</a>" into " <a ...>bla</a>" (note the
- ;; excess space to the right of the opening tag in the unprocessed
- ;; string, which we move to the left of the same opening tag, where we
- ;; expect it to make more sense in the general case).
- (loop
- for matches = (ppcre:all-matches "<a [^>]*?> " markup)
- while (not (null matches))
- do (progn
- (setf markup
- (replace markup markup :start1 (1+ (first matches))
- :end1 (second matches)
- :start2 (first matches)
- :end2 (1- (second matches))))
- (setf (elt markup (first matches)) #\Space)))
- markup)
+ (reduce #'(lambda (string thing)
+ (destructuring-bind (regex . replacement)
+ thing
+ (ppcre:regex-replace-all regex
+ string
+ replacement)))
+ (load-time-value
+ (mapcar #'(lambda (thing)
+ (destructuring-bind (regex . replacement)
+ thing
+ (cons (ppcre:create-scanner regex) replacement)))
+ '(;; "<em>...</em> ." -> "<em>...</em>."
+ ("(</[^>]*?>) \\." . "\\1.")
+ ;; "<a ...> bla</a>" -> " <a ...>bla</a>"
+ ("(<a [^>]*?>) " . "\\1"))))
+ :initial-value markup))
(defun name-of-day (day-of-week)