Browse Source

Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

Eric Schulte 14 years ago
parent
commit
e127899719
3 changed files with 121 additions and 6 deletions
  1. 4 4
      lisp/org-html.el
  2. 28 2
      lisp/org-latex.el
  3. 89 0
      testing/lisp/test-org.el

+ 4 - 4
lisp/org-html.el

@@ -2320,10 +2320,9 @@ When TITLE is nil, just close all open levels."
 	 (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
 	 (preferred (and target
 			 (cdr (assoc target org-export-preferred-target-alist))))
-	 (remove (or preferred target))
 	 (l org-level-max)
 	 snumber snu href suffix)
-    (setq extra-targets (remove remove extra-targets))
+    (setq extra-targets (remove (or preferred target) extra-targets))
     (setq extra-targets
 	  (mapconcat (lambda (x)
 		       (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
@@ -2362,12 +2361,13 @@ When TITLE is nil, just close all open levels."
 		(progn
 		  (org-close-li)
 		  (if target
-		      (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
+		      (insert (format "<li id=\"%s\">" (or preferred target))
+			      extra-targets title "<br/>\n")
 		    (insert "<li>" title "<br/>\n")))
 	      (aset org-levels-open (1- level) t)
 	      (org-close-par-maybe)
 	      (if target
-		  (insert (format "<ul>\n<li id=\"%s\">" target)
+		  (insert (format "<ul>\n<li id=\"%s\">" (or preferred target))
 			  extra-targets title "<br/>\n")
 		(insert "<ul>\n<li>" title "<br/>\n"))))
 	(aset org-levels-open (1- level) t)

+ 28 - 2
lisp/org-latex.el

@@ -1285,8 +1285,7 @@ OPT-PLIST is the options plist for current buffer."
      (format
       "\n\n\\title{%s}\n"
       ;; convert the title
-      (org-export-latex-content
-       title '(lists tables fixed-width keywords)))
+      (org-export-latex-fontify-headline title))
      ;; insert author info
      (if (plist-get opt-plist :author-info)
 	 (format "\\author{%s}\n"
@@ -1453,6 +1452,33 @@ links, keywords, lists, tables, fixed-width"
     ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
     ;; the beginning of the buffer - inserting "\n" is safe here though.
     (insert "\n" string)
+
+    ;; Preserve math snippets
+    
+    (let* ((matchers (plist-get org-format-latex-options :matchers))
+	   (re-list org-latex-regexps)
+	   beg end re e m n block off)
+      ;; Check the different regular expressions
+      (while (setq e (pop re-list))
+	(setq m (car e) re (nth 1 e) n (nth 2 e)
+	      block (if (nth 3 e) "\n\n" ""))
+	(setq off (if (member m '("$" "$1")) 1 0))
+	(when (and (member m matchers) (not (equal m "begin")))
+	  (goto-char (point-min))
+	  (while (re-search-forward re nil t)
+	    (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
+	    (add-text-properties beg end
+				 '(org-protected t org-latex-math t))))))
+
+    ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
+    (goto-char (point-min))
+    (let ((case-fold-search nil))
+      (while (re-search-forward "\\<\\(\\(La\\)?TeX\\)\\>" nil t)
+	(unless (eq (char-before (match-beginning 1)) ?\\)
+	  (org-if-unprotected-1
+	   (replace-match (org-export-latex-protect-string
+			   (concat "\\" (match-string 1)
+				   "{}")) t t)))))
     (goto-char (point-min))
     (let ((re (concat "\\\\\\([a-zA-Z]+\\)"
 		      "\\(?:<[^<>\n]*>\\)*"

+ 89 - 0
testing/lisp/test-org.el

@@ -0,0 +1,89 @@
+;;; test-org.el
+
+;; Copyright (c) ߚ David Maus
+;; Authors: David Maus
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+;;;; Comments:
+
+;; Template test file for Org-mode tests
+
+
+;;; Code:
+(let ((load-path (cons (expand-file-name
+			".." (file-name-directory
+			      (or load-file-name buffer-file-name)))
+		       load-path)))
+  (require 'org-test)
+  (require 'org-test-ob-consts))
+
+
+;;; Tests
+(ert-deftest test-org/org-link-escape-ascii-character ()
+  "Escape an ascii character."
+  (should
+   (string=
+    "%5B"
+    (org-link-escape "["))))
+
+(ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
+  "Escape an ascii control character."
+  (should
+   (string=
+    "%09"
+    (org-link-escape "\t"))))
+
+(ert-deftest test-org/org-link-escape-multibyte-character ()
+  "Escape an unicode multibyte character."
+  (should
+   (string=
+    "%E2%82%AC"
+    (org-link-escape "€"))))
+
+(ert-deftest test-org/org-link-escape-custom-table ()
+  "Escape string with custom character table."
+  (should
+   (string=
+    "Foo%3A%42ar%0A"
+    (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
+
+(ert-deftest test-org/org-link-escape-custom-table-merge ()
+  "Escape string with custom table merged with default table."
+  (should
+   (string=
+    "%5BF%6F%6F%3A%42ar%0A%5D"
+    (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
+
+(ert-deftest test-org/org-link-unescape-ascii-character ()
+  "Unescape an ascii character."
+  (should
+   (string=
+    "["
+    (org-link-unescape "%5B"))))
+
+(ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
+  "Unescpae an ascii control character."
+  (should
+   (string=
+    "\n"
+    (org-link-unescape "%0A"))))
+
+(ert-deftest test-org/org-link-unescape-multibyte-character ()
+  "Unescape unicode multibyte character."
+  (should
+   (string=
+    "€"
+    (org-link-unescape "%E2%82%AC"))))
+
+(ert-deftest test-org/org-link-unescape-ascii-extended-char ()
+  "Unescape old style percent escaped character."
+  (should
+   (string=
+    "àâçèéêîôùû"
+    (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB"))))
+
+(provide 'test-org)
+
+;;; test-org.el ends here