org-babel-read: Allow reading multi-line strings
* lisp/ob-core.el (org-babel-read): Fix regexp for detecting string-like CELLs. Avoid calling `read' twice. Recover gracefully if `read' errs. * testing/lisp/test-ob.el (test-ob/org-babel-read): Add more tests. Reported-by: Max Nikulin <manikulin@gmail.com> Link: https://orgmode.org/list/v155g2$ncm$1@ciao.gmane.io
This commit is contained in:
parent
1523e21d82
commit
edb5eaaac3
|
@ -3360,16 +3360,23 @@ situations in which is it not appropriate."
|
||||||
(string= cell "*this*")))
|
(string= cell "*this*")))
|
||||||
;; FIXME: Arbitrary code evaluation.
|
;; FIXME: Arbitrary code evaluation.
|
||||||
(eval (read cell) t))
|
(eval (read cell) t))
|
||||||
((save-match-data
|
((let (read-val)
|
||||||
(and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" cell)
|
(save-match-data
|
||||||
|
(and (string-match
|
||||||
|
(rx bos (0+ space)
|
||||||
|
?\" (0+ anychar) ?\"
|
||||||
|
(0+ space) eos)
|
||||||
|
cell)
|
||||||
;; CELL is a single string
|
;; CELL is a single string
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert cell)
|
(insert cell)
|
||||||
(goto-char 1)
|
(goto-char 1)
|
||||||
(read (current-buffer))
|
(when (setq read-val
|
||||||
|
(ignore-errors
|
||||||
|
(read (current-buffer))))
|
||||||
(skip-chars-forward "[:space:]")
|
(skip-chars-forward "[:space:]")
|
||||||
(eobp))))
|
(eobp)))
|
||||||
(read cell))
|
read-val))))
|
||||||
(t (org-no-properties cell))))
|
(t (org-no-properties cell))))
|
||||||
|
|
||||||
(defun org-babel--string-to-number (string)
|
(defun org-babel--string-to-number (string)
|
||||||
|
|
|
@ -2599,6 +2599,9 @@ abc
|
||||||
;; Special case: data inside quotes
|
;; Special case: data inside quotes
|
||||||
(should (equal "foo" (org-babel-read " \"foo\" " inhibit)))
|
(should (equal "foo" (org-babel-read " \"foo\" " inhibit)))
|
||||||
(should (equal "foo with\" inside" (org-babel-read " \"foo with\\\" inside\" " inhibit)))
|
(should (equal "foo with\" inside" (org-babel-read " \"foo with\\\" inside\" " inhibit)))
|
||||||
|
(should (equal "abc\nsdf" (org-babel-read "\"abc\nsdf\"" inhibit)))
|
||||||
|
(should (equal "foo" (org-babel-read "\"foo\"" inhibit)))
|
||||||
|
(should (equal "\"foo\"(\"bar\"" (org-babel-read "\"foo\"(\"bar\"" inhibit)))
|
||||||
;; Unpaired quotes
|
;; Unpaired quotes
|
||||||
(should (equal "\"foo\"\"bar\"" (org-babel-read "\"foo\"\"bar\"" inhibit)))))
|
(should (equal "\"foo\"\"bar\"" (org-babel-read "\"foo\"\"bar\"" inhibit)))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue