From c90ede3153eb5f7e670c8aed38eb47c970cf3b06 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Tue, 8 Aug 2006 03:39:15 +0000 Subject: [PATCH] Publish captions for images that have descriptions. * lisp/muse-colors.el (muse-colors-lisp-tag): Use a simpler regexp to match the tags. (muse-colors-explicit-link): Show images in link descriptions if inlined images are enabled. * lisp/muse-docbook.el (muse-docbook-markup-strings): Add definitions for 'image-with-desc, 'image, and 'image-link. (muse-docbook-markup-paragraph): If an inlined image begins a paragraph, insert before it. (muse-docbook-fixup-images): New function that upper-cases the "format" attribute of the tag. (muse-docbook-finalize-buffer): Call it. * lisp/muse-html.el (muse-html-markup-strings): Publish images with descriptions as centered tables, with a centered caption underneath. The resulting look is consistent with the way that they are published in the LaTeX style. Thanks to Jody Klymak for the suggestion. (muse-xhtml-markup-strings): Ditto, but XHTML apparently has no valid way to center a table. (muse-html-markup-paragraph): Use class="image" instead of "image-link" for paragraphs that start with an embedded image. * lisp/muse-latex.el (muse-latex-fixup-dquotes): Go to beginning of document, instead of relying on caller to do this for us. * lisp/muse-publish.el (muse-publish-url): Use 'image instead of 'image-link and 'image-link in place of 'url-with-image. Separate the image file from its extension so that docbook and texinfo can publish images correctly. (muse-publish-markup-link): Don't force a description if one is not given. This fixes a bug where images without descriptions were being published as 'image-with-desc instead of 'image. * lisp/muse-texinfo.el (muse-texinfo-markup-strings): Improve image markup to achieve an effect similar to that of the LaTeX publishing style. Simplify 'url string. * lisp/muse.el (muse-replace-regexp-in-string): Save match data when we have to use the custom version of this function. * muse.texi (Images): Explain how to toggle inlining of images and give better examples. Mention captions and that captioned images should not be used inside of text paragraphs. (Markup Strings): Bring up-to-date with the changes made since 3.02. git-archimport-id: mwolson@gnu.org--2006/muse--main--1.0--patch-177 --- lisp/muse-colors.el | 8 ++- lisp/muse-docbook.el | 24 +++++++- lisp/muse-groff.el | 6 +- lisp/muse-html.el | 22 ++++--- lisp/muse-latex.el | 14 +++-- lisp/muse-publish.el | 16 +++-- lisp/muse-texinfo.el | 9 ++- lisp/muse-xml.el | 6 +- lisp/muse.el | 7 ++- muse.texi | 161 ++++++++++++++++++++++++++++++++++++++++++--------- 10 files changed, 211 insertions(+), 62 deletions(-) diff --git a/lisp/muse-colors.el b/lisp/muse-colors.el index 74fcae8..9a664d3 100644 --- a/lisp/muse-colors.el +++ b/lisp/muse-colors.el @@ -628,10 +628,10 @@ Functions should not modify the contents of the buffer." (let (beg-lisp end-lisp) (save-match-data (goto-char beg) - (setq beg-lisp (and (looking-at "<[^ ]+[^>]*>") + (setq beg-lisp (and (looking-at "<[^>]+>") (match-end 0))) (goto-char end) - (setq end-lisp (and (muse-looking-back "]*>") + (setq end-lisp (and (muse-looking-back "]+>") (match-beginning 0)))) (add-text-properties beg end @@ -779,7 +779,9 @@ in place of an image link defined by BEG and END." (invis-props (append props (muse-link-properties desc)))) ;; see if we should try and inline an image (if (and muse-colors-inline-images - (muse-colors-resolve-image-file link)) + (or (muse-colors-resolve-image-file link) + (and (muse-colors-resolve-image-file desc) + (setq link desc)))) ;; we found an image, so inline it (muse-colors-insert-image link diff --git a/lisp/muse-docbook.el b/lisp/muse-docbook.el index ae6e73a..59ba555 100644 --- a/lisp/muse-docbook.el +++ b/lisp/muse-docbook.el @@ -100,7 +100,19 @@ For more on the structure of this list, see :group 'muse-docbook) (defcustom muse-docbook-markup-strings - '((anchor-ref . "%s") + '((image-with-desc . " + + + +%3% +") + (image . " + +") + (image-link . " + +") + (anchor-ref . "%s") (url . "%s") (link . "%s") (link-and-anchor . "%s") @@ -214,7 +226,7 @@ found in `muse-docbook-encoding-map'." (unless (bolp) (insert "\n"))) ((eq (char-after) ?\<) - (when (looking-at (concat "<\\(emphasis\\|systemitem" + (when (looking-at (concat "<\\(emphasis\\|systemitem\\|inlinemediaobject" "\\|u?link\\|anchor\\|email\\)[ >]")) (muse-insert-markup ""))) (t @@ -247,7 +259,15 @@ and anything after `Firstname' is optional." "" "" 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-finalize-buffer () + (muse-docbook-fixup-images) (when (boundp 'buffer-file-coding-system) (when (memq buffer-file-coding-system '(no-conversion undecided-unix)) ;; make it agree with the default charset diff --git a/lisp/muse-groff.el b/lisp/muse-groff.el index d33b0c2..c17638c 100644 --- a/lisp/muse-groff.el +++ b/lisp/muse-groff.el @@ -106,9 +106,9 @@ For more on the structure of this list, see :group 'muse-groff) (defcustom muse-groff-markup-strings - `((image-with-desc . "\n.MPIMG -R %s\n") - (image-link . "\n.MPIMG -R %s\n") - (url-with-image . "\n.\\\" %s\n.MPIMG -R %s") + `((image-with-desc . "\n.MPIMG -R %s.%s\n") + (image . "\n.MPIMG -R %s.%s\n") + (image-link . "\n.\\\" %s\n.MPIMG -R %s.%s") (url . "\n.URL %s %s\n\\z") (link . "\n.URL %s %s\n\\z") (email-addr . "\f[C]%s\f[]") diff --git a/lisp/muse-html.el b/lisp/muse-html.el index 7328681..c5a960c 100644 --- a/lisp/muse-html.el +++ b/lisp/muse-html.el @@ -240,9 +240,13 @@ For more on the structure of this list, see :group 'muse-html) (defcustom muse-html-markup-strings - '((image-with-desc . "\"%s\"") - (image-link . "\"\"") - (url-with-image . "") + '((image-with-desc . " + + +
\"%3%\"
%3%
") + (image . "\"\"") + (image-link . " +") (anchor-ref . "%s") (url . "%s") (link . "%s") @@ -315,9 +319,13 @@ differs little between the various styles." :group 'muse-html) (defcustom muse-xhtml-markup-strings - '((image-with-desc . "\"%s\"") - (image-link . "\"\"") - (url-with-image . "\"\"") + '((image-with-desc . " + + +
\"%3%\"
%3%
") + (image . "\"\"") + (image-link . " +\"\"") (rule . "
") (fn-sep . "
\n") (begin-underline . "") @@ -427,7 +435,7 @@ This will be used if no special characters are found." (muse-insert-markup "

") (muse-insert-markup "

"))) ((looking-at "]") - (muse-insert-markup "

")) + (muse-insert-markup "

")) (t (forward-char 1) nil))) diff --git a/lisp/muse-latex.el b/lisp/muse-latex.el index ab3d178..038a323 100644 --- a/lisp/muse-latex.el +++ b/lisp/muse-latex.el @@ -147,9 +147,15 @@ For more on the structure of this list, see :group 'muse-latex) (defcustom muse-latex-markup-strings - '((image-with-desc . "\\begin{figure}[h]\\centering\\includegraphics[width=0.75\\textwidth]{%s}\\caption{%s}\\end{figure}") - (image-link . "\\begin{figure}[h]\\centering\\includegraphics[width=0.75\\textwidth]{%s}\\end{figure}") - (url-with-image . "%% %s\n\\includegraphics[width=0.75\\textwidth]{%s}") + '((image-with-desc . "\\begin{figure}[h] +\\centering\\includegraphics[width=0.75\\textwidth]{%s.%s} +\\caption{%s} +\\end{figure}") + (image . "\\begin{figure}[h] +\\centering\\includegraphics[width=0.75\\textwidth]{%s.%s} +\\end{figure}") + (image-link . "%% %s +\\includegraphics[width=0.75\\textwidth]{%s.%s}") (anchor-ref . "\\ref{%s}") (url . "\\url{%s}") (url-and-desc . "\\href{%s}{%s}\\footnote{%1%}") @@ -365,6 +371,7 @@ These are applied to image filenames." (defun muse-latex-fixup-dquotes () "Fixup double quotes." + (goto-char (point-min)) (let ((open t)) (while (search-forward "\"" nil t) (unless (get-text-property (match-beginning 0) 'read-only) @@ -392,7 +399,6 @@ and it will do what you expect." :group 'muse-latex) (defun muse-latex-finalize-buffer () - (goto-char (point-min)) (muse-latex-fixup-dquotes) (when (and muse-latex-permit-contents-tag muse-publish-generate-contents) diff --git a/lisp/muse-publish.el b/lisp/muse-publish.el index 70edf78..7fac3a6 100644 --- a/lisp/muse-publish.el +++ b/lisp/muse-publish.el @@ -1330,14 +1330,18 @@ the cadr is the page name, and the cddr is the anchor." ((string= url "") desc) ((eq type 'image) - (if desc - (muse-markup-text 'image-with-desc url desc) - (muse-markup-text 'image-link url))) + (let ((ext (or (file-name-extension url) ""))) + (setq url (file-name-sans-extension url)) + (if desc + (muse-markup-text 'image-with-desc url ext desc) + (muse-markup-text 'image url ext)))) ((eq type 'link-and-anchor) (muse-markup-text 'link-and-anchor url anchor (or desc orig-url))) ((and desc (string-match muse-image-regexp desc)) - (muse-markup-text 'url-with-image url desc)) + (let ((ext (or (file-name-extension desc) ""))) + (setq desc (file-name-sans-extension desc)) + (muse-markup-text 'image-link url desc ext))) ((eq type 'link) (muse-markup-text 'link url (or desc orig-url))) (t @@ -1361,7 +1365,7 @@ the cadr is the page name, and the cddr is the anchor." (match-string 0)) t nil))) (setq desc (if explicit - (or (match-string 2) (match-string 1)) + (match-string 2) (match-string 0))) (setq link (if explicit (muse-handle-explicit-link (match-string 1)) @@ -1372,7 +1376,7 @@ the cadr is the page name, and the cddr is the anchor." (eq (char-after (match-end 0)) ?\"))))) ;; if explicit link has no user-provided description, treat it ;; as if it were an implicit link - (when (and explicit (not (match-string 2))) + (when (and explicit (not desc)) (setq explicit nil)) (muse-publish-insert-url link desc explicit)))) diff --git a/lisp/muse-texinfo.el b/lisp/muse-texinfo.el index f23bd27..2a712ed 100644 --- a/lisp/muse-texinfo.el +++ b/lisp/muse-texinfo.el @@ -118,11 +118,11 @@ For more on the structure of this list, see :group 'muse-texinfo) (defcustom muse-texinfo-markup-strings - '((image-with-desc . "@image{%s}") - (image-link . "@image{%s}") - (url-with-image . "@uref{%s, %s}") + '((image-with-desc . "@center @image{%1%, , , %3%, %2%}@*\n@center %3%") + (image . "@noindent @image{%s, , , , %s}") + (image-link . "@uref{%s, %s.%s}") (anchor-ref . "@ref{%s, %s}") - (url . "@uref{%s, %s}") + (url . "@uref{%s}") (link . "@ref{Top, , Overview, %s, %s}") (link-and-anchor . "@ref{%2%, , %2%, %1%, %3%}") (email-addr . "@email{%s}") @@ -221,7 +221,6 @@ These are applied to URLs." (insert ?\n)))) (defun muse-texinfo-finalize-buffer () - (goto-char (point-min)) (muse-latex-fixup-dquotes) (texinfo-insert-node-lines (point-min) (point-max) t) (texinfo-all-menus-update t)) diff --git a/lisp/muse-xml.el b/lisp/muse-xml.el index 3333606..6935e0f 100644 --- a/lisp/muse-xml.el +++ b/lisp/muse-xml.el @@ -112,9 +112,9 @@ For more on the structure of this list, see :group 'muse-xml) (defcustom muse-xml-markup-strings - '((image-with-desc . "%s") - (image-link . "") - (url-with-image . "%s") + '((image-with-desc . "%s") + (image . "") + (image-link . "%s.%s") (anchor-ref . "%s") (url . "%s") (link . "%s") diff --git a/lisp/muse.el b/lisp/muse.el index 928bf46..2e4c572 100644 --- a/lisp/muse.el +++ b/lisp/muse.el @@ -422,9 +422,10 @@ If fifth arg LITERAL is non-nil, insert REPLACEMENT literally." (replace-regexp-in-string regexp replacement text fixedcase literal)) (t (let ((repl-len (length replacement)) start) - (while (setq start (string-match regexp text start)) - (setq start (+ start repl-len) - text (replace-match replacement fixedcase literal text)))) + (save-match-data + (while (setq start (string-match regexp text start)) + (setq start (+ start repl-len) + text (replace-match replacement fixedcase literal text))))) text))) (defun muse-add-to-invisibility-spec (element) diff --git a/muse.texi b/muse.texi index ca6c750..bfaf751 100644 --- a/muse.texi +++ b/muse.texi @@ -857,25 +857,56 @@ both. Thus, the following code will publish as a clickable image that points to @url{http://www.mwolson.org/}. @example -[[http://www.mwolson.org/][http://www.mwolson.org/static/logos/site-logo.png]] +[[http://www.mwolson.org/][/static/logos/site-logo.png]] @end example @cindex images, displaying -@cindex images, inlined @cindex images, local +@subheading Displaying images in Muse mode If a link to a locally-available image is encountered in the link description, Muse mode will attempt to display it if your version of -Emacs permits this. The following example will display correctly and -publish correctly if a @acronym{PNG} file called @file{TestLogo.png} -exists in the @file{../pics/} directory. +Emacs permits this. + +This behavior may be toggled with @kbd{C-c C-i}, or disabled permanently +by setting the @code{muse-colors-inline-images} option to @code{nil}. + +The method for finding images may be altered by customizing the +@code{muse-colors-inline-image-method} option. One useful value for +this option is @code{muse-colors-use-publishing-directory}, which tells +Muse mode to look in the directory where the current file will be +published. The default is to look in the current directory. Relative +paths like @samp{../pics/} should work for either setting. + +Eventually, it is hoped that Muse will be able to copy images from the a +``source'' directory to a publishing directory by customizing +@code{muse-project-alist}, but this has not been implemented yet. + +@cindex images, without descriptions +@cindex images, inlined +@subheading Publishing simple images +The following example will display correctly and publish correctly if a +@acronym{PNG} file called @file{TestLogo.png} exists in the +@file{../pics/} directory. If text is on the same line as the picture, +it will remain so in the output. @example -[[TestPage][../pics/TestLogo.png]] +[[../myimage.png]] @end example -@cindex images, without a description -An image link is not required to have a description. The link -@samp{[[../myimage.png]]} will display and publish as expected. +@cindex images, captions +@subheading Publishing images with captions +If you want to add a caption to an image, use the following syntax. +This will center the image (if the output format supports it) and add a +centered caption below the picture. Formats that do not support +centering the image will instead leave it against the left margin. + +@example +[[../pics/mycat.png][My cat Dexter]] +@end example + +Images with captions may only occur in their own paragraphs, with no +text on the same line. Otherwise, the published output will not be +syntactically correct. @node Horizontal Rules and Anchors, Embedded Lisp, Images, Markup Rules @comment node-name, next, previous, up @@ -2268,29 +2299,42 @@ differs little between the various styles. @item image-with-desc An image and a description. -Argument 1: image. Argument 2: description. +Argument 1: image without extension. Argument 2: image extension. +Argument 3: description. + +@item image +An inlined image. + +Argument 1: image without extension. Argument 2: image extension. @item image-link A link to an image. -Argument 1: image link. +Argument 1: link. Argument 2: image without extension. +Argument 3: image extension. -@item url-with-image -A URL with an image. +@item anchor-ref +A reference to an anchor on the current page. -Argument 1: link. Argument 2: image. +Argument 1: anchor name. Argument 2: description if one exists, or the +original link otherwise. -@item url-link +@item url +A URL without a description. + +Argument 1: URL. + +@item link A link with a description. Argument 1: link. Argument 2: description if one exists, or the original link otherwise. -@item internal-link -A link that refers to an internal anchor. +@item link-and-anchor +A link to a page with an anchor, and a description. -Argument 1: internal link. Argument 2: description if one exists, or -the original link otherwise. +Argument 1: link. Argument 2: anchor name. +Argument 3: description if one exists, or the original link otherwise. @item email-addr A link to an email address. @@ -2300,9 +2344,20 @@ Argument 1: email address. Argument 2: email address. @item emdash A 2-length dash. +Argument 1: Initial whitespace. Argument 2: Terminating whitespace. + +@item comment-begin +Beginning of a comment. + +@item comment-end +End of a comment. + @item rule A horizontal line or space. +@item no-break-space +A space that separates two words which are not to be separated. + @item footnote Beginning of footnote. @@ -2314,6 +2369,9 @@ Mark a reference for the current footnote. Argument 1: number of this footnote. +@item footnotemark-end +End of a reference for the current footnote. + @item footnotetext Indicate the text of the current footnote. @@ -2325,12 +2383,12 @@ End of a footnote text line. @item fn-sep Text used to replace ``Footnotes:'' line. -@item enddots -4 dots. - @item dots 3 dots. +@item enddots +4 dots. + @item part Beginning of a part indicator line. This is used by book publishing. @@ -2463,20 +2521,71 @@ Begin an unordered list. @item end-uli End an unordered list. +@item begin-uli-item +Begin an unordered list item. + +@item end-uli-item +End an unordered list item. + @item begin-oli Begin an ordered list. @item end-oli End an ordered list. -@item begin-ddt +@item begin-oli-item +Begin an ordered list item. + +@item end-oli-item +End an ordered list item. + +@item begin-dl Begin a definition list. -@item start-dde -Begin a term in a definition list. +@item end-dl +End a definition list. + +@item begin-dl-item +Begin a definition list item. + +@item end-dl-item +End a definition list item. + +@item begin-ddt +Begin a definition list term. @item end-ddt -End a definition list. +End a definition list term. + +@item begin-dde +Begin a definition list entry. + +@item end-dde +End a definition list entry. + +@item begin-table +Begin a table. + +@item end-table +End a table. + +@item begin-table-group +Begin a table grouping. + +@item end-table-group +End a table grouping. + +@item begin-table-row +Begin a table row. + +@item end-table-row +End a table row. + +@item begin-table-entry +Begin a table entry. + +@item end-table-entry +End a table entry. @end table -- 2.11.4.GIT