emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to customize the org-mode's BEGIN_SRC HTML output
@ 2010-08-23  9:41 卓强 Will Zhuo
  2010-08-23 19:03 ` Erik Iverson
  0 siblings, 1 reply; 10+ messages in thread
From: 卓强 Will Zhuo @ 2010-08-23  9:41 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1567 bytes --]

Hi,

Recently I start blogging using org-mode, it works pretty well, except that
I would like to customize its output somehow and don't know how to make it
work.

Here's one of the cusomization requirement:

when putting source code in blog, I would like to use the plugin:
http://alexgorbatchev.com/SyntaxHighlighter/ which is basicly a javascript
frontend engine turning the following HTML to a nice looking code snippet on
the web brower.

<pre class="brush: js">
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }
</pre>

I would like to make my code snippets in the org files exporting exactly
what SyntaxHighlighter required (with a <pre class="brush: %(lanangue name)>
tag and plain source code in it only escape the special char)

However, I could not find a way:
using #+BEGIN_EXAMPLE give me a <pre> tag with class="example" and some
<span> tag

using #+BEGIN_SRC give me a <pre> tag with class="src src-%(lanangue name)"
and a bunch of <span> in the code itself.

using #+BEGIN_HTML give me nothing and it does not escape special chars like
"<>" either.

And there seems no custmized variable which could control the "class" of the
<pre> tag.

My questions are:
Is there some way to achive this?
If it need hack , where should I modify el files to be able to get the
BEGIN_SRC works as my expected?
Generally, how should one do this kind of customization and how to even add
another export format, is there any tutorial to startup ?

thanks for your help,
ZHUO,Qiang

[-- Attachment #1.2: Type: text/html, Size: 1923 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: How to customize the org-mode's BEGIN_SRC HTML output
@ 2010-08-24 13:39 Benjamin Beckwith
  2010-08-25  2:36 ` Rafael
  0 siblings, 1 reply; 10+ messages in thread
From: Benjamin Beckwith @ 2010-08-24 13:39 UTC (permalink / raw)
  To: emacs-orgmode

Hi, I also was interested in posting these blocks (through org2blog in
wordpress).  The code I posted below is added to
'org-export-preprocess-hooks' where it looks for BEGIN_SRC blocks as
well as ':' blocks of code.

In the case of BEGIN_SRC blocks, I add a header option, :syntaxhl where
I can pass in additional settings to the syntaxhighlighter code.

The code below uses Wordpress shortcodes, but I am sure that you can
adapt for your own purposes.

------------------------------------------------------------
(defun bnb/org2blog-src-blocks-to-wp-syntaxhighlighter ()
  "Export #+BEGIN_SRC blocks as Wordpress Syntaxhighlighter
tags. There is a special header option, :syntaxhl that contains
the options to pass to syntaxhighlighter.

This is intended to be added to `org-export-preprocess-hooks'"
  (interactive)
  (save-window-excursion
    (let ((case-fold-search t)
	  (colon-re "^[ \t]*:\\([ \t]\\|$\\)")
	  lang body headers syntaxhl
	  beg)
      (goto-char (point-min))
      (while (re-search-forward colon-re nil t)
	(replace-match (match-string 1))
	(beginning-of-line 1)
	(insert "[text light=\"true\"]\n")
	(setq beg (point))
	(while (looking-at colon-re)
	  (replace-match (match-string 1))
	  (end-of-line 1)
	  (or (eobp) (forward-char 1)))
	(end-of-line 1)
	(add-text-properties beg
			     (if (bolp)
				 (1- (point))
			       (point))
			     '(org-protected t))
	(insert "\n[/text]"))
      (unless (boundp 'org-babel-src-block-regexp)
	(require 'ob))
      (while (re-search-forward
	      (concat "\\(" org-babel-src-block-regexp
		      "\\|" org-babel-inline-src-block-regexp
		      "\\)")
	      nil t)
	(setq lang (match-string-no-properties 3))
	(if (string-match "-" lang)
	    (error "SyntaxHighlighter does not support languages with '-' in
the names"))
	(setq headers (match-string-no-properties 5))
	(setq body (match-string-no-properties 6))
	(save-match-data
	  (setq syntaxhl
		(if (string-match ":syntaxhl[ ]+\\([^ ]+\\)" headers)
		    (concat " " (replace-regexp-in-string "\;" " " (match-string 1
headers))))))
	(replace-match
	 (concat "\n\n[" lang syntaxhl "]\n" body "[/" lang "]\n")
	 nil t)))))

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: How to customize the org-mode's BEGIN_SRC HTML output
@ 2010-08-25  3:32 Benjamin Beckwith
  2010-08-25  8:30 ` Eric S Fraga
  0 siblings, 1 reply; 10+ messages in thread
From: Benjamin Beckwith @ 2010-08-25  3:32 UTC (permalink / raw)
  To: emacs-orgmode

Rafael,

I had my shortcodes setup to accept the language directly. Your change
should work as you indicated.  I have an additional fix to my code that
should behave better for you.  I add a property, org-protected, that
prevents processing of the text.

I tried it on your code blocks by calling org-export directly (C-c C-e)
and then choosing 'H' to see the html in a buffer.  This really helps
with debug.

Fixed code follows
----------------------------------------------------
(defun bnb/org2blog-src-blocks-to-wp-syntaxhighlighter ()
  "Export #+BEGIN_SRC blocks as Wordpress Syntaxhighlighter
tags. There is a special header option, :syntaxhl that contains
the options to pass to syntaxhighlighter.

This is intended to be added to `org-export-preprocess-hooks'"
  (interactive)
  (save-window-excursion
    (let ((case-fold-search t)
	  (colon-re "^[ \t]*:\\([ \t]\\|$\\)")
	  lang body headers syntaxhl block
	  beg)
      (goto-char (point-min))
      (while (re-search-forward colon-re nil t)
	(replace-match (match-string 1))
	(beginning-of-line 1)
	(insert "[text light=\"true\"]\n")
	(setq beg (point))
	(while (looking-at colon-re)
	  (replace-match (match-string 1))
	  (end-of-line 1)
	  (or (eobp) (forward-char 1)))
	(end-of-line 1)
	(add-text-properties beg
			     (if (bolp)
				 (1- (point))
			       (point))
			     '(org-protected t))
	(insert "\n[/text]"))
      (unless (boundp 'org-babel-src-block-regexp)
	(require 'ob))
      (while (re-search-forward
	      (concat "\\(" org-babel-src-block-regexp
		      "\\|" org-babel-inline-src-block-regexp
		      "\\)")
	      nil t)
	(setq lang (match-string-no-properties 3))
	(if (string-match "-" lang)
	    (error "SyntaxHighlighter does not support languages with '-' in
the names"))
	(setq headers (match-string-no-properties 5))
	(setq body (match-string-no-properties 6))
	(save-match-data
	  (setq syntaxhl
		(if (string-match ":syntaxhl[ ]+\\([^ ]+\\)" headers)
		    (concat " " (replace-regexp-in-string "\;" " " (match-string 1
headers))))))
	(setq block (concat "\n\n[" lang syntaxhl "]\n" body "[/" lang "]\n"))
	(add-text-properties 0 (length block) '(org-protected t) block)
	(replace-match
	 block
	 nil t)))))
----------------------------------

I also remembered that I made the following setting as well, but I do
not know if I still need it.

(setq org-export-preprocess-hook
      (list
       'bnb/org2blog-src-blocks-to-wp-syntaxhighlighter
       'org-export-blocks-preprocess))

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-09-01 14:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-23  9:41 How to customize the org-mode's BEGIN_SRC HTML output 卓强 Will Zhuo
2010-08-23 19:03 ` Erik Iverson
2010-08-26  3:22   ` Andrei Jirnyi
  -- strict thread matches above, loose matches on Subject: below --
2010-08-24 13:39 Benjamin Beckwith
2010-08-25  2:36 ` Rafael
2010-08-25  3:32 Benjamin Beckwith
2010-08-25  8:30 ` Eric S Fraga
2010-08-25 12:23   ` Rafael
2010-08-25 12:51     ` Puneeth
2010-08-26  1:54       ` Rafael
2010-08-29  9:37       ` Puneeth
2010-08-29 18:18         ` Rafael
2010-09-01 10:42           ` Puneeth
2010-09-01 14:38             ` Rafael

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).