From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rafael Subject: Re: How to customize the org-mode's BEGIN_SRC HTML output Date: Wed, 25 Aug 2010 20:54:43 -0500 Message-ID: <87lj7up28s.fsfhello@somewhere.com> References: <87hbijumal.wl%ucecesf@ucl.ac.uk> <871v9mx4me.fsfhello@somewhere.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=49872 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OoRgB-0001f4-VU for emacs-orgmode@gnu.org; Wed, 25 Aug 2010 21:55:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OoRgA-0007RV-Sn for emacs-orgmode@gnu.org; Wed, 25 Aug 2010 21:54:59 -0400 Received: from lo.gmane.org ([80.91.229.12]:49862) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OoRgA-0007RB-J4 for emacs-orgmode@gnu.org; Wed, 25 Aug 2010 21:54:58 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OoRg9-0002Jw-6K for emacs-orgmode@gnu.org; Thu, 26 Aug 2010 03:54:57 +0200 Received: from 201.114.243.177 ([201.114.243.177]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 26 Aug 2010 03:54:57 +0200 Received: from rvf0068 by 201.114.243.177 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 26 Aug 2010 03:54:57 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Puneeth 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
 and 
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))))))