From da5cba03a6f921b9ef8c1bf5d41c0d0946c0e8a8 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 5 Aug 2007 02:58:30 +0200 Subject: Reimplement FIXUP-MARKDOWN-OUTPUT using PPCRE:REGEX-REPLACE-ALL. darcs-hash:08197eaffc2b8a3d32256b27c39492f1a69f8fa0 --- utils.lisp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'utils.lisp') 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 " bla" into " bla" (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 "]*?> " 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))) + '(;; "... ." -> "...." + ("(]*?>) \\." . "\\1.") + ;; " bla" -> " bla" + ("(]*?>) " . "\\1")))) + :initial-value markup)) (defun name-of-day (day-of-week) -- cgit v1.2.3