emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* 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-24 13:39 How to customize the org-mode's BEGIN_SRC HTML output Benjamin Beckwith
@ 2010-08-25  2:36 ` Rafael
  2010-08-25  8:19   ` Eric S Fraga
  0 siblings, 1 reply; 10+ messages in thread
From: Rafael @ 2010-08-25  2:36 UTC (permalink / raw)
  To: emacs-orgmode

Benjamin Beckwith <bnbeckwith@gmail.com> writes:

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

Thanks! that seems to almost work for me, if I replace your penultimate
line:

> (concat "\n\n[" lang syntaxhl "]\n" body "[/" lang "]\n")

by

(concat "\n\n[sourcecode language=\"" lang syntaxhl "\"]\n"
                                          body "[/sourcecode]\n")

but then the line breaks are lost, and the latex exporter tries to be
too smart and replace the code.. Please see

http://rvftestblog.wordpress.com/2010/08/24/code-blocks-again/

which was intended as a result of posting the following:

#+POSTID: 17
#+DATE: [2010-08-24 Tue 20:43]
#+OPTIONS: toc:nil num:nil todo:nil pri:nil tags:nil ^:{}
#+DESCRIPTION: Testing
#+KEYWORDS: test
#+TITLE: Code blocks again

A perl example:

#+BEGIN_SRC perl 
   for (my $i = 0; $i != 10; ++i) {
        print "hello, world!\n";
   }
#+END_SRC

another

#+BEGIN_SRC latex
\begin{theorem}
  \label{theorem:1}
  {\normalfont (Augmentation Theorem)} Let $M=(S,I)$ be a matroid, and
  $X,Y\subseteq I$ with $|X|<|Y|$. Then there is $Z\subseteq
  Y\setminus X$ such that $|X\cup Z|=|Y|$ and $X\cup Z\in I$.
\end{theorem}
#+END_SRC

update 8: let's see if it works now...

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

* Re: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-25  2:36 ` Rafael
@ 2010-08-25  8:19   ` Eric S Fraga
  0 siblings, 0 replies; 10+ messages in thread
From: Eric S Fraga @ 2010-08-25  8:19 UTC (permalink / raw)
  To: Rafael; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1107 bytes --]

On Tue, 24 Aug 2010 21:36:40 -0500, Rafael <rvf0068@gmail.com> wrote:
> 
> Benjamin Beckwith <bnbeckwith@gmail.com> writes:
> 
> > 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.
> 
> Thanks! that seems to almost work for me, if I replace your penultimate
> line:
> 
> > (concat "\n\n[" lang syntaxhl "]\n" body "[/" lang "]\n")
> 
> by
> 
> (concat "\n\n[sourcecode language=\"" lang syntaxhl "\"]\n"
>                                           body "[/sourcecode]\n")
> 
> but then the line breaks are lost, and the latex exporter tries to be
> too smart and replace the code.. Please see

[...]

Actually, I lose the line breaks with the original version as well.

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

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

[-- Attachment #3: 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: 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
  2010-08-25 12:23   ` Rafael
  2010-08-25 14:49   ` Benjamin Beckwith
  0 siblings, 2 replies; 10+ messages in thread
From: Eric S Fraga @ 2010-08-25  8:30 UTC (permalink / raw)
  To: Benjamin Beckwith; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1329 bytes --]

On Tue, 24 Aug 2010 23:32:01 -0400, Benjamin Beckwith <bnbeckwith@gmail.com> wrote:
> 
> 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

[...]

Benjamin,

can you show us a simple example blog entry that works with this?  I
have tried and, with your version, I do not get the source code plugin
in Wordpress invoked.  If I use Rafael's change, the plugin does get
used.  Also, both your code and Rafael's cause all linebreaks in the
code to disappear.  

For instance, with some simple =MATLAB= code:

--8<---------------cut here---------------start------------->8---
#+srcname: matlabblock
#+begin_src matlab
function y = f(x)
  x = 1989;
  y = (2010-x)^2;
#+end_src
--8<---------------cut here---------------end--------------->8---

your most recent code generates

,----
| <p>    [matlab] function y = f(x)   x = 1989;   y = (2010-x)^2; [/matlab]
`----

which is not something wordpress seems to understand?

Thanks,
eric

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

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

[-- Attachment #3: 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: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-25 12:23   ` Rafael
@ 2010-08-25 12:51     ` Puneeth
  2010-08-25 13:15       ` Eric S Fraga
  2010-08-29  9:37       ` Puneeth
  0 siblings, 2 replies; 10+ messages in thread
From: Puneeth @ 2010-08-25 12:51 UTC (permalink / raw)
  To: Rafael; +Cc: emacs-orgmode

Hi All,

I'm not sure if I should've jumped into the discussion much earlier,
but anyways,

On Wed, Aug 25, 2010 at 5:53 PM, Rafael <rvf0068@gmail.com> wrote:
> I think Benjamin means that he has customized this
>
> http://en.support.wordpress.com/shortcodes/
>
> so that his code works directly. But it is not clear to me which changes
> he had to do for that, nor if that is available to free wordpress
> users...

I do not understand the part about wordpress shortcodes and stuff. For
the theme I use on my wordpress.com blog, I do not get any syntax
highlighting from the direct html export of org(2blog).  I only
learnt, recently that wordpress has a special way to include code for
syntax highlighting. (Some themes seem to highlight code in documents
generated directly using org's export. for eg: [1])

> Oh, and by the way, with Org-mode version 7.01h I concur with Eric in
> that I unfortunately still lose the linebreaks and get LaTeX code
> modified with Benjamin's new version..

The line breaks being stripped off is due to code in org2blog. It has
nothing to do with org-mode's export. Wordpress does not ignore
linebreaks in the content, which looks very ugly for normal posts.
Code in org2blog strips off the line breaks from the html generated by
org-export-as-html. It checks for <pre> and <blockquote> tags and
leaves out the newlines within those tags. This is (most) probably
what is causing trouble.

I'll only be able to look into it in the weekend. Anybody is free to
beat me to that. :)

HTH,
Puneeth

[1] - http://rvftestblog.wordpress.com/2010/08/14/testing-code-blocks/

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

* Re: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-25 12:51     ` Puneeth
@ 2010-08-25 13:15       ` Eric S Fraga
  2010-08-29  9:37       ` Puneeth
  1 sibling, 0 replies; 10+ messages in thread
From: Eric S Fraga @ 2010-08-25 13:15 UTC (permalink / raw)
  To: Puneeth; +Cc: Rafael, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]

On Wed, 25 Aug 2010 18:21:22 +0530, Puneeth <punchagan@gmail.com> wrote:
> 
> Hi All,
> 
> I'm not sure if I should've jumped into the discussion much earlier,
> but anyways,
> 
> On Wed, Aug 25, 2010 at 5:53 PM, Rafael <rvf0068@gmail.com> wrote:
> > I think Benjamin means that he has customized this
> >
> > http://en.support.wordpress.com/shortcodes/
> >
> > so that his code works directly. But it is not clear to me which changes
> > he had to do for that, nor if that is available to free wordpress
> > users...
> 
> I do not understand the part about wordpress shortcodes and stuff. For
> the theme I use on my wordpress.com blog, I do not get any syntax
> highlighting from the direct html export of org(2blog).  I only
> learnt, recently that wordpress has a special way to include code for
> syntax highlighting. (Some themes seem to highlight code in documents
> generated directly using org's export. for eg: [1])

It turns, having dug deeper, that there are two formats for source
code highlighting.  The two formats exist because users that have a
blog hosted by wordpress (e.g. someblog.wordpress.com) use one format
and those users that have their own hosted blogs based on
wordpress.org code use another.  The first is based on =[sourcecode
language...]= construct; the latter is based on a plugin and the
format is =[language]...[/language]=.  I don't understand why the
difference exists.

> 
> > Oh, and by the way, with Org-mode version 7.01h I concur with Eric in
> > that I unfortunately still lose the linebreaks and get LaTeX code
> > modified with Benjamin's new version..
> 
> The line breaks being stripped off is due to code in org2blog. It has

[...]

Ah ha!  This makes sense.  Thanks.

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

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

[-- Attachment #3: 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: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-25  8:30 ` Eric S Fraga
  2010-08-25 12:23   ` Rafael
@ 2010-08-25 14:49   ` Benjamin Beckwith
  1 sibling, 0 replies; 10+ messages in thread
From: Benjamin Beckwith @ 2010-08-25 14:49 UTC (permalink / raw)
  To: Eric S Fraga, emacs-orgmode

Eric,

I should mention that I am using the "Syntaxhighlighter Evolved"
plugin for Wordpress.  It allows shortcodes with just the language
name.  I probably should use the [sourcecode lang="..."] variant
instead.  Maybe that is why my version did not work for you?

My latest page created with my code can be found at:
http://bnbeckwith.com/index.php/writegood-mode/

As for the linebreaks, in my haste to share I forgot that I was
advising the org2blog-strip-newlines function. Which effectively keeps
all line breaks.
------------------------------
(defadvice org2blog-strip-new-lines (around
bnb/org2blog-disable-newline-removal)
  "Disables the function the removes newlines from the generated HTML"
  (setq ad-return-value (ad-get-arg 0)))
------------------------------

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

* Re: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-25 12:51     ` Puneeth
  2010-08-25 13:15       ` Eric S Fraga
@ 2010-08-29  9:37       ` Puneeth
  2010-08-29 18:18         ` Rafael
  2010-08-29 19:28         ` Eric S Fraga
  1 sibling, 2 replies; 10+ messages in thread
From: Puneeth @ 2010-08-29  9:37 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Rafael, Benjamin Beckwith

On Wed, Aug 25, 2010 at 6:21 PM, Puneeth <punchagan@gmail.com> wrote:
>> Oh, and by the way, with Org-mode version 7.01h I concur with Eric in
>> that I unfortunately still lose the linebreaks and get LaTeX code
>> modified with Benjamin's new version..
>
> The line breaks being stripped off is due to code in org2blog. It has
> nothing to do with org-mode's export. Wordpress does not ignore
> linebreaks in the content, which looks very ugly for normal posts.
> Code in org2blog strips off the line breaks from the html generated by
> org-export-as-html. It checks for <pre> and <blockquote> tags and
> leaves out the newlines within those tags. This is (most) probably
> what is causing trouble.
>
> I'll only be able to look into it in the weekend. Anybody is free to
> beat me to that. :)

This has been fixed. Thanks to a patch from Benjamin Beckwith. You can
now use any WP shortcode blocks in your org2blog posts, without losing
line breaks.

Also, org2blog now directly posts babel src blocks as WP's sourcecode
blocks, without modifying the src blocks in your org file. Just like
with Benjamin's hook function, :syntaxhl header option can still be
used to pass additional arguments to WP's syntaxhighlighter.

Happy Blogging,
Puneeth

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

* Re: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-29  9:37       ` Puneeth
  2010-08-29 18:18         ` Rafael
@ 2010-08-29 19:28         ` Eric S Fraga
  1 sibling, 0 replies; 10+ messages in thread
From: Eric S Fraga @ 2010-08-29 19:28 UTC (permalink / raw)
  To: Puneeth; +Cc: Rafael, emacs-orgmode, Benjamin Beckwith

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

On Sun, 29 Aug 2010 15:07:11 +0530, Puneeth <punchagan@gmail.com> wrote:

[...]

> This has been fixed. Thanks to a patch from Benjamin Beckwith. You can
> now use any WP shortcode blocks in your org2blog posts, without losing
> line breaks.
> 
> Also, org2blog now directly posts babel src blocks as WP's sourcecode
> blocks, without modifying the src blocks in your org file. Just like
> with Benjamin's hook function, :syntaxhl header option can still be
> used to pass additional arguments to WP's syntaxhighlighter.
> 
> Happy Blogging,
> Puneeth

Thanks!  This works like a charm.

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

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

[-- Attachment #3: 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: Re: How to customize the org-mode's BEGIN_SRC HTML output
  2010-08-29 18:18         ` Rafael
@ 2010-09-01 10:42           ` Puneeth
  0 siblings, 0 replies; 10+ messages in thread
From: Puneeth @ 2010-09-01 10:42 UTC (permalink / raw)
  To: Rafael; +Cc: emacs-orgmode

Rafael,

This has been Done.

Happy Blogging,
Puneeth

On Sun, Aug 29, 2010 at 11:48 PM, Rafael <rvf0068@gmail.com> wrote:
>
> Now, in case you wanted to have some more feature requests, ;-), here
> they are:
>
> 1. Making an option to disable the inclusion of ':light="true"'.
>
> 2. Note that Wordpress also includes support for inline math expressions
> written in LaTeX, like this: $latex E=mc^2$, and displayed expressions,
> like this: $latex \displaystyle E=mc^2$
> (http://rvftestblog.wordpress.com/2010/08/24/code-blocks-again/ to see
> what I mean). So it would be great if, the
> exporter could translate $....$ into $latex ....$ and
>
> \begin{equation}
> .......
> \end{equation}
>
> into
>
> $latex \displaystyle ...... $.

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-24 13:39 How to customize the org-mode's BEGIN_SRC HTML output Benjamin Beckwith
2010-08-25  2:36 ` Rafael
2010-08-25  8:19   ` Eric S Fraga
  -- strict thread matches above, loose matches on Subject: below --
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-25 13:15       ` Eric S Fraga
2010-08-29  9:37       ` Puneeth
2010-08-29 18:18         ` Rafael
2010-09-01 10:42           ` Puneeth
2010-08-29 19:28         ` Eric S Fraga
2010-08-25 14:49   ` Benjamin Beckwith

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