From 9f1bbef52989532e16873a1f75331af0c7b0401f Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias Date: Sun, 3 Oct 2021 22:12:44 +0200 Subject: [PATCH] ox-html.el: add verse numbers html attribute to verse blocks * lisp/ox-html.el (org-html-verse-block): add `lines' html attribute --- lisp/ox-html.el | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index a150b1fdb..4889bbe45 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -281,6 +281,7 @@ property on the headline itself.") .underline { text-decoration: underline; } #postamble p, #preamble p { font-size: 90%; margin: .2em; } p.verse { margin-left: 3%; } + .versenum {float:right;} pre { border: 1px solid #e6e6e6; border-radius: 3px; @@ -3754,20 +3755,36 @@ information." ;;;; Verse Block -(defun org-html-verse-block (_verse-block contents info) - "Transcode a VERSE-BLOCK element from Org to HTML. -CONTENTS is verse block contents. INFO is a plist holding -contextual information." - (format "

\n%s

" - ;; Replace leading white spaces with non-breaking spaces. - (replace-regexp-in-string - "^[ \t]+" (lambda (m) (org-html--make-string (length m) " ")) - ;; 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]*\n" (regexp-quote br)))) - (replace-regexp-in-string re (concat br "\n") contents))))) +(defun org-html-verse-block (verse-block contents info) + "Transcode a VERSE-BLOCK element from Org to HTML. + CONTENTS is verse block contents. INFO is a plist holding + contextual information." + (let* ((lin (org-export-read-attribute :attr_html verse-block :lines)) + (versenum (if lin 0 "")) + (seqverse (if lin (string-to-number lin) "")) + (contents (if lin + (with-temp-buffer + (insert contents) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^.+" nil t seqverse) + (re-search-forward "$" nil t) + (replace-match (concat "" + (number-to-string + (setf versenum (+ versenum seqverse))) + "")))) + (buffer-string)) + contents))) + (format "

\n%s

" + ;; Replace leading white spaces with non-breaking spaces. + (replace-regexp-in-string + "^[ \t]+" (lambda (m) (org-html--make-string (length m) " ")) + ;; 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]*\n" (regexp-quote br)))) + (replace-regexp-in-string re (concat br "\n") contents)))))) ;;; Filter Functions -- 2.32.0