emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Re: Publish fontified source codes with emacs-wiki


From: Sacha Chua
Subject: [emacs-wiki-discuss] Re: Publish fontified source codes with emacs-wiki
Date: Wed, 29 Dec 2004 22:35:26 +0900
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

Sun Yijiang <address@hidden> writes:

> I wrote this package to add a new tag "src" to emacs-wiki.  For example:

Looks like a frequently-added function. <impish grin>

Digging through my config, I find the following snippet (also using
htmlize):

;;;_+ <example mode=....></example>
;;; Stolen shamelessy from code by Satyaki Das <address@hidden>
;;; http://verify.stanford.edu/satyaki/emacs/EmacsWikiTricks.html

(defun sacha/htmlfontify-insert-region (buffer begin end)
  "Insert into BUFFER the htmlified text between BEGIN and END."
  (save-excursion
    (let* ((hfy-optimisations (cons 'skip-refontification hfy-optimisations))
           (input-text (buffer-substring begin end))
           (temp-file (make-temp-file "html-input"))
           output-buffer)
      (with-temp-buffer
        (insert input-text)
        (setq buffer-file-name temp-file)
        (save-excursion (setq output-buffer (htmlfontify-buffer nil nil)))
        (set-buffer-modified-p nil))
      (unwind-protect
          (let (b e yanked-output)
            (set-buffer output-buffer)
            (goto-char (point-min))
            (search-forward "<pre>\n")
            (setq b (line-beginning-position))
            (goto-char (point-max))
            (search-backward "</pre>")
            (forward-line -1)
            (setq e (line-beginning-position))
            (setq yanked-output (buffer-substring-no-properties b e))
            (set-buffer buffer)
            (insert yanked-output))
        (set-buffer output-buffer)
        (set-buffer-modified-p nil)
        (delete-file temp-file)
        (kill-buffer output-buffer)))))


-- 
Sacha Chua <address@hidden> - open source geekette
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C
interests: emacs, gnu/linux, personal information management, CS ed
applying as a Debian new maintainer | looking for a grad school




reply via email to

[Prev in Thread] Current Thread [Next in Thread]