ox-md, ox-ascii, ox-texinfo: Strip blank lines from paragraphs

* lisp/org-macs.el (org-remove-blank-lines): New helper function to
strip blank lines from string.
* lisp/ox-ascii.el (org-ascii-paragraph):
* lisp/ox-latex.el (org-latex-paragraph):
* lisp/ox-md.el (org-md-paragraph):
* lisp/ox-texinfo.el (org-texinfo-paragraph): Strip blank lines from
paragraphs - these exporters are using blank lines as paragraph
separators.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/v00le7$frp$1@ciao.gmane.io
This commit is contained in:
Ihor Radchenko 2024-04-21 15:54:48 +03:00
parent 14848726a0
commit 6d5fa81984
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
5 changed files with 23 additions and 4 deletions

View File

@ -1290,6 +1290,10 @@ Assumes that s is a single line, starting in column 0."
t t s)))
s)
(defun org-remove-blank-lines (s)
"Remove blank lines in S."
(replace-regexp-in-string (rx "\n" (1+ (0+ space) "\n")) "\n" s))
(defun org-wrap (string &optional width lines)
"Wrap string to either a number of lines, or a width in characters.
If WIDTH is non-nil, the string is wrapped to that width, however many lines

View File

@ -1652,6 +1652,12 @@ information."
"Transcode a PARAGRAPH element from Org to ASCII.
CONTENTS is the contents of the paragraph, as a string. INFO is
the plist used as a communication channel."
;; Ensure that we do not create multiple paragraphs, when a single
;; paragraph is expected.
;; Multiple newlines may appear in CONTENTS, for example, when
;; certain objects are stripped from export, leaving single newlines
;; before and after.
(setq contents (org-remove-blank-lines contents))
(org-ascii--justify-element
(let ((indented-line-width (plist-get info :ascii-indented-line-width)))
(if (not (wholenump indented-line-width)) contents

View File

@ -3050,9 +3050,7 @@ the plist used as a communication channel."
;; Multiple newlines may appear in CONTENTS, for example, when
;; certain objects are stripped from export, leaving single newlines
;; before and after.
(replace-regexp-in-string
(rx "\n" (1+ (0+ space) "\n")) "\n"
contents))
(org-remove-blank-lines contents))
;;;; Plain List

View File

@ -633,6 +633,12 @@ information."
"Transcode PARAGRAPH element into Markdown format.
CONTENTS is the paragraph contents. INFO is a plist used as
a communication channel."
;; Ensure that we do not create multiple paragraphs, when a single
;; paragraph is expected.
;; Multiple newlines may appear in CONTENTS, for example, when
;; certain objects are stripped from export, leaving single newlines
;; before and after.
(setq contents (org-remove-blank-lines contents))
(let ((first-object (car (org-element-contents paragraph))))
;; If paragraph starts with a #, protect it.
(if (and (stringp first-object) (string-prefix-p "#" first-object))

View File

@ -1517,7 +1517,12 @@ information."
"Transcode a PARAGRAPH element from Org to Texinfo.
CONTENTS is the contents of the paragraph, as a string. INFO is
the plist used as a communication channel."
contents)
;; Ensure that we do not create multiple paragraphs, when a single
;; paragraph is expected.
;; Multiple newlines may appear in CONTENTS, for example, when
;; certain objects are stripped from export, leaving single newlines
;; before and after.
(org-remove-blank-lines contents))
;;;; Plain List