emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [patch] ox-html.el: add html attribute (verse numbers) to verse blocks
Date: Mon, 04 Oct 2021 14:27:01 +0000	[thread overview]
Message-ID: <87v92cooga.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 441 bytes --]

Hi all,

I believe that an html attribute to display marginal verse numbers in
sequence could be useful for certain content, as philological texts
(like here:
https://en.wikisource.org/wiki/The_Iliad_and_Odyssey_of_Homer_(Cowper)/Volume_2/The_Odyssey/Book_I)

The `lines' property must be a digit that is equivalent to the verse
numbers sequence:

#+ATTR_HTML: :lines 5
#+begin_verse
some verses...
#+end_verse

Best regards,

Juan Manuel 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html.el-add-verse-numbers-html-attribute-to-verse.patch --]
[-- Type: text/x-patch, Size: 3032 bytes --]

From 9f1bbef52989532e16873a1f75331af0c7b0401f Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
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 "<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]*\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 "<span class=\"versenum\">"
+						      (number-to-string
+						       (setf versenum (+ versenum seqverse)))
+						      "</span>"))))
+			   (buffer-string))
+		       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]*\n" (regexp-quote br))))
+		 (replace-regexp-in-string re (concat br "\n") contents))))))
 
 \f
 ;;; Filter Functions
-- 
2.32.0


             reply	other threads:[~2021-10-04 14:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-04 14:27 Juan Manuel Macías [this message]
2022-05-30  5:10 ` [patch] ox-html.el: add html attribute (verse numbers) to verse blocks Ihor Radchenko
2022-05-30 15:36   ` Juan Manuel Macías
2022-05-31  5:06     ` Ihor Radchenko
2022-05-31 11:00       ` Juan Manuel Macías
2022-07-04 11:44         ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v92cooga.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).