;; (load "lb-en.el") ;; (load "lb-es.el") ;; Markup. ;; Emacs-Time-stamp: "2007-11-02 15:55:36" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-ht.el\"") ;; TO-DO: Check: more than "_-_-_" per page. ;; ;; TO-DO: If 100-pg .tx files change in copy directory, how does index.txt update? ;; ;; TO-DO: In footnote text region at page bottom, check for
before markers. ;; ;; TO-DO: ;; ;; TO-DO: ;; ;; TO-DO: ;; ;; TO-DO: ;; ;; TO-DO: ;; ;; TO-DO: ;; ;; TO-DO: ;; ;;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv (defvar lbg- nil "") (defvar lbg- nil "") (defvar lbg- nil "") (defvar lbg-i-from1 nil "") (defvar lbg-html-href nil "") (defvar lbg-html-hrefs nil "") (defvar lbg-html-index nil "") (defvar lbg-card-index nil "") (defvar lbg-this-section nil "") (defvar lbg-next-section nil "Set by lb-ht-footnote-pop-from-next-section") (defvar lbg-pf-output-html nil "") (defvar lbg-original-page-last nil "") (defvar lbg-original-page-first nil "") (defvar lbg-sections nil "") (defvar lbg-sections-max-levels nil "Maximum value of 'LVL'") (defvar lbg-sections-max-levels-list nil "List of largest 'LVL' by section") (progn ;; (defvar lbg-pf-log nil "") (defvar lbg-text-indextxlog nil "") (defvar lbg-text-indextab nil "") (defvar lbg-text-indextx nil "") (defvar lbg-text-indextxt nil "")) (defvar lb-ht-footnote-page-and-marker-separator ;; (_makunbound) "•" "") (defvar lb-ht-footnote-href-prefix-fw "forw" "") ;; (_makunbound) (defvar lb-ht-footnote-href-prefix-bk "back" "") ;; (_makunbound) (defvar lb-ht-__ nil "meta data") ;; (_makunbound) ;; (lb-ht-gen-del-self-href) (defun lb-ht-gen-del-self-href (&optional arg1fnsd-bfn) ;)(03 b "Delete href= and value if value matches filename of current buffer. Hmmm... seems more general than that... 2007.08.07 WARNING! Whole paragraph, surrounded by blank lines, is deleted" (_-dfun-hook "lb-ht-gen-del-self-href") ;; (let ( _rc) (if (not arg1fnsd-bfn) (setq arg1fnsd-bfn (file-name-sans-directory (bfn)))) ;; EXCEPTION - change, do not delete. ;; 2006.12.12 - 'href="#index.pdf"' in files like en/PS . (save-excursion (goto-char (point-min)) (while (search-forward-regexp (concat "[ \t\n]+href=/ ;; (match-string 0) "\\(" ;; (match-string 1) "#index[.]" ;; fix! no hardcode. "\\(txtttt\\|ps\\|pdf\\)" ;; (match-string 2) "\\)" "\"") nil t) (replace-match (file-name-sans-extension (file-name-sans-directory (lb-get-diskfilename (match-string-no-properties 2)))) t t nil 1))) ;; (save-excursion (goto-char (point-min)) (while (search-forward-regexp (concat "[ \t\n]+href=/ arg1fnsd-bfn ;; 2006.12.13 - "index.html#index.card" ;; 2006.12.13 - "index.html#index.html" ;; "\"" "\\(\"\\|#\\)" ) nil t) ;; WARNING! Will delete both href= and title= if in same paragraph. ;; (replace-match "") (_-para-delete))) _rc)) ;; (lb-ht-sub-__ lb-ht-__) (defun lb-ht-sub-__ (&optional arg1__assoc) ;)(03 d. "Replace __TAG__ with values from ARG1. Optional ARG1 is an assoc list. Without ARG1, default replacements are done (e.g., __FORMULA_MISSING__)" ;; (_-dfun-hook "lb-ht-sub-__") ;; (let ((lb-dfun (_-dfun-hook "lb-ht-sub-__")) lb-pf lb-pt lb-list-arg1 lb-item lb-tag-__ lb-str lb-cons lb-ms1 lb-ms2 lb-rc) ;; (setq lb-list-arg1 arg1__assoc) ;; Whenever list passed as ARG1, do default replacements just in case. ;; This way, the call without ARG1 does not have to be repeated. (if lb-list-arg1 (lb-ht-sub-__)) ;; MAIN 1 OF 2. --------------------------------- ;; MAIN 1 OF 2. --------------------------------- ;; MAIN 1 OF 2. --------------------------------- ;; Do this first, before lb-list-arg1 potentially modified. (when (not lb-list-arg1) ;; __NUMERIC_LVL1__ ...2 ...3 ;; __ALPHA_LVL1__ ...2 ...3 (goto-char (point-max)) ;; SEE: ;; (lb-tx-zap-paragraphs lb-re-__-lvl4chunking-real) (while (and (search-backward-regexp lb-re-__-lvl4chunking-real nil t) (setq lb-ms1 (match-string-no-properties 1)) (setq lb-ms2 (match-string-no-properties 2)) (progn (progn (replace-match "") (if (_-blank-line-p) (_-move-away-from-adjacent-blank-line))) (goto-char (car (_-where-double-newlines))) (insert "
(point) (point-min))
(or (forward-char -1) t))
(if (looking-at "[ \t\n\r][=][ \t]*[\n]")
t)))))
(setq lb-rc "CONTINUED-="))
;; TEMPLATES.
(if (and (not lb-rc)
(string-match "^abcdefg" arg1str))
(setq lb-rc ""))
(if (and (not lb-rc)
(string-match "^abcdefg" arg1str))
(setq lb-rc ""))
(if (and (not lb-rc)
(string-match "^abcdefg" arg1str))
(setq lb-rc ""))
(if (and (not lb-rc)
(string-match "^abcdefg" arg1str))
(setq lb-rc ""))
;; DEFAULT
(if (null lb-rc) (setq lb-rc "OTHER")))
lb-rc))
;;
(defun lb-ht-get-minors (arg1chaptitle)
"ARG1 is an nth-1 from list returned by lb-ht-toc-get-headings"
;; (lb-ht-get-minors (nth 1 (lb-ht-toc-get-headings 12)))
;; (lb-ht-get-minors nil)
;; => ((8 . "1. OVERCOMING HEGEL") ...)
(_-dfun-hook "lb-ht-get-minors")
;;
(let (
lb-rc)
(loop for i from 1 to (1- (length lbg-sections))
do
(setq lb-headings-there (lb-ht-toc-get-headings i t))
(if (string= arg1chaptitle (nth 1 lb-headings-there))
(_-app 'lb-rc (list (cons (nth 3 lb-headings-there) i)))))
lb-rc))
;; (lb-ht-gen-insert-img-close-slash)
(defun lb-ht-gen-insert-img-close-slash nil
"ABBYY uses so insert slash before '>'"
;;
(_-dfun-hook "lb-ht-gen-insert-img-close-slash")
(let (_rc)
(goto-char (point-min))
(while (search-forward-regexp "<[iI][mM][gG]" nil t)
(replace-match (downcase (match-string-no-properties 0)) t t)
(search-forward-string ">")
(when (not (looking-at-backward-become-forward "/[ \t\n]*>"))
(forward-char -1)
(insert " /")))
_rc))
(defun lb-ht-gen-add-span-pageno-subroutine (arg1where-lag)
(setq _pg (match-string-no-properties 1))
(setq _where (match-string-no-properties 2))
(let (_visible _visible-on-the-fly)
(if (setq _visible
(if (string= "top" _where)
_pg
(if arg1where-lag arg1where-lag)))
(save-excursion
(if (string= "bottom" _where)
(end-of-line)
(beginning-of-line))
(insert
(concat "\n\n" ""
;; ON-THE-FLY
(progn
(setq _visible-on-the-fly _visible)
;; Remove leading "0"s.
(if (string-match "^0+" _visible-on-the-fly)
(setq _visible-on-the-fly
(replace-match "" t t _visible-on-the-fly)))
_visible-on-the-fly)
"" "\n\n")))))
_pg)
;; (lb-ht-gen-add-span-pageno)
(defun lb-ht-gen-add-span-pageno nil
"Show page numbers in webpage"
;;
(_-dfun-hook "lb-ht-gen-add-span-pageno")
(let (_pt _pt-data-begin
_pg _pg-lag
_where _where-lag
_lag _re-pg-where
_rc)
;; Where page numbers?
(goto-char (point-min))
(while (search-forward-string "where=" nil t)
(when (_-sgml-comment-p)
(setq _where (progn (looking-at "[^ ]+")
(match-string-no-properties 0)))
(if (and _where-lag
(not (string= _where _where-lag)))
(error "%s: %s" _where-lag _where))
(setq _where-lag _where)))
;; fix? uncomment?
;; (setq _pt-data-begin (search-forward-string "%%data%%" nil nil))
(progn (setq _re-pg-where
(concat "pg=\\([^ ]+\\)" "[^\n]+" "where=\\([^ ]+\\)"))
(if (string= "bottom" _where)
(goto-char (point-max))
(if (string= "top" _where)
(goto-char (point-min))
(error "%s: %s" "Not top or bottom" _where))))
(if (string= "top" _where) ;; MAIN.
(while (sfr _re-pg-where nil t)
(when (_-sgml-comment-p)
(setq _pg-lag (lb-ht-gen-add-span-pageno-subroutine _pg-lag))))
(while (sbr _re-pg-where nil t)
(when (_-sgml-comment-p)
(setq _pg-lag (lb-ht-gen-add-span-pageno-subroutine _pg-lag))))
;; Flush lagged value.
(search-backward "%%data%%")
(end-of-line)
(lb-ht-gen-add-span-pageno-subroutine _pg-lag))
_rc))
(defun lb-ht-OLD-2007.03.04-gen-add-span-pageno nil
"Show page numbers in webpage"
(_-dfun-hook "lb-ht-gen-add-span-pageno")
(let (_pg _where _lag _pt _pt-data-begin
_rc)
;; (foo "1" "top")
;; (foo "1" "bottom")
(defun foo (_pg _where)
(concat "\n\n" ""
(if (string= "bottom" _where)
(int-to-string (1+ (string-to-int _pg)))
_pg)
"" "\n\n"))
(goto-char (point-min))
(setq _pt-data-begin (search-forward-string "%%data%%" nil nil))
(goto-char (point-max))
(while (and (setq _pt (search-backward-regexp
(concat "
(if (or (search-backward-string "%%notes%%" nil t)
(search-forward-string "%%notes%%" nil t))
(if (not (_-sgml-comment-p))
(tx-editing-del-para)))
_rc))
;; (lb-ht-gen-wrap-arrows-without-hrefs-span-disappear)
(defun lb-ht-gen-wrap-arrows-without-hrefs-span-disappear nil
"Delete arrow if no HREF"
(_-dfun-hook "lb-ht-gen-wrap-arrows-without-hrefs-span-disappear")
;;
(let (_pt
_rc)
(goto-char (point-min))
(while (and (search-forward-regexp "")))
t))
(_-sgml-markup-p))
(goto-char _pt)
(if (looking-at "\\(&[lg]t;\\)+<")
(replace-match
(concat
""
(match-string 0)
"/span><"
"")))))
_rc))
;;
(defun lb-ht-gen-del-leading-href-poundsign nil ;)(03c
"Remove '#' from beginning of HREF for final version (not templates)"
;;
(_-dfun-hook "lb-ht-gen-del-leading-href-poundsign")
(let (
lb-rc)
;; fix!
;; do not hardcode here.
(loop for lb-item in '(".index"
;; 2006.11.17
;;"index"
"index.html"
;; 2006.12.04
;; "bibl"
"index.card"
"index.txt"
"index.ps"
"index.pdf")
do
(if (not (string-match "[.]" lb-item))
(setq lb-item (concat lb-item "" lb-ext-html)))
(goto-char (point-min))
(while (search-forward-regexp
(concat "href=/"\\("
"#"
"\\)" lb-item "\"") nil t)
(replace-match "" nil nil nil 1)))))
;; (lb-ht-generate-index-card)
(defun lb-ht-generate-index-card nil
"
NOTE: .db are updated from .index with ~/leninist.biz$ bash lb.sh en 1"
(_-dfun-hook "lb-ht-generate-index-card")
;;
(let (lb-str lb-tags-in-db lb-tags-in-tmplt
lb-pf-db
lb-publ-translations
(lb-rc lbg-card-index))
;; fix! Fields like TITLE might be different between .tx and .index !!!
(progn
;;
(progn (lb-ht-common-__ "lb-ht-generate-index-card")
lb-ht-__)
(setq lb-tags-in-db
(lb-db-get-__-tags
(setq lb-pf-db
(concat (file-name-directory lbg-html-index) lb-file-db))))
(setq lb-tags-in-tmplt
(with-temp-buffer
(_-ifcl lbg-pf-template)
(normal-mode)
(goto-char (point-min))
;; Isolate table with __TAGS__.
(delete-region (point) (search-forward-regexp
"