mwolson.org Blog - /Website

Mon, 29 Aug 2005

Yet another blog venue

In addition to my Self-maintained blog, I've also got a Xanga blog (for keeping up with a certain circle of friends) and a LiveJournal blog (which is almost never updated). For my Technical writing class, I will be participating in Yet Another Blog. Let's see how well my Muse publisher can keep up. I imagine that I can use my Xanga export code for this.

For reference, here's the Emacs Lisp code that I use to turn a self-published blog entry into a Xanga-fied one. Basically, it involves making all relative links into absolute ones, and removing additional whitespace. By concatenating the HTML, Xanga is prevented from being ... ah ... creative with it.

(defun my-muse-prepare-entry-for-xanga (file)
  "Mangle FILE so that Xanga doesn't bug out, saving to X clipboard.

If FILE is not specified, use the published version of the current file."
  (interactive
   (list
    (expand-file-name (concat (muse-page-name) muse-blosxom-extension)
                      (muse-style-element
                       :path (car (muse-project-applicable-styles
                                   buffer-file-name
                                   (cddr (muse-project-of-file))))))))
  (save-match-data
    (muse-with-temp-buffer
      (insert-file-contents file)
      ;; surround first line in <h3></h3>
      (goto-char (point-min))
      (insert "<h3>")
      (end-of-line)
      (insert "</h3>")
      ;; treat example regions properly
      (let (beg end)
        (while (re-search-forward "<pre[^>]*>" nil t)
          (setq beg (match-end 0))
          (setq end (if (re-search-forward "</pre>" nil 1)
                        (match-beginning 0)
                      (point)))
          (save-restriction
            (narrow-to-region beg end)
            ;; change initial spaces to &nbsp;
            (goto-char (point-min))
            (while (re-search-forward "^ +" nil t)
              (replace-match (apply 'concat (make-list
                                             (length (match-string 0))
                                             "&nbsp;"))))
            ;; change newline to <br />
            (goto-char (point-min))
            (while (re-search-forward "\n" nil t)
              (replace-match "<br />")))))
      ;; get rid of 2 spaces together and merge lines
      (goto-char (point-min))
      (while (re-search-forward (concat "[" muse-regexp-blank "\n]+") nil t)
        (replace-match " "))
      ;; remove trailing space
      (goto-char (point-min))
      (while (re-search-forward " *</p> *" nil t)
        (replace-match "</p>"))
      ;; make relative links work
      (goto-char (point-min))
      (while (re-search-forward "href=\"[/.]+" nil t)
        (replace-match "href=\"http://www.mwolson.org/" nil t))
      ;; copy entry to clipboard
      (clipboard-kill-ring-save (point-min) (point-max))
      (message "Copied blog entry to clipboard"))))

Add a comment

Name: 
Your email address: 
Your website: 
 
Comment: