From mboxrd@z Thu Jan 1 00:00:00 1970 From: David O'Toole Subject: org and htmlfontify Date: Sat, 19 Sep 2009 18:41:15 -0400 Message-ID: <1253400075.3121.9.camel@vomac> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mp8cP-0000TP-Bl for emacs-orgmode@gnu.org; Sat, 19 Sep 2009 18:41:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mp8cK-0000Sh-Ss for emacs-orgmode@gnu.org; Sat, 19 Sep 2009 18:41:24 -0400 Received: from [199.232.76.173] (port=47138 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mp8cK-0000SV-Qj for emacs-orgmode@gnu.org; Sat, 19 Sep 2009 18:41:20 -0400 Received: from mx20.gnu.org ([199.232.41.8]:53955) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mp8cK-0004SI-8G for emacs-orgmode@gnu.org; Sat, 19 Sep 2009 18:41:20 -0400 Received: from mail-qy0-f178.google.com ([209.85.221.178]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mp8cJ-0007nB-CY for emacs-orgmode@gnu.org; Sat, 19 Sep 2009 18:41:19 -0400 Received: by qyk8 with SMTP id 8so1780458qyk.24 for ; Sat, 19 Sep 2009 15:41:18 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hello orgmoders. I thought I would share my custom publishing function for using htmlfontify together with org-publish to automatically convert Lisp source code files into HTML with my own custom-inserted anchors. The lisp snippet is below. This was used to make the HTML links in my developer documentation properly jump to particular headings in the HTMLfontified output (try the page and see what I mean: http://dto.github.com/notebook/developers-guide.html I am also working something else org-related: http://dto.github.com/notebook/folio.html (defun spaces-to-underscores (string) (save-match-data (with-temp-buffer (insert string) (goto-char (point-min)) (while (re-search-forward " \\|-" nil t) ;; and dashes! (replace-match "_")) (buffer-substring-no-properties (point-min) (point-max))))) (defun publish-lisp-to-html (plist filename pub-dir) (interactive) (let* ((dir (file-name-directory filename)) (base (file-name-sans-extension (file-name-nondirectory filename))) (target (expand-file-name (concat base ".html") pub-dir)) (html nil) (hfy-src-doc-link-style "color: #a020f0; font-weight: bold;") (hfy-sec-doc-link-unstyle " color: #4d4d4d;")) (with-current-buffer (find-file-noselect filename) (hfy-force-fontification) (setf html (hfy-fontify-buffer dir filename))) (with-current-buffer html ;; add anchors for all three-semicolon headings (goto-char (point-min)) (while (re-search-forward ";;;[^@]*@@ \\([^<>]*\\)" nil t) (message "matched %s" (match-string-no-properties 1)) (replace-match (format ";;; @@ %s" (spaces-to-underscores (match-string-no-properties 1)) (match-string-no-properties 1)))) (write-file target nil)) (kill-buffer html)))