org-element: Be stricter when matching arguments in LaTeX environments

* lisp/org-element.el (org-element--current-element): Be stricter when
  matching arguments in LaTeX environments.  In particular, do not
  allow anything else than options and arguments in the opening line.
* testing/lisp/test-org-element.el: Add tests.
This commit is contained in:
Nicolas Goaziou 2013-05-12 17:15:06 +02:00
parent a8d0e76b7d
commit 7d37898371
2 changed files with 11 additions and 2 deletions

View File

@ -3775,7 +3775,8 @@ element it has to parse."
(goto-char (car affiliated))
(org-element-keyword-parser limit nil))
;; LaTeX Environment.
((looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}")
((looking-at
"[ \t]*\\\\begin{[A-Za-z0-9*]+}\\(\\[.*?\\]\\|{.*?}\\)*[ \t]*$")
(org-element-latex-environment-parser limit affiliated))
;; Drawer and Property Drawer.
((looking-at org-drawer-regexp)

View File

@ -1136,11 +1136,19 @@ e^{i\\pi}+1=0
:value
(org-element-map
(org-element-parse-buffer) 'latex-environment 'identity nil t)))))
;; Allow environments with options.
;; Allow environments with options and arguments.
(should
(eq 'latex-environment
(org-test-with-temp-text
"\\begin{theorem}[Euler]\ne^{i\\pi}+1=0\n\\end{theorem}"
(org-element-type (org-element-at-point)))))
(should
(eq 'latex-environment
(org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
(org-element-type (org-element-at-point)))))
(should-not
(eq 'latex-environment
(org-test-with-temp-text "\\begin{env}{arg} something\nvalue\n\\end{env}"
(org-element-type (org-element-at-point))))))