;;; muse-docbook.el --- publish DocBook files ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 ;; Free Software Foundation, Inc. ;; This file is part of Emacs Muse. It is not part of GNU Emacs. ;; Emacs Muse is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published ;; by the Free Software Foundation; either version 3, or (at your ;; option) any later version. ;; Emacs Muse is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with Emacs Muse; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;;; Contributors: ;; Dale P. Smith (dpsm AT en DOT com) improved the markup ;; significantly and made many valuable suggestions. ;;; Code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Muse DocBook XML Publishing ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'muse-publish) (require 'muse-regexps) (require 'muse-xml-common) (defgroup muse-docbook nil "Options controlling the behavior of Muse DocBook XML publishing. See `muse-docbook' for more information." :group 'muse-publish) (defcustom muse-docbook-extension ".xml" "Default file extension for publishing DocBook XML files." :type 'string :group 'muse-docbook) (defcustom muse-docbook-header " (muse-docbook-encoding)\"?> (muse-docbook-entities)>
<lisp>(muse-publishing-directive \"title\")</lisp> (muse-docbook-get-author (muse-publishing-directive \"author\")) (muse-publishing-directive \"date\") \n" "Header used for publishing DocBook XML files. This may be text or a filename." :type 'string :group 'muse-docbook) (defcustom muse-docbook-footer " (muse-docbook-bibliography)
\n" "Footer used for publishing DocBook XML files. This may be text or a filename." :type 'string :group 'muse-docbook) (defcustom muse-docbook-markup-regexps `(;; Beginning of doc, end of doc, or plain paragraph separator (10000 ,(concat "\\(\\(\n\\(?:[" muse-regexp-blank "]*\n\\)*" "\\([" muse-regexp-blank "]*\n\\)\\)" "\\|\\`\\s-*\\|\\s-*\\'\\)") 3 muse-docbook-markup-paragraph)) "List of markup rules for publishing a Muse page to DocBook XML. For more on the structure of this list, see `muse-publish-markup-regexps'." :type '(repeat (choice (list :tag "Markup rule" integer (choice regexp symbol) integer (choice string function symbol)) function)) :group 'muse-docbook) (defcustom muse-docbook-markup-functions '((anchor . muse-xml-markup-anchor) (table . muse-xml-markup-table)) "An alist of style types to custom functions for that kind of text. For more on the structure of this list, see `muse-publish-markup-functions'." :type '(alist :key-type symbol :value-type function) :group 'muse-docbook) (defcustom muse-docbook-markup-strings '((image-with-desc . " %3% ") (image . " ") (image-link . " ") (anchor-ref . "%s") (url . "%s") (link . "%s") (link-and-anchor . "%s") (email-addr . "%s") (anchor . "\n") (emdash . "%s—%s") (comment-begin . "") (rule . "") (no-break-space . " ") (enddots . "....") (dots . "...") (section . "
") (section-end . "") (subsection . "
") (subsection-end . "") (subsubsection . "
") (subsubsection-end . "") (section-other . "
") (section-other-end . "") (section-close . "
") (footnote . "") (footnote-end . "") (begin-underline . "") (end-underline . "") (begin-literal . "") (end-literal . "") (begin-emph . "") (end-emph . "") (begin-more-emph . "") (end-more-emph . "") (begin-most-emph . "") (end-most-emph . "") (begin-verse . "\n") (verse-space . " ") (end-verse . "") (begin-example . "") (end-example . "") (begin-center . "\n") (end-center . "\n") (begin-quote . "
\n") (end-quote . "\n
") (begin-cite . "") (begin-cite-author . "A:") (begin-cite-year . "Y:") (end-cite . "") (begin-quote-item . "") (end-quote-item . "") (begin-uli . "\n") (end-uli . "\n") (begin-uli-item . "") (end-uli-item . "") (begin-oli . "\n") (end-oli . "\n") (begin-oli-item . "") (end-oli-item . "") (begin-dl . "\n") (end-dl . "\n") (begin-dl-item . "\n") (end-dl-item . "\n") (begin-ddt . "") (end-ddt . "") (begin-dde . "") (end-dde . "") (begin-table . "\n") (end-table . "") (begin-table-group . " \n") (end-table-group . " \n") (begin-table-row . " \n") (end-table-row . " \n") (begin-table-entry . " ") (end-table-entry . "\n")) "Strings used for marking up text. These cover the most basic kinds of markup, the handling of which differs little between the various styles." :type '(alist :key-type symbol :value-type string) :group 'muse-docbook) (defcustom muse-docbook-encoding-default 'utf-8 "The default Emacs buffer encoding to use in published files. This will be used if no special characters are found." :type 'symbol :group 'muse-docbook) (defcustom muse-docbook-charset-default "utf-8" "The default DocBook XML charset to use if no translation is found in `muse-docbook-encoding-map'." :type 'string :group 'muse-docbook) (defun muse-docbook-encoding () (muse-xml-transform-content-type (or (and (boundp 'buffer-file-coding-system) buffer-file-coding-system) muse-docbook-encoding-default) muse-docbook-charset-default)) (defun muse-docbook-markup-paragraph () (catch 'bail-out (let ((end (copy-marker (match-end 0) t))) (goto-char (match-beginning 0)) (when (save-excursion (save-match-data (and (not (get-text-property (max (point-min) (1- (point))) 'muse-no-paragraph)) (re-search-backward "<\\(/?\\)\\(para\\|footnote\\|literallayout\\)[ >]" nil t) (cond ((string= (match-string 2) "literallayout") (and (not (string= (match-string 1) "/")) (throw 'bail-out t))) ((string= (match-string 2) "para") (and (not (string= (match-string 1) "/")) ;; don't mess up nested lists (not (and (muse-looking-back "") (throw 'bail-out t))))) ((string= (match-string 2) "footnote") (string= (match-string 1) "/")) (t nil))))) (when (get-text-property (1- (point)) 'muse-end-list) (goto-char (previous-single-property-change (1- (point)) 'muse-end-list))) (muse-insert-markup "")) (goto-char end)) (cond ((eobp) (unless (bolp) (insert "\n"))) ((get-text-property (point) 'muse-no-paragraph) (forward-char 1) nil) ((eq (char-after) ?\<) (when (looking-at (concat "<\\(emphasis\\|systemitem\\|inlinemediaobject" "\\|u?link\\|anchor\\|email\\)[ >]")) (muse-insert-markup ""))) (t (muse-insert-markup ""))))) (defun muse-docbook-get-author (&optional author) "Split the AUTHOR directive into separate fields. AUTHOR should be of the form: \"Firstname Other Names Lastname\", and anything after `Firstname' is optional." (setq author (save-match-data (split-string author))) (let ((num-el (length author))) (cond ((eq num-el 1) (concat "" (car author) "")) ((eq num-el 2) (concat "" (nth 0 author) "" "" (nth 1 author) "")) ((eq num-el 3) (concat "" (nth 0 author) "" "" (nth 1 author) "" "" (nth 2 author) "")) (t (let (first last) (setq first (car author)) (setq author (nreverse (cdr author))) (setq last (car author)) (setq author (nreverse (cdr author))) (concat "" first "" "" (mapconcat 'identity author " ") "" "" last "")))))) (defun muse-docbook-fixup-images () (goto-char (point-min)) (while (re-search-forward (concat "$") nil t) (replace-match (upcase (match-string 1)) t t nil 1))) (defun muse-docbook-fixup-citations () ;; remove the role attribute if there is no role (goto-char (point-min)) (while (re-search-forward "<\\(citation role=\"nil\"\\)>" nil t) (replace-match "citation" t t nil 1)) ;; replace colons in multi-head citations with semicolons (goto-char (point-min)) (while (re-search-forward "" nil t) (let ((start (point)) (end (re-search-forward ""))) (save-restriction (narrow-to-region start end) (goto-char (point-min)) (while (re-search-forward "," nil t) (replace-match ";")))))) (defun muse-docbook-munge-buffer () (muse-docbook-fixup-images) (muse-docbook-fixup-citations)) (defun muse-docbook-entities () (save-excursion (goto-char (point-min)) (if (re-search-forward "\n]") ""))) (defun muse-docbook-bibliography () (save-excursion (goto-char (point-min)) (if (re-search-forward "