emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rafael <rvf0068@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: How to customize the org-mode's BEGIN_SRC HTML output
Date: Wed, 25 Aug 2010 20:54:43 -0500	[thread overview]
Message-ID: <87lj7up28s.fsfhello@somewhere.com> (raw)
In-Reply-To: AANLkTi=6Ei+ZR+DR_Z_2g4ynTpJQNFj8RUKoxO4qzcT=@mail.gmail.com

Puneeth <punchagan@gmail.com> writes:

> 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 is a workaround, all based on work by Puneeth and Benjamin, that
seems to work for me. I did not know what to do with Benjamin's advice
stuff (Just evaluating it changed nothing in the output). 

;; Benjamin's stuff, one line changed
(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")
	 (concat "\n\n[sourcecode language=\"" lang syntaxhl "\"]\n" body "[/sourcecode]\n")
	 nil t)))))

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

;; searching for [sourcecode ... ] ... [/sourcecode] so that newlines
;; are not removed
;; Puneeth's stuff, two lines changed
(defun org2blog-strip-new-lines (html)
  "Strip the new lines from the html, except in pre and blockquote tags."
  (save-excursion
    (with-temp-buffer
      (let* (start-pos end-pos)
        (insert html)
        (setq start-pos (point-min))
        (goto-char start-pos)
        (while (re-search-forward "\\[sourcecode.*" nil t 1)
          (setq end-pos (match-beginning 0))
          (replace-regexp "\\\n" " " nil start-pos end-pos)
          (re-search-forward "\\[/sourcecode.*" nil t 1)
          (setq start-pos (match-end 0))
          (goto-char start-pos))
        (setq end-pos (point-max))
        (replace-regexp "\\\n" " " nil start-pos end-pos)
        (buffer-substring-no-properties (point-min) (point-max))))))

  parent reply	other threads:[~2010-08-26  1:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-25  3:32 How to customize the org-mode's BEGIN_SRC HTML output 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-26  1:54       ` Rafael [this message]
2010-08-29  9:37       ` Puneeth
2010-08-29 18:18         ` Rafael
2010-09-01 10:42           ` Puneeth
2010-09-01 14:38             ` Rafael
2010-08-29 19:28         ` Eric S Fraga
2010-08-25 14:49   ` Benjamin Beckwith
  -- strict thread matches above, loose matches on Subject: below --
2010-08-24 13:39 Benjamin Beckwith
2010-08-25  2:36 ` Rafael
2010-08-23  9:41 卓强 Will Zhuo
2010-08-23 19:03 ` Erik Iverson
2010-08-26  3:22   ` Andrei Jirnyi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lj7up28s.fsfhello@somewhere.com \
    --to=rvf0068@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).