From mboxrd@z Thu Jan 1 00:00:00 1970 From: torys.anderson@gmail.com (Tory S. Anderson) Subject: Adding Google Code Prettify support to exported code blocks Date: Sat, 07 Feb 2015 07:21:22 -0500 Message-ID: <871tm1syil.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YK4O6-0002KV-RM for emacs-orgmode@gnu.org; Sat, 07 Feb 2015 07:21:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YK4O4-0003HJ-Qa for emacs-orgmode@gnu.org; Sat, 07 Feb 2015 07:21:26 -0500 Received: from mail-yk0-x232.google.com ([2607:f8b0:4002:c07::232]:39271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YK4O4-0003HC-MX for emacs-orgmode@gnu.org; Sat, 07 Feb 2015 07:21:24 -0500 Received: by mail-yk0-f178.google.com with SMTP id q200so7988246ykb.9 for ; Sat, 07 Feb 2015 04:21:24 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: orgmode list I've started using Google Code Prettify on my blog and needed to add better support in the exports I'm getting out of org-mode. In particular, on my block prettify seems to do a poor job of guessing the language; so I've edited org-html-src-block to add the prettify tags (which are similar to the already exported src tags). But, ever the lisp learner, I'm open to suggestions for improvements. Following are code and an example. --8<---------------cut here---------------start------------->8--- ;; Exporting code blocks suitable for google code prettify (https://code.google.com/p/google-code-prettify/) (defun org-html-src-block (src-block contents info) "Transcode a SRC-BLOCK element from Org to HTML. CONTENTS holds the contents of the item. INFO is a plist holding contextual information. Modified to work with google code prettify (if installed on site)" (if (org-export-read-attribute :attr_html src-block :textarea) (org-html--textarea-block src-block) (let ((lang (org-element-property :language src-block)) (caption (org-export-get-caption src-block)) (code (org-html-format-code src-block info)) (label (let ((lbl (org-element-property :name src-block))) (if (not lbl) "" (format " id=\"%s\"" (org-export-solidify-link-text lbl)))))) (if (not lang) (format "
\n%s
" label code) (format "
\n%s%s\n
" (if (not caption) "" (format "" (org-export-data caption info))) ;; add prettyprint and lang- tags to exports (format "\n
%s
" lang lang label code)))))) --8<---------------cut here---------------end--------------->8--- This allows this org block: --8<---------------cut here---------------start------------->8--- #+BEGIN_SRC lisp ;; saving views (setq org-agenda-custom-commands '(("c" . "Weekly class agendas 2015-S") ("c6" "LMC 6215" ((agenda "" ((org-agenda-span 7) (org-agenda-start-on-weekday nil) (org-agenda-tag-filter-preset '("+LMC_6215" "-SCHEDULE")))))) ("c8" "CS 8803" ((agenda "" ((org-agenda-span 7) (org-agenda-start-on-weekday nil) (org-agenda-tag-filter-preset '("+CS_8803" "-SCHEDULE")))))))) #+END_SRC --8<---------------cut here---------------end--------------->8--- to produce this (prettifiable) output: --8<---------------cut here---------------start------------->8---

--8<---------------cut here---------------end--------------->8--- Upon pasting, it looks good on my blog.