Browse Source

Fixed bug in export of Org-mode code blocks

* lisp/ob-exp.el (org-babel-exp-code): Escape all lines when exporting
  Org-mode blocks.
* lisp/ob.el (org-babel-parse-src-block-match): Make use of the new
  language argument to org-babel-strip-protective-commas.
  (org-babel-parse-inline-src-block-match): Make use of the new
  language argument to org-babel-strip-protective-commas.
  (org-babel-strip-protective-commas): Now accepts a language
  argument.
Eric Schulte 13 years ago
parent
commit
d6ddb59203
2 changed files with 11 additions and 5 deletions
  1. 3 1
      lisp/ob-exp.el
  2. 8 4
      lisp/ob.el

+ 3 - 1
lisp/ob-exp.el

@@ -218,7 +218,9 @@ The function respects the value of the :exports header argument."
    "#+BEGIN_SRC %lang%flags\n%body\n#+END_SRC"
    `(("lang"  . ,(nth 0 info))
      ("flags" . ,((lambda (f) (when f (concat " " f))) (nth 3 info)))
-     ("body"  . ,(nth 1 info)))))
+     ("body"  . ,(if (string= (nth 0 info) "org")
+		     (replace-regexp-in-string "^" "," (nth 1 info))
+		   (nth 1 info))))))
 
 (defun org-babel-exp-results (info type &optional silent hash)
   "Evaluate and return the results of the current code block for export.

+ 8 - 4
lisp/ob.el

@@ -1162,7 +1162,7 @@ may be specified in the properties of the current outline entry."
           ;; get block body less properties, protective commas, and indentation
           (with-temp-buffer
             (save-match-data
-              (insert (org-babel-strip-protective-commas body))
+              (insert (org-babel-strip-protective-commas body lang))
 	      (unless preserve-indentation (org-do-remove-indentation))
               (buffer-string)))
 	  (org-babel-merge-params
@@ -1180,7 +1180,7 @@ may be specified in the properties of the current outline entry."
          (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
     (list lang
           (org-babel-strip-protective-commas
-           (org-babel-clean-text-properties (match-string 5)))
+           (org-babel-clean-text-properties (match-string 5)) lang)
           (org-babel-merge-params
            org-babel-default-inline-header-args
            (org-babel-params-from-properties lang)
@@ -2241,11 +2241,15 @@ block but are passed literally to the \"example-block\"."
   (when text
     (set-text-properties 0 (length text) nil text) text))
 
-(defun org-babel-strip-protective-commas (body)
+(defun org-babel-strip-protective-commas (body &optional lang)
   "Strip protective commas from bodies of source blocks."
   (with-temp-buffer
     (insert body)
-    (org-strip-protective-commas (point-min) (point-max))
+    (if (and lang (string= lang "org"))
+	(progn (goto-char (point-min))
+	       (while (re-search-forward "^[ \t]*\\(,\\)" nil t)
+		 (replace-match "" nil nil nil 1)))
+      (org-strip-protective-commas (point-min) (point-max)))
     (buffer-string)))
 
 (defun org-babel-script-escape (str &optional force)