瀏覽代碼

Multiple titles in chapters mostly works.

Fred Gilham 2 周之前
父節點
當前提交
3ff3fa135d
共有 1 個文件被更改,包括 28 次插入25 次删除
  1. 28 25
      bible.el

+ 28 - 25
bible.el

@@ -1193,7 +1193,24 @@ in buffer)."
   (unless (= (current-column) 0)
     (insert "\n")))
 
-
+(defun bible--insert-title (title-node)
+  "Insert the text in TITLE-NODE into buffer as a chapter title. 
+Since each verse will have a `title' tag, keep track and only emit a
+title when the new title in `title-node' is different from the one
+stored in `bible-chapter-title'."
+  (unless (equal bible-chapter-title title-node)
+;;    (unless bible-chapter-title
+;;      (goto-char (point-min)))
+    (setq-local bible-chapter-title title-node)
+    (let ((title-text (bible-dom-texts bible-chapter-title)))
+      (let ((refstart (point))
+	    refend)
+	(setf title-text (replace-regexp-in-string "<.*?>" "" title-text))
+	(bible-new-line)
+	(insert (bidi-string-mark-left-to-right title-text))
+	(bible-new-line)
+	(setq refend (point))
+	(put-text-property refstart refend 'face 'bold)))))
 
 (defun bible--insert-domnode-recursive (node &optional iproperties)
   "Recursively parse domnode NODE obtained from `libxml-parse-html-region'.
@@ -1204,7 +1221,6 @@ In processing subnodes, each case will prepend a space if it needs it."
     ;; For red-letter display.
     (setq iproperties (plist-put iproperties 'jesus t)))
   (dolist (subnode (dom-children node))
-
     (cond ((null subnode) nil)
           ((stringp subnode)
            ;; Red letter
@@ -1219,28 +1235,16 @@ In processing subnodes, each case will prepend a space if it needs it."
                ;;       (FMG 5-Mar-2026)
                ;; ('node nil)
                ;; ('lb nil)
-	       ;; We have to handle the title first to make sure it
-	       ;; gets put in the right place. This mess is to deal
-	       ;; with the possibility that the title might change in
-	       ;; the middle of the chapter. I'm talking about YOU,
-	       ;; Psalm 119.
-	       ('title
-		(unless (equal subnode bible-chapter-title)
-		  (unless (= (point) (point-min))
-		    (forward-line -1)
-		    (bible-new-line))
-		  (setq-local bible-chapter-title subnode)
-		  (let ((title-text (bible-dom-texts bible-chapter-title))
-			(refstart (point))
-			refend)
-		    (when (stringp title-text)
-		      (setf title-text (replace-regexp-in-string "<.*?>" "" title-text))
-		      (insert title-text "\n")
-		      (setq refend (point))
-		      (put-text-property refstart refend 'face 'bold)))))
                ;; 'w is usual case.
                ('w (insert " ") (bible--process-word subnode iproperties))
-               ;; Font tag should be ignored, treat as if 'w
+	       ('title 
+		;; This mess is to deal with the possibility that the
+		;; title might change in the middle of the chapter. I'm
+		;; talking about YOU, Psalm 119.
+		(if bible-chapter-title 
+		    (bible--insert-title subnode) ; Middle of chapter.
+		  (save-excursion (goto-char (point-min)) (bible--insert-title subnode)))) ; Beginning of chapter.
+	       ;; Font tag should be ignored, treat as if 'w
                ('font (insert " ") (bible--process-word subnode iproperties))
                ('hi (when (equal (dom-attr subnode 'type) "bold")
                       (let ((word (bible-dom-text subnode)))
@@ -1254,8 +1258,6 @@ In processing subnodes, each case will prepend a space if it needs it."
                ;; 'q is used for red letter.
                ;; NASB Module uses 'seg to indicate OT quotations (and others?).
 	       ((or 'body 'seg 'p 'q) (bible--insert-domnode-recursive subnode iproperties))
-;;               ('title (setq bible-chapter-title subnode) (bible-new-line))
-;;	       (setq bible-chapter-title subnode) (bible-new-line))
                ;; These tags appear in ESV modules (and maybe others?)
                ;; REVIEW: Is this right? (FMG 5-Mar-2026)
                ('l
@@ -1269,7 +1271,7 @@ In processing subnodes, each case will prepend a space if it needs it."
 			   ;; REVIEW: Some modules use `level' tag but
 			   ;; not in a consistent way. (FMG 7-Mar-2026)
                            (cond ((= indent 1) (insert " "))
-                                ((= indent 2) (bible-new-line) (insert "\t\t"))))))))
+                                 ((= indent 2) (bible-new-line) (insert "\t\t"))))))))
 	       ;; REVIEW: divine name handling doesn't seem to work the same
 	       ;;         with all modules.
 	       ('divinename (bible-handle-divine-name subnode))
@@ -1315,6 +1317,7 @@ If optional argument VERSE is supplied, set cursor at verse."
       ;; Render the DOM tree into the buffer.
       (unless bible-debugme        ; If this is true, display the XML.
         (erase-buffer)
+	(setq-local bible-chapter-title nil)
         ;; Looking for the "body" tag in the DOM node.
 	(bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil)
         (goto-char (point-min))))