emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Adding Google Code Prettify support to exported code blocks
@ 2015-02-07 12:21 Tory S. Anderson
  0 siblings, 0 replies; only message in thread
From: Tory S. Anderson @ 2015-02-07 12:21 UTC (permalink / raw)
  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 "<pre class=\"example\"%s>\n%s</pre>" label code)
	(format
	 "<div class=\"org-src-container\">\n%s%s\n</div>"
	 (if (not caption) ""
	   (format "<label class=\"org-src-name\">%s</label>"
		   (org-export-data caption info)))
	 ;; add prettyprint and lang- tags to exports
	 (format "\n<pre class=\"prettyprint lang-%s src src-%s\"%s>%s</pre>" 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---
<div class="org-src-container">
<pre class="prettyprint lang-lisp src src-lisp">
<!-- you get the idea; code ommitted -->
</pre>
</div>
--8<---------------cut here---------------end--------------->8---

Upon pasting, it looks good on my blog. 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-07 12:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-07 12:21 Adding Google Code Prettify support to exported code blocks Tory S. Anderson

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).