mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-28 07:44:49 +00:00
org-element: Fix interpretation of empty fixed-width elements
* lisp/org-element.el (org-element-fixed-width-interpreter): Fix interpretation of fixed-width elements with a nil or empty string value. * testing/lisp/test-org-element.el: Add tests.
This commit is contained in:
parent
8d5198d654
commit
5efd7311e8
@ -1834,8 +1834,11 @@ Assume point is at the beginning of the fixed-width area."
|
||||
(defun org-element-fixed-width-interpreter (fixed-width contents)
|
||||
"Interpret FIXED-WIDTH element as Org syntax.
|
||||
CONTENTS is nil."
|
||||
(replace-regexp-in-string
|
||||
"^" ": " (substring (org-element-property :value fixed-width) 0 -1)))
|
||||
(let ((value (org-element-property :value fixed-width)))
|
||||
(and value
|
||||
(replace-regexp-in-string
|
||||
"^" ": "
|
||||
(if (string-match "\n\\'" value) (substring value 0 -1) value)))))
|
||||
|
||||
|
||||
;;;; Horizontal Rule
|
||||
|
@ -2185,7 +2185,25 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))
|
||||
(should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
|
||||
;; Preserve indentation.
|
||||
(should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
|
||||
": 2 blanks\n: 1 blank\n")))
|
||||
": 2 blanks\n: 1 blank\n"))
|
||||
;; Remove last newline character
|
||||
(should
|
||||
(equal (org-element-fixed-width-interpreter
|
||||
'(fixed-width (:value "Test\n")) nil)
|
||||
": Test"))
|
||||
(should
|
||||
(equal (org-element-fixed-width-interpreter
|
||||
'(fixed-width (:value "Test")) nil)
|
||||
": Test"))
|
||||
;; Handle empty string.
|
||||
(should
|
||||
(equal (org-element-fixed-width-interpreter
|
||||
'(fixed-width (:value "")) nil)
|
||||
""))
|
||||
;; Handle nil value.
|
||||
(should-not
|
||||
(org-element-fixed-width-interpreter
|
||||
'(fixed-width (:value nil)) nil)))
|
||||
|
||||
(ert-deftest test-org-element/horizontal-rule-interpreter ()
|
||||
"Test horizontal rule interpreter."
|
||||
|
Loading…
Reference in New Issue
Block a user