1 ;;; muse-publish.el --- base publishing implementation
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
26 ;; Yann Hodique (yann DOT hodique AT gmail DOT com) fixed an
27 ;; unnecessary URL description transform in `muse-publish-url'.
29 ;; Peter K. Lee (saint AT corenova DOT com) provided the
30 ;; `muse-style-elements-list' function.
32 ;; Jim Ottaway (j DOT ottaway AT lse DOT ac DOT uk) provided a
33 ;; reference implementation for nested lists.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 (require 'muse-regexps
)
46 (defgroup muse-publish nil
47 "Options controlling the general behavior of Muse publishing."
50 (defcustom muse-before-publish-hook nil
51 "A hook run in the buffer to be published, before it is done."
55 (defcustom muse-after-publish-hook nil
56 "A hook run in the buffer to be published, after it is done."
60 (defcustom muse-publish-url-transforms
62 "A list of functions used to prepare URLs for publication.
63 Each is passed the URL. The transformed URL should be returned."
65 :options
'(muse-resolve-url)
68 (defcustom muse-publish-desc-transforms nil
69 "A list of functions used to prepare URL desciptions for publication.
70 Each is passed the description. The modified description should
75 (defcustom muse-publish-comments-p nil
76 "If nil, remove comments before publishing.
77 If non-nil, publish comments using the markup of the current style."
81 (defcustom muse-publish-report-threshhold
100000
82 "If a file is this size or larger, report publishing progress."
86 (defcustom muse-publish-markup-regexps
87 `(;; Remove leading and trailing whitespace from the file
88 (1000 "\\(\\`\n+\\|\n+\\'\\)" 0 "")
90 ;; Remove trailing whitespace from all lines
91 (1100 ,(concat "[" muse-regexp-blank
"]+$") 0 "")
93 ;; Handle any leading #directives
94 (1200 "\\`#\\([a-zA-Z-]+\\)\\s-+\\(.+\\)\n+" 0 directive
)
97 (1300 muse-tag-regexp
0 tag
)
100 (1350 "^;\\s-+\\(.+\\)" 0 comment
)
102 ;; prevent emphasis characters in explicit links from being marked
103 (1400 muse-explicit-link-regexp
0 muse-publish-mark-noemphasis
)
105 ;; define anchor points
106 (1500 "^\\(\\W*\\)#\\(\\S-+\\)\\s-*" 0 anchor
)
108 ;; emphasized or literal text
109 (1600 ,(concat "\\(^\\|[-[" muse-regexp-blank
110 "<('`\"\n]\\)\\(=[^=" muse-regexp-blank
111 "\n]\\|_[^_" muse-regexp-blank
112 "\n]\\|\\*+[^*" muse-regexp-blank
116 ;; headings, outline-mode style
117 (1700 "^\\(\\*+\\)\\s-+" 0 heading
)
120 (1800 "\\.\\.\\.\\." 0 enddots
)
121 (1850 "\\.\\.\\." 0 dots
)
123 ;; horizontal rule, or section separator
124 (1900 "^----+" 0 rule
)
126 ;; non-breaking space
127 (1950 "~~" 0 no-break-space
)
129 ;; beginning of footnotes section
130 (2000 "^Footnotes:?\\s-*" 0 fn-sep
)
131 ;; footnote definition/reference (def if at beginning of line)
132 (2100 "\\[\\([1-9][0-9]*\\)\\]" 0 footnote
)
134 ;; unnumbered List items begin with a -. numbered list items
135 ;; begin with number and a period. definition lists have a
136 ;; leading term separated from the body with ::. centered
137 ;; paragraphs begin with at least six columns of whitespace; any
138 ;; other whitespace at the beginning indicates a blockquote. The
139 ;; reason all of these rules are handled here, is so that
140 ;; blockquote detection doesn't interfere with indented list
143 (2200 ,(format muse-list-item-regexp
(concat "[" muse-regexp-blank
"]*"))
146 (2400 ,(concat "^\\([" muse-regexp-blank
"]+\\).+") 0 quote
)
148 (2500 ,(concat "\\(^\\|[" muse-regexp-blank
"]+\\)--\\($\\|["
149 muse-regexp-blank
"]+\\)")
152 ;; "verse" text is indicated the same way as a quoted e-mail
153 ;; response: "> text", where text may contain initial whitespace
155 (2600 ,(concat "^[" muse-regexp-blank
"]*> ") 0 verse
)
157 ;; simple table markup is supported, nothing fancy. use | to
158 ;; separate cells, || to separate header cells, and ||| for footer
160 (2700 ,(concat "\\(\\([" muse-regexp-blank
"]*\n\\)?"
161 "\\(" muse-table-line-regexp
"\\(?:\n\\|\\'\\)\\)\\)+")
164 ;; replace links in the buffer (links to other pages)
165 (2900 muse-explicit-link-regexp
0 link
)
168 (3000 muse-url-regexp
0 url
)
170 ;; bare email addresses
172 "\\([^[]\\)[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+" 0 email
)
174 "List of markup rules for publishing a page with Muse.
175 The rules given in this variable are invoked first, followed by
176 whatever rules are specified by the current style.
178 Each member of the list is either a function, or a list of the form:
180 (REGEXP/SYMBOL TEXT-BEGIN-GROUP REPLACEMENT-TEXT/FUNCTION/SYMBOL)
182 REGEXP is a regular expression, or symbol whose value is a regular
183 expression, which is searched for using `re-search-forward'.
184 TEXT-BEGIN-GROUP is the matching group within that regexp which
185 denotes the beginning of the actual text to be marked up.
186 REPLACEMENT-TEXT is a string that will be passed to `replace-match'.
187 If it is not a string, but a function, it will be called to determine
188 what the replacement text should be (it must return a string). If it
189 is a symbol, the value of that symbol should be a string.
191 The replacements are done in order, one rule at a time. Writing
192 the regular expressions can be a tricky business. Note that case
193 is never ignored. `case-fold-search' is always bound to nil
194 while processing the markup rules."
195 :type
'(repeat (choice
196 (list :tag
"Markup rule"
198 (choice regexp symbol
)
200 (choice string function symbol
))
202 :group
'muse-publish
)
204 (defcustom muse-publish-markup-functions
205 '((directive . muse-publish-markup-directive
)
206 (comment . muse-publish-markup-comment
)
207 (anchor . muse-publish-markup-anchor
)
208 (tag . muse-publish-markup-tag
)
209 (word . muse-publish-markup-word
)
210 (emdash . muse-publish-markup-emdash
)
211 (enddots . muse-publish-markup-enddots
)
212 (dots . muse-publish-markup-dots
)
213 (rule . muse-publish-markup-rule
)
214 (no-break-space . muse-publish-markup-no-break-space
)
215 (heading . muse-publish-markup-heading
)
216 (footnote . muse-publish-markup-footnote
)
217 (fn-sep . muse-publish-markup-fn-sep
)
218 (list . muse-publish-markup-list
)
219 (quote . muse-publish-markup-quote
)
220 (verse . muse-publish-markup-verse
)
221 (table . muse-publish-markup-table
)
222 (email . muse-publish-markup-email
)
223 (link . muse-publish-markup-link
)
224 (url . muse-publish-markup-url
))
225 "An alist of style types to custom functions for that kind of text.
227 Each member of the list is of the form:
231 SYMBOL describes the type of text to associate with this rule.
232 `muse-publish-markup-regexps' maps regexps to these symbols.
234 FUNCTION is the function to use to mark up this kind of rule if
235 no suitable function is found through the :functions tag of the
237 :type
'(alist :key-type symbol
:value-type function
)
238 :group
'muse-publish
)
240 (defcustom muse-publish-markup-tags
241 '(("contents" nil t muse-publish-contents-tag
)
242 ("verse" t nil muse-publish-verse-tag
)
243 ("example" t nil muse-publish-example-tag
)
244 ("code" t nil muse-publish-code-tag
)
245 ("quote" t nil muse-publish-quote-tag
)
246 ("literal" t nil muse-publish-mark-read-only
)
247 ("verbatim" t nil muse-publish-verbatim-tag
)
248 ("lisp" t nil muse-publish-lisp-tag
)
249 ("class" t t muse-publish-class-tag
)
250 ("command" t t muse-publish-command-tag
)
251 ("comment" t nil muse-publish-comment-tag
))
252 "A list of tag specifications, for specially marking up text.
253 XML-style tags are the best way to add custom markup to Muse.
254 This is easily accomplished by customizing this list of markup tags.
256 For each entry, the name of the tag is given, whether it expects
257 a closing tag and/or an optional set of attributes, and a
258 function that performs whatever action is desired within the
261 The tags themselves are deleted during publishing, before the
262 function is called. The function is called with three arguments,
263 the beginning and end of the region surrounded by the tags. If
264 properties are allowed, they are passed as a third argument in
265 the form of an alist. The `end' argument to the function is
268 Point is always at the beginning of the region within the tags, when
269 the function is called. Wherever point is when the function finishes
270 is where tag markup will resume.
272 These tag rules are processed once at the beginning of markup, and
273 once at the end, to catch any tags which may have been inserted
275 :type
'(repeat (list (string :tag
"Markup tag")
276 (boolean :tag
"Expect closing tag" :value t
)
277 (boolean :tag
"Parse attributes" :value nil
)
279 :group
'muse-publish
)
281 (defcustom muse-publish-markup-specials nil
282 "A table of characters which must be represented specially."
283 :type
'(alist :key-type character
:value-type string
)
284 :group
'muse-publish
)
286 (defvar muse-publishing-p nil
287 "Set to t while a page is being published.")
288 (defvar muse-batch-publishing-p nil
289 "Set to t while a page is being batch published.")
290 (defvar muse-publishing-styles nil
291 "The publishing styles that Muse recognizes.
292 This is automatically generated when loading publishing styles.")
293 (defvar muse-publishing-current-file nil
294 "The file that is currently being published.")
295 (defvar muse-publishing-current-output-path nil
296 "The path where the current file will be published to.")
297 (defvar muse-publishing-current-style nil
298 "The style of the file that is currently being published.")
299 (defvar muse-publishing-directives nil
300 "An alist of publishing directives from the top of a file.")
301 (defvar muse-publish-generate-contents nil
302 "Non-nil if a table of contents should be generated.
303 If non-nil, it is a cons cell specifying (MARKER . DEPTH), to
304 tell where the <contents> was seen, and to what depth the
305 contents were requested.")
306 (defvar muse-publishing-last-position nil
307 "Last position of the point when publishing.
308 This is used to make sure that publishing doesn't get stalled.")
310 ;; Functions for handling style information
312 (defsubst muse-style
(&optional style
)
313 "Resolve the given STYLE into a Muse style, if it is a string."
315 muse-publishing-current-style
317 (assoc style muse-publishing-styles
)
318 (muse-assert (consp style
))
321 (defun muse-define-style (name &rest elements
)
322 (let ((entry (assoc name muse-publishing-styles
)))
324 (setcdr entry elements
)
325 (setq muse-publishing-styles
326 (cons (append (list name
) elements
)
327 muse-publishing-styles
)))))
329 (defun muse-derive-style (new-name base-name
&rest elements
)
330 (apply 'muse-define-style new-name
331 (append elements
(list :base base-name
))))
333 (defsubst muse-get-keyword
(keyword list
&optional direct
)
334 (let ((value (cadr (memq keyword list
))))
335 (if (and (not direct
) (symbolp value
))
339 (defun muse-style-elements-list (elem &optional style
)
340 "Return a list all references to ELEM in STYLE, including base styles.
341 If STYLE is not specified, use current style."
344 (setq style
(muse-style style
))
345 (setq elements
(append elements
346 (muse-get-keyword elem style
)))
347 (setq style
(muse-get-keyword :base style
)))
350 (defsubst muse-style-element
(elem &optional style direct
)
351 "Search for ELEM in STYLE, including base styles.
352 If STYLE is not specified, use current style."
353 (setq style
(muse-style style
))
354 (let ((value (muse-get-keyword elem style direct
)))
357 (let ((base (muse-get-keyword :base style
)))
359 (muse-style-element elem base direct
))))))
361 (defun muse-find-markup-element (keyword ident style
)
362 (let ((def (assq ident
(muse-style-element keyword style
))))
365 (let ((base (muse-style-element :base style
)))
367 (muse-find-markup-element keyword ident base
))))))
369 (defun muse-markup-text (ident &rest args
)
370 "Insert ARGS into the text markup associated with IDENT.
371 If the markup text has sections like %N%, this will be replaced
372 with the N-1th argument in ARGS. After that, `format' is applied
373 to the text with ARGS as parameters."
374 (let ((text (muse-find-markup-element :strings ident
(muse-style))))
377 (let (start repl-text
)
378 (while (setq start
(string-match "%\\([1-9][0-9]*\\)%" text start
))
379 ;; escape '%' in the argument text, since we will be
380 ;; using format on it
381 (setq repl-text
(muse-replace-regexp-in-string
383 (nth (1- (string-to-number
384 (match-string 1 text
))) args
)
386 start
(+ start
(length repl-text
))
387 text
(replace-match repl-text t t text
))))
388 (apply 'format text args
))
391 (defun muse-insert-markup (&rest args
)
394 (muse-publish-mark-read-only beg
(point))))
396 (defun muse-find-markup-tag (keyword tagname style
)
397 (let ((def (assoc tagname
(muse-style-element keyword style
))))
399 (let ((base (muse-style-element :base style
)))
401 (muse-find-markup-tag keyword tagname base
))))))
403 (defsubst muse-markup-tag-info
(tagname &rest args
)
404 (let ((tag-info (muse-find-markup-tag :tags tagname
(muse-style))))
406 (assoc (match-string 1) muse-publish-markup-tags
))))
408 (defsubst muse-markup-function
(category)
409 (let ((func (muse-find-markup-element :functions category
(muse-style))))
411 (cdr (assq category muse-publish-markup-functions
)))))
413 ;; Publishing routines
415 (defun muse-publish-markup (name rules
)
416 (let* ((case-fold-search nil
)
417 (inhibit-read-only t
)
418 (limit (* (length rules
) (point-max)))
419 (verbose (and muse-publish-report-threshhold
420 (> (point-max) muse-publish-report-threshhold
)))
423 (goto-char (point-min))
424 (let ((regexp (nth 1 (car rules
)))
425 (group (nth 2 (car rules
)))
426 (repl (nth 3 (car rules
)))
428 (setq muse-publishing-last-position nil
)
430 (setq regexp
(symbol-value regexp
)))
431 (if (and verbose
(not muse-batch-publishing-p
))
432 (message "Publishing %s...%d%%" name
433 (* (/ (float (+ (point) base
)) limit
) 100)))
434 (while (and regexp
(setq pos
(re-search-forward regexp nil t
)))
435 (if (and verbose
(not muse-batch-publishing-p
))
436 (message "Publishing %s...%d%%" name
437 (* (/ (float (+ (point) base
)) limit
) 100)))
438 (unless (and (> (- (match-end 0) (match-beginning 0)) 0)
439 (get-text-property (match-beginning group
) 'read-only
))
443 (setq func
(muse-markup-function repl
)))
451 (replace-match text t
))))
452 (if (and muse-publishing-last-position
453 (= pos muse-publishing-last-position
))
457 (setq muse-publishing-last-position pos
)))
458 (setq rules
(cdr rules
)
459 base
(+ base
(point-max))))
460 (if (and verbose
(not muse-batch-publishing-p
))
461 (message "Publishing %s...done" name
))))
463 (defun muse-insert-file-or-string (file-or-string &optional title
)
464 (let ((beg (point)) end
)
465 (if (and (not (string-equal file-or-string
""))
466 (file-readable-p file-or-string
))
467 (setq end
(+ beg
(cadr (insert-file-contents file-or-string
))))
468 (insert file-or-string
)
471 (narrow-to-region beg end
)
472 (remove-text-properties (point-min) (point-max)
473 '(read-only nil rear-nonsticky nil
))
474 (goto-char (point-min))
475 (muse-publish-markup (or title
"")
476 '((100 "<\\(lisp\\)>" 0
477 muse-publish-markup-tag
))))))
479 (defun muse-style-run-hooks (keyword style
&rest args
)
482 (setq style
(muse-style style
)))
483 (let ((func (muse-get-keyword keyword style t
)))
487 (setq style
(muse-style-element :base style
)))))
489 (defun muse-publish-markup-region (beg end title style
)
490 "Apply the given STYLE's markup rules to the given region."
492 (narrow-to-region beg end
)
493 (muse-style-run-hooks :before style
)
496 (sort (copy-alist (append muse-publish-markup-regexps
497 (muse-style-elements-list :regexps style
)))
500 (< (car l
) (car r
))))))
501 (muse-style-run-hooks :before-end style
)
502 (muse-publish-escape-specials (point-min) (point-max) nil
'document
)))
504 (defun muse-publish-markup-buffer (title style
)
505 "Apply the given STYLE's markup rules to the current buffer."
506 (setq style
(muse-style style
))
507 (let ((style-header (muse-style-element :header style
))
508 (style-footer (muse-style-element :footer style
))
509 (muse-publishing-current-style style
)
510 (muse-publishing-directives
511 (list (cons "title" title
)
512 (cons "author" (user-full-name))
513 (cons "date" (format-time-string
515 (nth 5 (file-attributes
516 muse-publishing-current-file
))))))
517 (muse-publishing-p t
)
518 (inhibit-read-only t
))
519 (run-hooks 'muse-update-values-hook
)
520 (run-hooks 'muse-before-publish-hook
)
521 (muse-publish-markup-region (point-min) (point-max) title style
)
522 (goto-char (point-min))
524 (muse-insert-file-or-string style-header title
))
525 (goto-char (point-max))
527 (muse-insert-file-or-string style-footer title
))
528 (muse-style-run-hooks :after style
)
529 (run-hooks 'muse-after-publish-hook
)))
531 (defun muse-publish-markup-string (string &optional style
)
532 "Markup STRING using the given STYLE's markup rules."
533 (setq style
(muse-style style
))
534 (muse-with-temp-buffer
536 (let ((muse-publishing-current-style style
)
537 (muse-publishing-p t
))
538 (muse-publish-markup "*string*" (muse-style-element :rules style
)))
541 ;; Commands for publishing files
543 (defsubst muse-publish-get-style
(&optional styles
)
544 (unless styles
(setq styles muse-publishing-styles
))
545 (if (= 1 (length styles
))
547 (assoc (completing-read "Publish with style: " styles nil t
)
550 (defsubst muse-publish-get-output-dir
(style)
551 (let ((default-directory (or (muse-style-element :path style
)
553 (muse-read-directory-name "Publish to directory: " nil default-directory
)))
555 (defsubst muse-publish-get-info
()
556 (let ((style (muse-publish-get-style)))
557 (list style
(muse-publish-get-output-dir style
)
558 current-prefix-arg
)))
560 (defsubst muse-publish-output-name
(&optional file style
)
561 (setq style
(muse-style style
))
562 (concat (muse-style-element :prefix style
)
563 (muse-page-name file
)
564 (muse-style-element :suffix style
)))
566 (defsubst muse-publish-output-file
(file &optional output-dir style
)
567 (setq style
(muse-style style
))
569 (expand-file-name (muse-publish-output-name file style
) output-dir
)
570 (concat (file-name-directory file
)
571 (muse-publish-output-name file style
))))
573 (defsubst muse-publish-link-name
(&optional file style
)
574 (setq style
(muse-style style
))
575 (concat (muse-style-element :prefix style
)
576 (muse-page-name file
)
577 (or (muse-style-element :link-suffix style
)
578 (muse-style-element :suffix style
))))
580 (defsubst muse-publish-link-file
(file &optional output-dir style
)
581 (setq style
(muse-style style
))
583 (expand-file-name (muse-publish-link-name file style
) output-dir
)
584 (concat (file-name-directory file
)
585 (muse-publish-link-name file style
))))
588 (defun muse-publish-file (file style
&optional output-dir force
)
589 "Publish the given FILE in a particular STYLE to OUTPUT-DIR.
590 If the argument FORCE is nil, each file is only published if it is
591 newer than the published version. If the argument FORCE is non-nil,
592 the file is published no matter what."
593 (interactive (cons (read-file-name "Publish file: ")
594 (muse-publish-get-info)))
595 (let ((style-name style
))
596 (setq style
(muse-style style
))
598 (error "There is no style '%s' defined." style-name
)))
599 (let* ((output-path (muse-publish-output-file file output-dir style
))
600 (output-suffix (muse-style-element :osuffix style
))
601 (muse-publishing-current-file file
)
602 (muse-publishing-current-output-path output-path
)
603 (target (if output-suffix
604 (concat (file-name-sans-extension output-path
)
607 (threshhold (nth 7 (file-attributes file
))))
609 (message "Please save %s before publishing" file
)
610 (when (or force
(file-newer-than-file-p file target
))
611 (if (and muse-publish-report-threshhold
613 muse-publish-report-threshhold
))
614 (message "Publishing %s ..." file
))
615 (muse-with-temp-buffer
616 (insert-file-contents file
)
617 (muse-publish-markup-buffer (muse-page-name file
) style
)
618 (let ((backup-inhibited t
))
619 (write-file output-path
))
620 (muse-style-run-hooks :final style file output-path target
))
624 (defun muse-publish-this-file (style output-dir
&optional force
)
625 "Publish the page in the current file."
626 (interactive (muse-publish-get-info))
627 (unless (muse-publish-file buffer-file-name style output-dir force
)
628 (message (concat "The published version is up-to-date; use"
629 " C-u C-c C-t to force an update."))))
631 (defun muse-batch-publish-files ()
632 "Publish Muse files in batch mode."
633 (let ((muse-batch-publishing-p t
)
635 (setq style
(car command-line-args-left
)
636 command-line-args-left
(cdr command-line-args-left
)
637 output-dir
(car command-line-args-left
)
639 (if (string-match "\\`--output-dir=" output-dir
)
641 (substring output-dir
(match-end 0))
642 (setq command-line-args-left
(cdr command-line-args-left
)))))
643 (setq auto-mode-alist
644 (delete (cons (concat "\\." muse-file-extension
"\\'")
645 'muse-mode-choose-mode
)
647 (dolist (file command-line-args-left
)
648 (muse-publish-file file style output-dir t
))))
650 ;; Default publishing rules
652 (defun muse-publish-section-close (depth)
653 "Seach forward for the closing tag of given DEPTH."
656 (while (and (setq not-end
(re-search-forward
657 (concat "^\\*\\{1," (number-to-string depth
)
660 (get-text-property (match-beginning 0) 'read-only
)))
663 (goto-char (point-max)))
664 (cond ((not (eq (char-before) ?
\n))
666 ((not (eq (char-before (1- (point))) ?
\n))
668 (muse-insert-markup (muse-markup-text 'section-close depth
))
671 (defun muse-publish-markup-directive (&optional name value
)
672 (unless name
(setq name
(match-string 1)))
673 (unless value
(setq value
(match-string 2)))
674 (let ((elem (assoc name muse-publishing-directives
)))
677 (setq muse-publishing-directives
678 (cons (cons name value
)
679 muse-publishing-directives
))))
680 ;; Make sure we don't ever try to move the point forward (past the
681 ;; beginning of buffer) while we're still searching for directives.
682 (setq muse-publishing-last-position nil
)
683 (delete-region (match-beginning 0) (match-end 0)))
685 (defsubst muse-publishing-directive
(name)
686 (cdr (assoc name muse-publishing-directives
)))
688 (defun muse-publish-markup-anchor ()
689 (unless (get-text-property (match-end 1) 'noemphasis
)
690 (let ((text (muse-markup-text 'anchor
(match-string 2))))
691 (unless (string= text
"")
693 (skip-chars-forward (concat muse-regexp-blank
"\n"))
694 (muse-insert-markup text
)))
697 (defun muse-publish-markup-comment ()
698 (if (null muse-publish-comments-p
)
700 (goto-char (match-end 0))
701 (muse-insert-markup (muse-markup-text 'comment-end
))
702 (muse-publish-mark-read-only (match-beginning 1) (match-end 1))
703 (delete-region (match-beginning 0) (match-beginning 1))
704 (goto-char (match-beginning 0))
705 (muse-insert-markup (muse-markup-text 'comment-begin
))))
707 (defun muse-publish-markup-tag ()
708 (let ((tag-info (muse-markup-tag-info (match-string 1))))
710 (not (get-text-property (match-beginning 0) 'read-only
)))
711 (let ((closed-tag (match-string 3))
712 (start (match-beginning 0))
715 (when (nth 2 tag-info
)
716 (let ((attrstr (match-string 2)))
718 (string-match (concat "\\([^"
723 (let ((attr (cons (downcase
724 (muse-match-string-no-properties 1 attrstr
))
725 (muse-match-string-no-properties 3 attrstr
))))
726 (setq attrstr
(replace-match "" t t attrstr
))
728 (nconc attrs
(list attr
))
729 (setq attrs
(list attr
)))))))
730 (if (and (cadr tag-info
) (not closed-tag
))
731 (if (search-forward (concat "</" (car tag-info
) ">") nil t
)
732 (delete-region (match-beginning 0) (point))
733 (setq tag-info nil
)))
735 (setq end
(point-marker))
736 (delete-region start beg
)
738 (let ((args (list start end
)))
740 (nconc args
(list attrs
)))
741 (apply (nth 3 tag-info
) args
))))))
744 (defun muse-publish-escape-specials (beg end
&optional ignore-read-only context
)
745 "Escape specials from BEG to END using style-specific :specials.
746 If IGNORE-READ-ONLY is non-nil, ignore the read-only property.
747 CONTEXT is used to figure out what kind of specials to escape.
749 The following contexts exist in Muse.
750 'underline _underlined text_
751 'literal =monospaced text= or <code> region (monospaced, escaped)
752 'emphasis *emphasized text*
753 'email email@example.com
754 'url http://example.com
755 'url-desc [[...][description of an extended link]]
756 'example <example> region (monospaced, block context, escaped)
757 'verbatim <verbatim> region (escaped)
758 'document normal text"
759 (let ((specials (muse-style-element :specials nil t
)))
760 (cond ((functionp specials
)
761 (setq specials
(funcall specials context
)))
763 (setq specials
(symbol-value specials
))))
764 (if (functionp specials
)
765 (funcall specials beg end ignore-read-only
)
768 (narrow-to-region beg end
)
769 (goto-char (point-min))
770 (while (< (point) (point-max))
771 (if (and (not ignore-read-only
)
772 (get-text-property (point) 'read-only
))
773 (goto-char (or (next-single-property-change (point) 'read-only
)
775 (let ((repl (or (assoc (char-after) specials
)
777 muse-publish-markup-specials
))))
781 (insert-before-markers (cdr repl
)))))))))))
783 (defun muse-publish-markup-word ()
784 (let* ((beg (match-beginning 2))
785 (end (1- (match-end 2)))
786 (leader (buffer-substring-no-properties beg end
))
787 open-tag close-tag mark-read-only loc context
)
789 ((string= leader
"_")
790 (setq context
'underline
791 open-tag
(muse-markup-text 'begin-underline
)
792 close-tag
(muse-markup-text 'end-underline
)))
793 ((string= leader
"=")
794 (setq context
'literal
795 open-tag
(muse-markup-text 'begin-literal
)
796 close-tag
(muse-markup-text 'end-literal
))
797 (setq mark-read-only t
))
799 (let ((l (length leader
)))
800 (setq context
'emphasis
)
802 ((= l
1) (setq open-tag
(muse-markup-text 'begin-emph
)
803 close-tag
(muse-markup-text 'end-emph
)))
804 ((= l
2) (setq open-tag
(muse-markup-text 'begin-more-emph
)
805 close-tag
(muse-markup-text 'end-more-emph
)))
806 ((= l
3) (setq open-tag
(muse-markup-text 'begin-most-emph
)
807 close-tag
(muse-markup-text 'end-most-emph
)))
808 (t (setq context nil
))))))
810 (not (get-text-property beg
'noemphasis
))
811 (setq loc
(search-forward leader nil t
))
812 (or (eobp) (not (eq (char-syntax (char-after loc
)) ?w
)))
813 (not (eq (char-syntax (char-before (point))) ?\
))
814 (not (get-text-property (point) 'noemphasis
)))
817 (delete-region beg end
)
818 (setq end
(point-marker))
819 (muse-insert-markup close-tag
)
821 (muse-insert-markup open-tag
)
824 (muse-publish-escape-specials beg end t context
)
825 (muse-publish-mark-read-only beg end
)))
829 (defun muse-publish-markup-emdash ()
830 (let ((prespace (match-string 1))
831 (postspace (match-string 2)))
832 (delete-region (match-beginning 0) (match-end 0))
833 (muse-insert-markup (muse-markup-text 'emdash prespace postspace
))
834 (when (eq (char-after) ?\
<)
837 (defun muse-publish-markup-enddots ()
838 (unless (get-text-property (match-beginning 0) 'noemphasis
)
839 (delete-region (match-beginning 0) (match-end 0))
840 (muse-insert-markup (muse-markup-text 'enddots
))))
842 (defun muse-publish-markup-dots ()
843 (unless (get-text-property (match-beginning 0) 'noemphasis
)
844 (delete-region (match-beginning 0) (match-end 0))
845 (muse-insert-markup (muse-markup-text 'dots
))))
847 (defun muse-publish-markup-rule ()
848 (unless (get-text-property (match-beginning 0) 'noemphasis
)
849 (delete-region (match-beginning 0) (match-end 0))
850 (muse-insert-markup (muse-markup-text 'rule
))))
852 (defun muse-publish-markup-no-break-space ()
853 (unless (get-text-property (match-beginning 0) 'noemphasis
)
854 (delete-region (match-beginning 0) (match-end 0))
855 (muse-insert-markup (muse-markup-text 'no-break-space
))))
857 (defun muse-publish-markup-heading ()
858 (let* ((len (length (match-string 1)))
859 (start (muse-markup-text
860 (cond ((= len
1) 'section
)
861 ((= len
2) 'subsection
)
862 ((= len
3) 'subsubsection
)
865 (end (muse-markup-text
866 (cond ((= len
1) 'section-end
)
867 ((= len
2) 'subsection-end
)
868 ((= len
3) 'subsubsection-end
)
869 (t 'section-other-end
))
871 (delete-region (match-beginning 0) (match-end 0))
872 (muse-insert-markup start
)
875 (muse-insert-markup end
))
876 (muse-publish-section-close len
)))
878 (defvar muse-publish-footnotes nil
)
880 (defun muse-publish-markup-footnote ()
881 "Scan ahead and snarf up the footnote body"
883 ((get-text-property (match-beginning 0) 'noemphasis
)
885 ((= (muse-line-beginning-position) (match-beginning 0))
888 (let ((footnote (save-match-data
889 (string-to-number (match-string 1))))
891 (delete-region (match-beginning 0) (match-end 0))
893 (when (re-search-forward (format "^\\[%d\\]\\s-+" footnote
) nil t
)
894 (let* ((start (match-beginning 0))
895 (beg (goto-char (match-end 0)))
897 (if (search-forward "\n\n" nil t
)
898 (copy-marker (match-beginning 0))
899 (goto-char (point-max))
900 (skip-chars-backward "\n")
902 (while (re-search-forward
903 (concat "^[" muse-regexp-blank
"]+\\([^\n]\\)")
905 (replace-match "\\1" t
))
906 (let ((footnotemark-cmd (muse-markup-text 'footnotemark
))
907 (footnotemark-end-cmd (muse-markup-text 'footnotemark-end
)))
908 (if (string= "" footnotemark-cmd
)
910 (concat (muse-markup-text 'footnote
)
911 (buffer-substring-no-properties beg end
)
912 (muse-markup-text 'footnote-end
)))
913 (setq footnotemark
(format footnotemark-cmd footnote
914 footnotemark-end-cmd
))
915 (unless muse-publish-footnotes
916 (set (make-local-variable 'muse-publish-footnotes
)
917 (make-vector 256 nil
)))
918 (unless (aref muse-publish-footnotes footnote
)
922 (concat (format (muse-markup-text 'footnotetext
)
924 (buffer-substring-no-properties beg end
)
925 (muse-markup-text 'footnotetext-end
))))
926 (aset muse-publish-footnotes footnote footnotemark
))))
928 (skip-chars-forward "\n")
929 (delete-region start
(point)))))
930 (muse-insert-markup (or footnotemark footnote
))))))
932 (defun muse-publish-markup-fn-sep ()
933 (delete-region (match-beginning 0) (match-end 0))
934 (muse-insert-markup (muse-markup-text 'fn-sep
)))
936 (defun muse-insert-markup-end-list (&rest args
)
939 (add-text-properties beg
(point) '(end-list t
))
940 (muse-publish-mark-read-only beg
(point))))
942 (defun muse-publish-surround-dl (indent post-indent
)
943 (let* ((beg-item (muse-markup-text 'begin-dl-item
))
944 (end-item (muse-markup-text 'end-dl-item
))
945 (beg-ddt (muse-markup-text 'begin-ddt
)) ;; term
946 (end-ddt (muse-markup-text 'end-ddt
))
947 (beg-dde (muse-markup-text 'begin-dde
)) ;; definition
948 (end-dde (muse-markup-text 'end-dde
))
950 def-on-same-line beg
)
952 ;; envelope this as one term+definitions unit -- HTML does not
953 ;; need this, but DocBook and Muse's custom XML format do
954 (muse-insert-markup beg-item
)
955 (when (looking-at muse-dl-term-regexp
)
956 ;; find the term and wrap it with published markup
958 (goto-char (match-end 1))
959 (delete-region (point) (match-end 0))
960 (muse-insert-markup-end-list end-ddt
)
961 ;; if definition is immediately after term, move to next line
962 (unless (eq (char-after) ?
\n)
966 (delete-region (point) (match-beginning 1))
967 (muse-insert-markup beg-ddt
)))
969 ;; move past current item
970 continue
(muse-forward-list-item 'dl-term indent
))
972 (narrow-to-region beg
(point))
973 (goto-char (point-min))
974 ;; publish each definition that we find, defaulting to an
975 ;; empty definition if none are found
976 (muse-publish-surround-text beg-dde end-dde
978 (muse-forward-list-item 'dl-entry indent
))
980 (goto-char (point-max))
981 (skip-chars-backward (concat muse-regexp-blank
"\n"))
982 (muse-insert-markup-end-list end-item
)
984 (goto-char (point-max)))))))
986 (defun muse-publish-surround-text (beg-tag end-tag move-func
&optional indent post-indent determine-indent
)
988 (list-item (format muse-list-item-regexp
989 (concat "[" muse-regexp-blank
"]*")))
992 (setq indent
(concat "[" muse-regexp-blank
"]+")))
994 (setq post-indent
(concat " \\{0," (number-to-string post-indent
)
996 (setq post-indent
""))
998 (muse-insert-markup beg-tag
)
1000 ;; move past current item; continue is non-nil if there
1001 ;; are more like items to be processed
1002 continue
(funcall move-func indent
))
1004 (when determine-indent
1005 ;; if the caller doesn't know how much indentation
1006 ;; to use, figure it out ourselves
1010 ;; snarf all leading whitespace
1011 (let ((this-indent (and (match-beginning 2)
1012 (buffer-substring (match-beginning 1)
1013 (match-beginning 2)))))
1014 (when (and this-indent
1015 (not (string= this-indent
"")))
1016 (setq indent this-indent
1017 determine-indent nil
))))))
1019 ;; remove list markup if we encountered another item of the
1021 (replace-match "" t t nil
1))
1022 (narrow-to-region beg
(point))
1023 ;; narrow to current item
1024 (goto-char (point-min))
1026 (let ((list-nested nil
)
1028 (post-indent post-indent
))
1029 (while (< (point) (point-max))
1030 (when (and (looking-at list-item
)
1031 (not (get-text-property (muse-list-item-critical-point)
1033 ;; if we encounter a list item, allow no post-indent
1035 (setq list-nested t
))
1036 (when (looking-at (concat indent
"\\("
1037 (or (and list-nested
"")
1040 ;; if list is not nested, remove indentation
1041 (unless indent-found
1042 (setq post-indent
(match-string 1)
1046 (skip-chars-backward (concat muse-regexp-blank
"\n"))
1047 (muse-insert-markup-end-list end-tag
)
1049 (goto-char (point-max)))))))
1051 (defun muse-publish-markup-list ()
1052 "Markup a list entry.
1053 The reason this function is so funky, is to prevent text properties
1054 like read-only from being inadvertently deleted."
1055 (let* ((str (match-string 1))
1056 (type (muse-list-item-type str
))
1057 (indent (buffer-substring (muse-line-beginning-position)
1058 (match-beginning 1)))
1059 (post-indent (length str
))
1060 (last (match-beginning 0)))
1062 ((get-text-property (muse-list-item-critical-point) 'read-only
)
1065 (unless (eq (char-after (match-end 1)) ?-
)
1066 (delete-region (match-beginning 0) (match-end 0))
1067 (muse-insert-markup (muse-markup-text 'begin-uli
))
1069 (muse-publish-surround-text
1070 (muse-markup-text 'begin-uli-item
)
1071 (muse-markup-text 'end-uli-item
)
1073 (muse-forward-list-item 'ul indent
))
1075 (muse-insert-markup-end-list (muse-markup-text 'end-uli
)))
1078 (delete-region (match-beginning 0) (match-end 0))
1079 (muse-insert-markup (muse-markup-text 'begin-oli
))
1081 (muse-publish-surround-text
1082 (muse-markup-text 'begin-oli-item
)
1083 (muse-markup-text 'end-oli-item
)
1085 (muse-forward-list-item 'ol indent
))
1087 (muse-insert-markup-end-list (muse-markup-text 'end-oli
)))
1089 ((not (string= (match-string 2) ""))
1090 ;; must have an initial term
1091 (goto-char (match-beginning 0))
1092 (muse-insert-markup (muse-markup-text 'begin-dl
))
1094 (muse-publish-surround-dl indent post-indent
)
1095 (muse-insert-markup-end-list (muse-markup-text 'end-dl
)))
1099 (defun muse-publish-markup-quote ()
1100 "Markup a quoted paragraph.
1101 The reason this function is so funky, is to prevent text properties
1102 like read-only from being inadvertently deleted."
1103 (let* ((ws (match-string 1))
1104 (centered (>= (string-width ws
) 6))
1105 (begin-elem (if centered
'begin-center
'begin-quote-item
))
1106 (end-elem (if centered
'end-center
'end-quote-item
)))
1107 (replace-match "" t t nil
1)
1109 (muse-insert-markup (muse-markup-text 'begin-quote
)))
1110 (muse-publish-surround-text (muse-markup-text begin-elem
)
1111 (muse-markup-text end-elem
)
1112 (function (lambda (indent)
1113 (muse-forward-paragraph)
1116 (muse-insert-markup (muse-markup-text 'end-quote
)))))
1118 (defun muse-publish-markup-leading-space (markup-space multiple
)
1120 (when (and markup-space
1121 (>= (setq count
(skip-chars-forward " ")) 0))
1122 (delete-region (muse-line-beginning-position) (point))
1124 (muse-insert-markup markup-space
)
1125 (setq count
(- count multiple
))))))
1127 (defun muse-publish-markup-verse ()
1128 (let ((leader (match-string 0)))
1129 (goto-char (match-beginning 0))
1130 (muse-insert-markup (muse-markup-text 'begin-verse
))
1131 (while (looking-at leader
)
1133 (muse-publish-markup-leading-space (muse-markup-text 'verse-space
) 2)
1134 (let ((beg (point)))
1138 (let ((text (muse-markup-text 'empty-verse-line
)))
1139 (when text
(muse-insert-markup text
))))
1143 (or (looking-at (concat leader
"["
1146 (not (looking-at leader
)))))
1147 (let ((begin-text (muse-markup-text 'begin-last-stanza-line
))
1148 (end-text (muse-markup-text 'end-last-stanza-line
)))
1149 (when end-text
(muse-insert-markup end-text
))
1151 (when begin-text
(muse-insert-markup begin-text
))
1154 (let ((begin-text (muse-markup-text 'begin-verse-line
))
1155 (end-text (muse-markup-text 'end-verse-line
)))
1156 (when end-text
(muse-insert-markup end-text
))
1158 (when begin-text
(muse-insert-markup begin-text
))
1161 (muse-insert-markup (muse-markup-text 'end-verse
))
1164 (defun muse-publish-table-fields (beg end
)
1165 "Parse given region as a table, returning a cons cell.
1166 The car is the length of the longest row.
1168 The cdr is a list of the fields of the table, with the first
1169 element indicating the type of the row:
1170 1: body, 2: header, 3: footer.
1172 The existing region will be removed, except for initial blank lines."
1173 (unless (muse-publishing-directive "disable-tables")
1178 (narrow-to-region beg end
)
1179 (goto-char (point-min))
1180 (while (looking-at (concat "^[" muse-regexp-blank
"]*$"))
1184 (when (looking-at muse-table-line-regexp
)
1185 (setq fields
(cons (length (match-string 1))
1186 (split-string (match-string 0)
1187 muse-table-field-regexp
))
1188 field-list
(cons fields field-list
)
1189 longest
(max (length fields
) longest
)))
1190 (setq left
(forward-line 1))))
1191 (delete-region beg end
)
1194 (cons (1- longest
) (nreverse field-list
))))))
1196 (defun muse-publish-markup-table ()
1197 "Style does not support tables.")
1199 (defun muse-publish-escape-specials-in-string (string &optional context
)
1200 "Escape specials in STRING using style-specific :specials.
1201 CONTEXT is used to figure out what kind of specials to escape.
1203 See the documentation of the `muse-publish-escape-specials'
1204 function for the list of available contexts."
1207 (let ((specials (muse-style-element :specials nil t
)))
1208 (cond ((functionp specials
)
1209 (setq specials
(funcall specials context
)))
1211 (setq specials
(symbol-value specials
))))
1212 (if (functionp specials
)
1213 (funcall specials string
)
1214 (apply (function concat
)
1218 (setq repl
(or (assoc ch specials
)
1219 (assoc ch muse-publish-markup-specials
)))
1223 (append string nil
))))))
1225 (defun muse-publish-markup-email ()
1226 (let* ((beg (match-end 1))
1227 (addr (buffer-substring-no-properties beg
(match-end 0))))
1228 (setq addr
(muse-publish-escape-specials-in-string addr
'email
))
1230 (delete-region beg
(match-end 0))
1231 (if (or (eq (char-before (match-beginning 0)) ?
\")
1232 (eq (char-after (match-end 0)) ?
\"))
1234 (insert (format (muse-markup-text 'email-addr
) addr addr
)))
1235 (muse-publish-mark-read-only beg
(point))))
1237 (defun muse-publish-classify-url (target)
1238 "Transform anchors and get published name, if TARGET is a page.
1239 The return value is a cons cell. The car is the type of link,
1240 the cadr is the page name, and the cddr is the anchor."
1242 (cond ((or (null target
) (string= target
""))
1244 ((string-match muse-url-regexp target
)
1245 (cons 'url
(cons target nil
)))
1246 ((string-match muse-image-regexp target
)
1247 (cons 'image
(cons target nil
)))
1248 ((string-match muse-file-regexp target
)
1249 (cons 'file
(cons target nil
)))
1250 ((string-match "#" target
)
1251 (if (eq (aref target
0) ?\
#)
1252 (cons 'anchor-ref
(cons nil
(substring target
1)))
1253 (cons 'link-and-anchor
1254 (cons (muse-publish-link-name
1255 (substring target
0 (match-beginning 0)))
1256 (substring target
(match-end 0))))))
1258 (cons 'link
(cons (muse-publish-link-name target
) nil
))))))
1260 (defun muse-publish-url (url &optional desc explicit
)
1261 "Resolve a URL into its final <a href> form."
1262 (let ((orig-url url
)
1264 (dolist (transform muse-publish-url-transforms
)
1265 (setq url
(save-match-data (when url
(funcall transform url explicit
)))))
1266 (dolist (transform muse-publish-desc-transforms
)
1267 (setq desc
(save-match-data
1268 (when desc
(funcall transform desc explicit
)))))
1270 (setq desc
(muse-publish-escape-specials-in-string desc
'url-desc
)))
1272 (muse-publish-escape-specials-in-string orig-url
'url-desc
))
1273 (let ((target (muse-publish-classify-url url
)))
1274 (setq type
(car target
)
1275 url
(muse-publish-escape-specials-in-string (cadr target
) 'url
)
1276 anchor
(muse-publish-escape-specials-in-string
1277 (cddr target
) 'url
)))
1278 (cond ((eq type
'anchor-ref
)
1279 (muse-markup-text 'anchor-ref anchor
(or desc orig-url
)))
1284 (muse-markup-text 'image-with-desc url desc
)
1285 (muse-markup-text 'image-link url
)))
1286 ((eq type
'link-and-anchor
)
1287 (muse-markup-text 'link-and-anchor url anchor
1288 (or desc orig-url
)))
1289 ((and desc
(string-match muse-image-regexp desc
))
1290 (muse-markup-text 'url-with-image url desc
))
1292 (muse-markup-text 'link url
(or desc orig-url
)))
1295 (let ((text (muse-markup-text 'url-and-desc url desc
)))
1296 (and (not (string= text
""))
1298 (muse-markup-text 'url url
(or desc orig-url
)))))))
1300 (defun muse-publish-insert-url (url &optional desc explicit
)
1301 "Resolve a URL into its final <a href> form."
1302 (delete-region (match-beginning 0) (match-end 0))
1303 (let ((text (muse-publish-url url desc explicit
)))
1305 (muse-insert-markup text
))))
1307 (defun muse-publish-markup-link ()
1308 (let (desc explicit link
)
1309 (setq explicit
(save-match-data
1310 (if (string-match muse-explicit-link-regexp
1313 (setq desc
(if explicit
(match-string 2) (match-string 0)))
1314 (setq link
(if explicit
1315 (muse-handle-explicit-link (match-string 1))
1316 (muse-handle-implicit-link (match-string 0))))
1319 (not (or (eq (char-before (match-beginning 0)) ?
\")
1320 (eq (char-after (match-end 0)) ?
\")))))
1321 (muse-publish-insert-url link desc explicit
))))
1323 (defun muse-publish-markup-url ()
1324 (unless (or (eq (char-before (match-beginning 0)) ?
\")
1325 (eq (char-after (match-end 0)) ?
\"))
1326 (muse-publish-insert-url (match-string 0))))
1328 ;; Default publishing tags
1330 (defun muse-publish-contents-tag (beg end attrs
)
1331 (set (make-local-variable 'muse-publish-generate-contents
)
1332 (cons (copy-marker (point) t
)
1333 (let ((depth (cdr (assoc "depth" attrs
))))
1334 (or (and depth
(string-to-number depth
)) 2)))))
1336 (defun muse-publish-verse-tag (beg end
)
1339 (narrow-to-region beg end
)
1340 (goto-char (point-min))
1341 (while (eq ?\
(char-syntax (char-after)))
1343 (while (< (point) (point-max))
1346 (if (eq ?\
(char-syntax (char-before)))
1347 (delete-char -
1)))))
1349 (defun muse-publish-mark-read-only (beg end
)
1350 "Add read-only properties to the given region."
1351 (add-text-properties beg end
'(rear-nonsticky (read-only) read-only t
))
1354 (defun muse-publish-mark-noemphasis (&optional beg end
)
1355 "Make sure that no emphasis characters are interpreted within
1356 the given region. If a region is not specified, use the 0th
1357 match data to determine it.
1359 This is usually applied to extended links."
1360 (unless beg
(setq beg
(match-beginning 0)))
1361 (unless end
(setq end
(match-end 0)))
1362 (add-text-properties beg end
'(noemphasis t
))
1365 (defun muse-publish-quote-tag (beg end
)
1368 (narrow-to-region beg end
)
1369 (muse-insert-markup (muse-markup-text 'begin-quote
))
1370 (muse-publish-surround-text (muse-markup-text 'begin-quote-item
)
1371 (muse-markup-text 'end-quote-item
)
1372 (function (lambda (indent)
1373 (muse-forward-paragraph)
1374 (goto-char (match-end 0))
1375 (< (point) (point-max)))))
1376 (muse-insert-markup (muse-markup-text 'end-quote
)))))
1378 (defun muse-publish-code-tag (beg end
)
1379 (muse-publish-escape-specials beg end nil
'literal
)
1381 (insert (muse-markup-text 'begin-literal
))
1383 (insert (muse-markup-text 'end-literal
))
1384 (muse-publish-mark-read-only beg
(point)))
1386 (defun muse-publish-example-tag (beg end
)
1387 (muse-publish-escape-specials beg end nil
'example
)
1389 (insert (muse-markup-text 'begin-example
))
1391 (insert (muse-markup-text 'end-example
))
1392 (muse-publish-mark-read-only beg
(point)))
1394 (defun muse-publish-verbatim-tag (beg end
)
1395 (muse-publish-escape-specials beg end nil
'verbatim
)
1396 (muse-publish-mark-read-only beg end
))
1398 (defalias 'muse-publish-class-tag
'ignore
)
1400 (defun muse-publish-lisp-tag (beg end
)
1402 (let ((str (muse-eval-lisp
1405 (buffer-substring-no-properties beg end
)
1407 (delete-region beg end
)))))
1408 (set-text-properties 0 (length str
) nil str
)
1411 (defun muse-publish-command-tag (beg end attrs
)
1412 (while (looking-at "\\s-*$")
1414 (let ((interp (cdr (assoc "interp" attrs
))))
1418 (buffer-substring-no-properties (point) end
)
1419 (delete-region beg end
)) t
)
1420 (shell-command-on-region beg end interp t t
))
1421 (muse-publish-mark-read-only beg
(point))))
1423 (defun muse-publish-comment-tag (beg end
)
1424 (if (null muse-publish-comments-p
)
1425 (delete-region beg end
)
1427 (muse-insert-markup (muse-markup-text 'comment-end
))
1428 (muse-publish-mark-read-only beg end
)
1430 (muse-insert-markup (muse-markup-text 'comment-begin
))))
1432 ;; Miscellaneous helper functions
1434 (defun muse-publish-strip-tags (string)
1435 "Remove all tags from the string."
1436 (while (string-match "<.*?>" string
)
1437 (setq string
(replace-match "" nil t string
)))
1440 (defun muse-publish-markup-type (category default-func
)
1441 (let ((rule (muse-find-markup-element :overrides category
(muse-style))))
1442 (funcall (or rule default-func
))))
1444 (defun muse-published-buffer-contents (buffer)
1445 (with-current-buffer buffer
1446 (goto-char (point-min))
1447 (let ((beg (and (search-forward "Emacs Muse begins here")
1448 (muse-line-end-position)))
1449 (end (and (search-forward "Emacs Muse ends here")
1450 (muse-line-beginning-position))))
1451 (buffer-substring-no-properties beg end
))))
1453 (defun muse-published-contents (file)
1454 (when (file-readable-p file
)
1455 (muse-with-temp-buffer
1456 (insert-file-contents file
)
1457 (muse-published-buffer-contents (current-buffer)))))
1459 (defun muse-publish-transform-output
1460 (file temp-file output-path name gen-func
&rest cleanup-exts
)
1461 "Transform the given TEMP-FILE into the OUTPUT-PATH, using GEN-FUNC."
1462 (setq file
(muse-page-name file
))
1463 (message "Generating %s output for %s..." name file
)
1464 (if (not (funcall gen-func temp-file output-path
))
1465 (message "Generating %s from %s...failed" name file
)
1466 (message "Generating %s output for %s...done" name file
)
1467 (muse-delete-file-if-exists temp-file
)
1468 (dolist (ext cleanup-exts
)
1469 (muse-delete-file-if-exists
1470 (expand-file-name (concat file ext
)
1471 (file-name-directory output-path
))))
1472 (message "Wrote %s" output-path
)))
1474 (defun muse-publish-read-only (string)
1475 (let ((end (1- (length string
))))
1476 (add-text-properties 0 end
1477 '(rear-nonsticky (read-only) read-only t
)
1481 (provide 'muse-publish
)
1483 ;;; muse-publish.el ends here