summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-01-12 14:48:53 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-01-12 14:48:53 +0100
commit343417bcdb630d4ac1bfd481c8aeb0da47db3199 (patch)
treea8c8d1da45f15df783aa2b9d942cf4a57c368e96
parenta51c6ffa532a3f40a1d5c9a77788926397fedf78 (diff)
parent0e626313e1876f934ad9d5cc798d9b74b574a79d (diff)
downloadorg-mode-343417bcdb630d4ac1bfd481c8aeb0da47db3199.tar.gz
Merge branch 'maint'
-rw-r--r--lisp/org-element.el84
-rw-r--r--lisp/ox-html.el43
-rw-r--r--testing/lisp/test-org-element.el5
3 files changed, 71 insertions, 61 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 685e32c..e1cfbfd 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4675,47 +4675,51 @@ indentation removed from its contents."
;; the beginnings of the contents or right after a line
;; break.
(lambda (blob first-flag min-ind)
- (catch 'zero
- (dolist (datum (org-element-contents blob) min-ind)
- (when first-flag
- (setq first-flag nil)
- (cond
- ;; Objects cannot start with spaces: in this
- ;; case, indentation is 0.
- ((not (stringp datum)) (throw 'zero 0))
- ((not (string-match
- "\\`\\([ \t]+\\)\\([^ \t\n]\\|\n\\|\\'\\)" datum))
- (throw 'zero 0))
- ((equal (match-string 2 datum) "\n")
- (put-text-property
- (match-beginning 1) (match-end 1) 'org-ind 'empty datum))
- (t
- (let ((i (string-width (match-string 1 datum))))
- (put-text-property
- (match-beginning 1) (match-end 1) 'org-ind i datum)
- (setq min-ind (min i min-ind))))))
+ (dolist (datum (org-element-contents blob) min-ind)
+ (when first-flag
+ (setq first-flag nil)
(cond
- ((stringp datum)
- (let ((s 0))
- (while (string-match
- "\n\\([ \t]+\\)\\([^ \t\n]\\|\n\\|\\'\\)" datum s)
- (setq s (match-end 1))
- (if (equal (match-string 2 datum) "\n")
- (put-text-property
- (match-beginning 1) (match-end 1)
- 'org-ind 'empty
- datum)
- (let ((i (string-width (match-string 1 datum))))
- (put-text-property
- (match-beginning 1) (match-end 1) 'org-ind i datum)
- (setq min-ind (min i min-ind)))))))
- ((eq (org-element-type datum) 'line-break)
- (setq first-flag t))
- ((memq (org-element-type datum) org-element-recursive-objects)
- (setq min-ind
- (funcall find-min-ind datum first-flag min-ind))))))))
- (min-ind (funcall find-min-ind
- element (not ignore-first) most-positive-fixnum)))
+ ;; Objects cannot start with spaces: in this
+ ;; case, indentation is 0.
+ ((not (stringp datum)) (throw :zero 0))
+ ((not (string-match
+ "\\`\\([ \t]+\\)\\([^ \t\n]\\|\n\\|\\'\\)" datum))
+ (throw :zero 0))
+ ((equal (match-string 2 datum) "\n")
+ (put-text-property
+ (match-beginning 1) (match-end 1) 'org-ind 'empty datum))
+ (t
+ (let ((i (string-width (match-string 1 datum))))
+ (put-text-property
+ (match-beginning 1) (match-end 1) 'org-ind i datum)
+ (setq min-ind (min i min-ind))))))
+ (cond
+ ((stringp datum)
+ (let ((s 0))
+ (while (string-match
+ "\n\\([ \t]*\\)\\([^ \t\n]\\|\n\\|\\'\\)" datum s)
+ (setq s (match-end 1))
+ (cond
+ ((equal (match-string 1 datum) "")
+ (unless (member (match-string 2 datum) '("" "\n"))
+ (throw :zero 0)))
+ ((equal (match-string 2 datum) "\n")
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'org-ind 'empty datum))
+ (t
+ (let ((i (string-width (match-string 1 datum))))
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'org-ind i datum)
+ (setq min-ind (min i min-ind))))))))
+ ((eq (org-element-type datum) 'line-break)
+ (setq first-flag t))
+ ((memq (org-element-type datum) org-element-recursive-objects)
+ (setq min-ind
+ (funcall find-min-ind datum first-flag min-ind)))))))
+ (min-ind
+ (catch :zero
+ (funcall find-min-ind
+ element (not ignore-first) most-positive-fixnum))))
(if (or (zerop min-ind) (= min-ind most-positive-fixnum)) element
;; Build ELEMENT back, replacing each string with the same
;; string minus common indentation.
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index b89ad5d..a741142 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1567,21 +1567,26 @@ INFO is the current state of the export process, as a plist."
(org-html-html5-p info)))
(defun org-html-close-tag (tag attr info)
- (concat "<" tag " " attr
+ "Return close-tag for string TAG.
+ATTR specifies additional attributes. INFO is a property list
+containing current export state."
+ (concat "<" tag
+ (org-string-nw-p (concat " " attr))
(if (org-html-xhtml-p info) " />" ">")))
(defun org-html-doctype (info)
- "Return correct html doctype tag from `org-html-doctype-alist',
-or the literal value of :html-doctype from INFO if :html-doctype
-is not found in the alist.
-INFO is a plist used as a communication channel."
+ "Return correct HTML doctype tag.
+INFO is a plist used as a communication channel. Doctype tag is
+extracted from `org-html-doctype-alist', or the literal value
+of :html-doctype from INFO if :html-doctype is not found in the
+alist."
(let ((dt (plist-get info :html-doctype)))
(or (cdr (assoc dt org-html-doctype-alist)) dt)))
(defun org-html--make-attribute-string (attributes)
"Return a list of attributes, as a string.
-ATTRIBUTES is a plist where values are either strings or nil. An
-attributes with a nil value will be omitted from the result."
+ATTRIBUTES is a plist where values are either strings or nil. An
+attribute with a nil value will be omitted from the result."
(let (output)
(dolist (item attributes (mapconcat 'identity (nreverse output) " "))
(cond ((null item) (pop output))
@@ -3591,20 +3596,16 @@ information."
"Transcode a VERSE-BLOCK element from Org to HTML.
CONTENTS is verse block contents. INFO is a plist holding
contextual information."
- ;; Replace each newline character with line break. Also replace
- ;; each blank line with a line break.
- (setq contents (replace-regexp-in-string
- "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
- (replace-regexp-in-string
- "\\(\\\\\\\\\\)?[ \t]*\n"
- (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
- ;; Replace each white space at beginning of a line with a
- ;; non-breaking space.
- (while (string-match "^[ \t]+" contents)
- (let* ((num-ws (length (match-string 0 contents)))
- (ws (org-html--make-string num-ws "&#xa0;")))
- (setq contents (replace-match ws nil t contents))))
- (format "<p class=\"verse\">\n%s</p>" contents))
+ (format "<p class=\"verse\">\n%s</p>"
+ ;; Replace leading white spaces with non-breaking spaces.
+ (replace-regexp-in-string
+ "^[ \t]+" (lambda (m) (org-html--make-string (length m) "&#xa0;"))
+ ;; Replace each newline character with line break. Also
+ ;; remove any trailing "br" close-tag so as to avoid
+ ;; duplicates.
+ (let* ((br (org-html-close-tag "br" nil info))
+ (re (format "\\(%s\\)[ \t]*$" (regexp-quote br))))
+ (replace-regexp-in-string re br contents)))))
;;; Filter Functions
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 72ffdae..177c848 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -3250,6 +3250,11 @@ Text
(org-element-normalize-contents
'(paragraph nil " Two spaces\n Three spaces"))
'(paragraph nil "Two spaces\n Three spaces")))
+ (should
+ (equal
+ (org-element-normalize-contents
+ '(paragraph nil " Two spaces\nNo space"))
+ '(paragraph nil " Two spaces\nNo space")))
;; Ignore objects within contents when computing maximum common
;; indentation. However, if contents start with an object, common
;; indentation is 0.