Explorar el Código

New indentation treatment for blocks during export

Now we also deal with center, quote, and verse blocks.
Carsten Dominik hace 16 años
padre
commit
8a9e604a7a
Se han modificado 7 ficheros con 52 adiciones y 30 borrados
  1. 8 0
      lisp/ChangeLog
  2. 4 2
      lisp/org-docbook.el
  3. 19 18
      lisp/org-exp.el
  4. 4 2
      lisp/org-html.el
  5. 7 7
      lisp/org-latex.el
  6. 1 1
      lisp/org-list.el
  7. 9 0
      lisp/org-macs.el

+ 8 - 0
lisp/ChangeLog

@@ -1,5 +1,13 @@
 2009-06-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-docbook.el (org-export-as-docbook): Better indentation
+	treatment.
+
+	* org-macs.el (org-replace-match-keep-properties): New function.
+
+	* org-exp.el (org-export-mark-blockquote-verse-center): Better
+	preprocessing of center and quote and verse blocks.
+
 	* org-docbook.el (org-export-docbook-close-lists-maybe): New function.
 	(org-export-as-docbook): Close lists when original indentation
 	mandates it.

+ 4 - 2
lisp/org-docbook.el

@@ -642,9 +642,10 @@ publishing directory."
 	      (org-export-docbook-open-para))
 	    (throw 'nextline nil))
 
+	  (org-export-docbook-close-lists-maybe line)
+
 	  ;; Protected HTML
 	  (when (get-text-property 0 'org-protected line)
-	    (org-export-docbook-close-lists-maybe line)
 	    (let (par)
 	      (when (re-search-backward
 		     "\\(<para>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
@@ -973,7 +974,8 @@ publishing directory."
 		    ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
 		    (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
 		   line)
-	      (setq ind (org-get-string-indentation line)
+	      (setq ind (or (get-text-property 0 'original-indentation line)
+			    (org-get-string-indentation line))
 		    item-type (if (match-beginning 4) "o" "u")
 		    starter (if (match-beginning 2)
 				(substring (match-string 2 line) 0 -1))

+ 19 - 18
lisp/org-exp.el

@@ -1681,24 +1681,25 @@ from the buffer."
   "Mark block quote and verse environments with special cookies.
 These special cookies will later be interpreted by the backend."
   ;; Blockquotes
-  (goto-char (point-min))
-  (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
-			    nil t)
-    (replace-match (if (equal (downcase (match-string 1)) "end")
-		       "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
-		   t t))
-  ;; Verse
-  (goto-char (point-min))
-  (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
-    (replace-match (if (equal (downcase (match-string 1)) "end")
-		       "ORG-VERSE-END" "ORG-VERSE-START")
-		   t t))
-  ;; Center
-  (goto-char (point-min))
-  (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_center\\>.*" nil t)
-    (replace-match (if (equal (downcase (match-string 1)) "end")
-		       "ORG-CENTER-END" "ORG-CENTER-START")
-		   t t)))
+  (let (type t1 ind beg end beg1 end1)
+    (goto-char (point-min))
+    (while (re-search-forward
+	    "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
+	    nil t)
+      (setq ind (length (match-string 1))
+	    type (downcase (match-string 3))
+	    t1 (if (equal type "quote") "blockquote" type))
+      (setq beg (match-beginning 0)
+	    beg1 (1+ (match-end 0)))
+      (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t)
+	(setq end (1+ (point-at-eol))
+	      end1 (1- (match-beginning 0)))
+	(setq content (org-remove-indentation (buffer-substring beg1 end1)))
+	(setq content (concat "ORG-" (upcase type) "-START\n"
+			      content "\n"
+			      "ORG-" (upcase type) "-END\n"))
+	(delete-region beg end)
+	(insert (org-add-props content nil 'original-indentation ind))))))
 
 (defun org-export-attach-captions-and-attributes (backend target-alist)
   "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.

+ 4 - 2
lisp/org-html.el

@@ -839,9 +839,10 @@ lang=\"%s\" xml:lang=\"%s\">
 	      (org-open-par))
 	    (throw 'nextline nil))
 
+	  (org-export-html-close-lists-maybe line)
+
 	  ;; Protected HTML
 	  (when (get-text-property 0 'org-protected line)
-	    (org-export-html-close-lists-maybe line)
 	    (let (par)
 	      (when (re-search-backward
 		     "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
@@ -1181,7 +1182,8 @@ lang=\"%s\" xml:lang=\"%s\">
 		    ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
 		    (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
 		   line)
-	      (setq ind (org-get-string-indentation line)
+	      (setq ind (or (get-text-property 0 'original-indentation line)
+			    (org-get-string-indentation line))
 		    item-type (if (match-beginning 4) "o" "u")
 		    starter (if (match-beginning 2)
 				(substring (match-string 2 line) 0 -1))

+ 7 - 7
lisp/org-latex.el

@@ -1510,20 +1510,20 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
   ;; Convert blockquotes
   (goto-char (point-min))
   (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
-    (replace-match "\\begin{quote}" t t))
+    (org-replace-match-keep-properties "\\begin{quote}" t t))
   (goto-char (point-min))
   (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
-    (replace-match "\\end{quote}" t t))
+    (org-replace-match-keep-properties "\\end{quote}" t t))
 
   ;; Convert verse
   (goto-char (point-min))
   (while (search-forward "ORG-VERSE-START" nil t)
-    (replace-match "\\begin{verse}" t t)
+    (org-replace-match-keep-properties "\\begin{verse}" t t)
     (beginning-of-line 2)
     (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
       (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
 	(goto-char (match-end 1))
-	(replace-match
+	(org-replace-match-keep-properties
 	 (org-export-latex-protect-string
 	  (concat "\\hspace*{1cm}" (match-string 2))) t t)
 	(beginning-of-line 1))
@@ -1532,15 +1532,15 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 	(insert "\\\\"))
       (beginning-of-line 2))
     (and (looking-at "[ \t]*ORG-VERSE-END.*")
-	 (replace-match "\\end{verse}" t t)))
+	 (org-replace-match-keep-properties "\\end{verse}" t t)))
 
   ;; Convert center
   (goto-char (point-min))
   (while (search-forward "ORG-CENTER-START" nil t)
-    (replace-match "\\begin{center}" t t))
+    (org-replace-match-keep-properties "\\begin{center}" t t))
   (goto-char (point-min))
   (while (search-forward "ORG-CENTER-END" nil t)
-    (replace-match "\\end{center}" t t))
+    (org-replace-match-keep-properties "\\end{center}" t t))
 
   (run-hooks 'org-export-latex-after-blockquotes-hook)
 

+ 1 - 1
lisp/org-list.el

@@ -1055,7 +1055,7 @@ INDENT is the indentation of the list, as a string."
     (catch 'exit
       (while (or (looking-at org-list-beginning-re)
 		 (looking-at (concat "^" indent "[ \t]+\\|^$"))
-		 (>= (or (get-text-property (point) 'original-indentation) -1)
+		 (> (or (get-text-property (point) 'original-indentation) -1)
 		     (length indent)))
 	(if (eq (point) (point-max))
 	    (throw 'exit (point-max)))

+ 9 - 0
lisp/org-macs.el

@@ -245,6 +245,15 @@ This is in contrast to merely setting it to 0."
       (setq plist (cddr plist)))
     p))
 
+
+(defun org-replace-match-keep-properties (newtext &optional fixedcase
+						  literal string)
+  "Like `replace-match', but add the text properties found original text."
+  (setq newtext (org-add-props newtext (text-properties-at
+					(match-beginning 0) string)))
+  (replace-match newtext fixedcase literal string))
+
+
 (provide 'org-macs)
 
 ;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668