2 @comment %**start of header
3 @setfilename ../../info/htmlfontify
4 @settitle Htmlfontify User Manual
6 @comment %**end of header
9 This manual documents Htmlfontify, a source code -> crosslinked +
10 formatted + syntax colorized html transformer.
12 Copyright @copyright{} 2002, 2003, 2013 Free Software Foundation, Inc.
15 Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.3 or
17 any later version published by the Free Software Foundation; with no
18 Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
19 and with the Back-Cover Texts as in (a) below. A copy of the license
20 is included in the section entitled ``GNU Free Documentation License''.
22 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
23 modify this GNU manual.''
27 @dircategory Emacs misc features
29 * Htmlfontify: (htmlfontify). Convert source code to html.
33 @title Htmlfontify User Manual
35 @subtitle Htmlfontify version 0.20
39 @author Vivek Dasmohapatra
42 @vskip 0pt plus 1filll
57 * Introduction:: About Htmlfontify.
58 * Usage & Examples:: How to use Htmlfontify.
59 * Customization:: Fine-tuning Htmlfontify's behaviour.
60 * Requirements:: External programs used by Htmlfontify.
61 * GNU Free Documentation License:: The license for this documentation.
62 * Index:: Index of contents.
69 Htmlfontify provides a means of converting individual Emacs buffers,
70 source files, or entire source trees to html, preserving formatting
71 and Emacs colorization / syntax highlighting as much as possible
72 through careful application of CSS stylesheets and html tags.
74 It can also turn instances of functions, methods and (for some
75 languages) variables and other constructs and items into links
76 to their definitions, and create an index file (or files) of
77 all such symbols, also linked to their points of definition.
79 Htmlfontify also provides several customization items, which should
80 allow it to mesh more-or-less seamlessly with various templating or
81 publishing systems (in the event, for instance, that you don't want
82 to produce the html pages directly).
84 @node Usage & Examples
85 @chapter Usage & Examples
86 @cindex Usage & Examples
88 Htmlfontify can be used both interactively and as part of another
89 elisp function. If you're running it in a modern Emacs, it will also
90 run when attached to a terminal (i.e., without X) or even when in
94 * Interactive:: Using Htmlfontify interactively.
95 * Non-interactive:: Using Htmlfontify from elisp.
96 * Variables:: Variables (other than customization entries).
97 * Data Structures:: Important data structures.
98 * Examples:: Example(s) of Htmlfontify in use.
104 @cindex functions (interactive)
106 Htmlfontify provides the following interactive functions:
109 @item htmlfontify-buffer
110 @findex htmlfontify-buffer
111 @anchor{htmlfontify-buffer}
115 (htmlfontify-buffer &optional @var{srcdir} @var{file})
118 Create a new buffer, named for the current buffer + a .html extension,
119 containing an inline CSS-stylesheet and formatted CSS-markup html that
120 reproduces the look of the current Emacs buffer as closely as possible.
122 ``Dangerous'' characters in the existing buffer are turned into html
123 entities, so you should even be able to do html-within-html fontified
126 You should, however, note that random control or non-ASCII characters
127 such as ^L (\x0c) or ยค (\xa4) won't get mapped yet.
129 If the @var{srcdir} and @var{file} arguments are set, lookup etags
130 derived entries in the @ref{hfy-tags-cache} and add html anchors
131 and hyperlinks as appropriate.
133 @item htmlfontify-run-etags
134 @findex htmlfontify-run-etags
135 @anchor{htmlfontify-run-etags}
139 (htmlfontify-run-etags @var{srcdir})
142 Load the etags cache for @var{srcdir}. See @ref{hfy-load-tags-cache}.
144 @item htmlfontify-copy-and-link-dir
145 @findex htmlfontify-copy-and-link-dir
146 @anchor{htmlfontify-copy-and-link-dir}
150 (htmlfontify-copy-and-link-dir @var{srcdir} @var{dstdir} &optional @var{f-ext} @var{l-ext})
153 Trawl @var{srcdir} and write fontified-and-hyperlinked output in
154 @var{dstdir}. @var{f-ext} and @var{l-ext} specify values for
155 @ref{hfy-extn} and @ref{hfy-link-extn}.
157 You may also want to set @ref{hfy-page-header} and @ref{hfy-page-footer}.
159 @item htmlfontify-load-rgb-file
160 @findex htmlfontify-load-rgb-file
161 @anchor{htmlfontify-load-rgb-file}
165 (htmlfontify-load-rgb-file &optional @var{file})
168 Load an X11 style rgb.txt file (search @code{hfy-rgb-load-path} if
169 @var{file} is not specified).
171 Note that this is not necessary if all you want is the standard X11
172 (XFree86 4.1.0) color name -> rgb triplet mapping. Htmlfontify has
173 a copy built in, for use when it cannot contact an X server.
175 Loads the variable @code{hfy-rgb-txt-color-map}, which is used by
176 @ref{hfy-fallback-color-values}.
178 @item htmlfontify-unload-rgb-file
179 @findex htmlfontify-unload-rgb-file
180 @anchor{htmlfontify-unload-rgb-file}
184 (htmlfontify-unload-rgb-file)
187 Unload the currently loaded X11 style rgb.txt file (if any).
190 @node Non-interactive
191 @section Non-interactive
192 @cindex Noninteractive
193 @cindex functions (noninteractive)
195 In addition to the aforementioned interactive methods, Htmlfontify
196 provides the following non-interactive ones:
199 @comment AUTOGENERATED BLOCK
201 @item hfy-face-to-style
202 @findex hfy-face-to-style
203 @anchor{hfy-face-to-style}
207 (hfy-face-to-style @var{fn})
210 Take @var{fn}, a font or @code{defface} style font specification,
211 (as returned by @code{face-attr-construct} or @ref{hfy-face-attr-for-class})
212 and return a @ref{hfy-style-assoc}.
214 See also: @ref{hfy-face-to-style-i}, @ref{hfy-flatten-style}.
216 @item hfy-fallback-color-values
217 @findex hfy-fallback-color-values
218 @anchor{hfy-fallback-color-values}
222 (hfy-fallback-color-values @var{color-string})
225 Use a fallback method for obtaining the rgb values for a color.
226 If @ref{htmlfontify-load-rgb-file} has been called, it uses the
227 color map specified, otherwise it uses Htmlfontify's built in map.
229 @item hfy-combined-face-spec
230 @findex hfy-combined-face-spec
231 @anchor{hfy-combined-face-spec}
235 (hfy-combined-face-spec @var{face})
238 Return a @code{defface} style alist of possible specifications for
239 @var{face}, with any entries resulting from user customization
240 (@code{custom-set-faces}) taking precedence.
242 See also: @ref{hfy-default-face-def}
245 @findex hfy-word-regex
246 @anchor{hfy-word-regex}
250 (hfy-word-regex @var{string})
253 Return a regex that matches @var{string} as the first @code{match-string},
254 with non word characters on either side (vaguely emulating the perl @code{\b}
257 @item hfy-force-fontification
258 @findex hfy-force-fontification
259 @anchor{hfy-force-fontification}
263 (hfy-force-fontification)
266 Emacs's fontification is designed for interactive use. As such, it sometimes
267 does things like deferring fontification until a section of the buffer is
268 exposed and rendered, or until Emacs is idle for a while. Sometimes, in
269 non-interactive circumstances, or if it can't see X, it doesn't bother
270 with some of the harder stuff. While this is all great from the perspective
271 of a user waiting for Emacs to load a 20000 line file and colorize it,
272 it's a pain from the point of view from non-interactive code. This function
273 lies, cheats, steals and generally bullies Emacs into fontifying a buffer
274 from start to finish, with all the extra frills, whether it thinks it needs
275 to or not. Oh yes: it operates on the current buffer.
277 @item hfy-link-style-string
278 @findex hfy-link-style-string
279 @anchor{hfy-link-style-string}
283 (hfy-link-style-string @var{style-string})
286 Replace the end of a CSS style declaration @var{style-string} with the contents
287 of the variable @ref{hfy-src-doc-link-style}, removing text matching the
288 regex @ref{hfy-src-doc-link-unstyle} first, if necessary.
291 @item hfy-prepare-index-i
292 @findex hfy-prepare-index-i
293 @anchor{hfy-prepare-index-i}
297 (hfy-prepare-index-i @var{srcdir} @var{dstdir} @var{filename} &optional @var{stub} @var{map})
300 Prepare a tags index buffer for @var{srcdir}.
301 @ref{hfy-tags-cache} must already have an entry for @var{srcdir} for
302 this to work. @ref{hfy-page-header}, @ref{hfy-page-footer},
303 @ref{hfy-link-extn} and @ref{hfy-extn} all play a part here.
305 If @var{stub} is set, prepare an (appropriately named) index buffer
306 specifically for entries beginning with @var{stub}.
308 If @var{map} is set, use that instead of @ref{hfy-tags-cache}.
310 @item hfy-compile-stylesheet
311 @findex hfy-compile-stylesheet
312 @anchor{hfy-compile-stylesheet}
316 (hfy-compile-stylesheet)
319 Trawl the current buffer, construct and return a @ref{hfy-sheet-assoc}.
323 @anchor{hfy-css-name}
327 (hfy-css-name @var{fn})
330 Strip some of the boring bits from a font-name and return a CSS style
331 name. If @var{fn} is a @code{defface} attribute list, either construct
332 a name for it, store it in the cache, and return it, or just fetch it
333 from the cache if it's already there.
335 @item hfy-make-directory
336 @findex hfy-make-directory
337 @anchor{hfy-make-directory}
341 (hfy-make-directory @var{dir})
344 Approximate equivalent of @code{mkdir -p @var{dir}}.
352 (hfy-triplet @var{color})
355 Takes a color name (string) and return a CSS rgb(R, G, B) triplet string.
356 Uses the definition of ``white'' to map the numbers to the 0-255 range, so
357 if you've redefined white, (especially if you've redefined it to have
358 a triplet member lower than that of the color you are processing,
359 strange things may happen).
361 @item hfy-default-footer
362 @findex hfy-default-footer
363 @anchor{hfy-default-footer}
367 (hfy-default-footer @var{file})
370 Default value for @ref{hfy-page-footer}
373 @findex hfy-list-files
374 @anchor{hfy-list-files}
378 (hfy-list-files @var{directory})
381 Return a list of files under @var{directory}.
382 Strips any leading @samp{./} from each filename.
385 @findex hfy-color-vals
386 @anchor{hfy-color-vals}
390 (hfy-color-vals @var{color})
393 Where @var{color} is a color name or #XXXXXX style triplet, return a list of
394 3 (16 bit) rgb values for said color. If a window system is unavailable,
395 calls @ref{hfy-fallback-color-values}.
398 @findex hfy-href-stub
399 @anchor{hfy-href-stub}
403 (hfy-href-stub @var{this-file} @var{def-files} @var{tag})
406 Return an href stub for a tag href: if @var{def-files} (list of files
407 containing definitions for the tag in question) contains only one entry,
408 the href should link straight to that file. Otherwise, the link should
409 be to the index file.
411 We are not yet concerned with the file extensions/tag line number and
414 If @ref{hfy-split-index} is set, and the href will be to an index file
415 rather than a source file, append a @samp{.X} to @ref{hfy-index-file}, where
416 @samp{X} is the uppercased first character of @var{tag}.
418 See also: @ref{hfy-relstub}, @ref{hfy-index-file}.
420 @item hfy-line-number
421 @findex hfy-line-number
422 @anchor{hfy-line-number}
429 Returns the line number of the point in the current buffer.
431 @item hfy-merge-adjacent-spans
432 @findex hfy-merge-adjacent-spans
433 @anchor{hfy-merge-adjacent-spans}
437 (hfy-merge-adjacent-spans @var{face-map})
440 Where @var{face-map} is a @ref{hfy-facemap-assoc} for the current buffer,
441 this function merges adjacent style blocks which are of the same value
442 and are separated by nothing more interesting than whitespace.
444 @code{<span class="foo">narf</span> <span class="foo">brain</span>}
446 (as interpreted from @var{face-map}) would become:
448 @code{<span class="foo">narf brain</span>}
450 Returns a modified copy of @var{face-map} (also a @ref{hfy-facemap-assoc}).
452 @item hfy-mark-tag-names
453 @findex hfy-mark-tag-names
454 @anchor{hfy-mark-tag-names}
458 (hfy-mark-tag-names @var{srcdir} @var{file})
461 Mark tags in @var{file} (lookup @var{srcdir} in @ref{hfy-tags-cache}) with the
462 @code{hfy-anchor} property, with a value of @samp{tag.line-number}.
470 (hfy-weight @var{weight})
473 Derive a font-weight CSS specifier from an Emacs weight specification symbol.
481 (hfy-size @var{height})
484 Derive a CSS font-size specifier from an Emacs font @code{:height} attribute.
485 Does not cope with the case where height is a function to be applied to
486 the height of the underlying font.
488 @item hfy-default-header
489 @findex hfy-default-header
490 @anchor{hfy-default-header}
494 (hfy-default-header @var{file} @var{style})
497 Default value for @ref{hfy-page-header}
505 (hfy-family @var{family})
508 Derives a CSS font-family specifier from an Emacs @code{:family} attribute.
510 @item hfy-mark-tag-hrefs
511 @findex hfy-mark-tag-hrefs
512 @anchor{hfy-mark-tag-hrefs}
516 (hfy-mark-tag-hrefs @var{srcdir} @var{file})
519 Mark href start points with the @code{hfy-link} property (value: href string).
521 Mark href end points with the @code{hfy-endl} property (value @code{t}).
523 Avoid overlapping links, and mark links in descending length of
524 tag name in order to prevent subtags from usurping supertags;
525 e.g., ``term'' for ``terminal'').
536 Derive CSS border-* attributes from the Emacs @code{:box} attribute.
538 @item hfy-box-to-style
539 @findex hfy-box-to-style
540 @anchor{hfy-box-to-style}
544 (hfy-box-to-style @var{spec})
547 Convert a complex @code{:box} Emacs font attribute set to a list of
548 CSS border-* attributes. Don't call this directly---it is called by
549 @ref{hfy-box} when necessary.
551 @item hfy-html-enkludge-buffer
552 @findex hfy-html-enkludge-buffer
553 @anchor{hfy-html-enkludge-buffer}
557 (hfy-html-enkludge-buffer)
560 Mark dangerous @samp{["<>]} characters with the @code{hfy-quoteme} property.
562 See also @ref{hfy-html-dekludge-buffer}.
573 Generate and return an Htmlfontify html output buffer for the current
574 buffer. May trample an existing buffer.
576 @item hfy-fontified-p
577 @findex hfy-fontified-p
578 @anchor{hfy-fontified-p}
585 @code{font-lock} doesn't like to say a buffer's been fontified when in
586 batch mode, but we want to know if we should fontify or raw copy, so in
587 batch mode we check for non-default face properties. Otherwise we test
588 @code{font-lock-mode} and @code{font-lock-fontified} for truth.
596 (hfy-lookup @var{face} @var{style})
599 Where @var{style} is a @ref{hfy-sheet-assoc} and @var{face} is an Emacs face,
600 return the relevant @var{css} style name.
602 @item hfy-fontify-buffer
603 @findex hfy-fontify-buffer
604 @anchor{hfy-fontify-buffer}
608 (hfy-fontify-buffer &optional @var{srcdir} @var{file})
611 Implement the guts of @ref{htmlfontify-buffer}.
619 (hfy-color @var{color})
622 Convert an Emacs :foreground property to a CSS color property.
624 @item hfy-flatten-style
625 @findex hfy-flatten-style
626 @anchor{hfy-flatten-style}
630 (hfy-flatten-style @var{style})
633 Take @var{style} (see @ref{hfy-face-to-style-i}, @ref{hfy-face-to-style})
634 and merge any multiple attributes appropriately. Currently only font-size is
635 merged down to a single occurrence---others may need special handling, but I
636 haven't encountered them yet. Returns a @ref{hfy-style-assoc}.
638 @item hfy-size-to-int
639 @findex hfy-size-to-int
640 @anchor{hfy-size-to-int}
644 (hfy-size-to-int @var{spec})
647 Convert @var{spec}, a CSS font-size specifier, back to an Emacs
648 @code{:height} attribute value. Used while merging multiple font-size
651 @item hfy-sprintf-stylesheet
652 @findex hfy-sprintf-stylesheet
653 @anchor{hfy-sprintf-stylesheet}
657 (hfy-sprintf-stylesheet @var{css} @var{file})
660 Generates a header, via @ref{hfy-page-header}, for @var{file}, containing the
661 stylesheet derived from @var{css}, which is a @ref{hfy-sheet-assoc}. Returns a
662 string containing the same.
670 (hfy-relstub @var{file} &optional @var{start})
673 Return a @samp{../} stub of the appropriate length for the current source
674 tree depth (as determined from @var{file}). @c iyswim.
676 @item hfy-compile-face-map
677 @findex hfy-compile-face-map
678 @anchor{hfy-compile-face-map}
682 (hfy-compile-face-map)
685 Compile and return a @ref{hfy-facemap-assoc} for the current buffer.
687 @item hfy-prepare-index
688 @findex hfy-prepare-index
689 @anchor{hfy-prepare-index}
693 (hfy-prepare-index @var{srcdir} @var{dstdir})
696 Return as list of index buffer(s), as determined by @ref{hfy-split-index}.
697 Uses @ref{hfy-prepare-index-i} to do this.
699 @item hfy-prepare-tag-map
700 @findex hfy-prepare-tag-map
701 @anchor{hfy-prepare-tag-map}
705 (hfy-prepare-tag-map @var{srcdir} @var{dstdir})
708 Prepare the counterpart(s) to the index buffer(s)---a list of buffers with
709 the same structure, but listing (and linking to) instances of tags (as
710 opposed to their definitions).
712 See also: @ref{hfy-prepare-index}, @ref{hfy-split-index}
714 @item hfy-subtract-maps
715 @findex hfy-subtract-maps
716 @anchor{hfy-subtract-maps}
720 (hfy-subtract-maps @var{srcdir})
723 Internal function---strips definitions of tags from the instance map.
724 See: @ref{hfy-tags-cache} and @ref{hfy-tags-rmap}
726 @item hfy-face-to-style-i
727 @findex hfy-face-to-style-i
728 @anchor{hfy-face-to-style-i}
732 (hfy-face-to-style-i @var{fn})
735 The guts of @ref{hfy-face-to-style}. @var{fn} should be a @code{defface}
736 font specification, as returned by @code{face-attr-construct} or
737 @ref{hfy-face-attr-for-class}. Note that this function does not get
738 font-sizes right if they are based on inherited modifiers (via the
739 :inherit) attribute, and any other modifiers that are cumulative if they
740 appear multiple times need to be merged by the user---@ref{hfy-flatten-style}
743 @item hfy-face-to-css
744 @findex hfy-face-to-css
745 @anchor{hfy-face-to-css}
749 (hfy-face-to-css @var{fn})
752 Take @var{fn}, a font or @code{defface} specification (c.f.
753 @code{face-attr-construct}) and return a CSS style specification.
755 See also: @ref{hfy-face-to-style}
758 @findex hfy-html-quote
759 @anchor{hfy-html-quote}
763 (hfy-html-quote @var{char-string})
766 Map a string (usually 1 character long) to an html safe string
770 @findex hfy-link-style
771 @anchor{hfy-link-style}
775 (hfy-link-style @var{style-string})
778 Convert the CSS style spec @var{style-string} to its equivalent
781 See: @ref{hfy-link-style-fun}.
784 @findex hfy-p-to-face
785 @anchor{hfy-p-to-face}
789 (hfy-p-to-face @var{props})
792 Given @var{props}, a list of text-properties, return the value of the
793 face property, or nil.
795 @item hfy-box-to-border-assoc
796 @findex hfy-box-to-border-assoc
797 @anchor{hfy-box-to-border-assoc}
801 (hfy-box-to-border-assoc @var{spec})
804 Helper function for @ref{hfy-box-to-style}.
806 @item hfy-face-attr-for-class
807 @findex hfy-face-attr-for-class
808 @anchor{hfy-face-attr-for-class}
812 (hfy-face-attr-for-class @var{face} &optional @var{class})
815 Return the face attributes for @var{face}. If @var{class} is set, it
816 must be a @code{defface} alist key [see below]. Prior to version 0.18,
817 the first face specification returned by @ref{hfy-combined-face-spec}
818 which @emph{didn't} clash with @var{class} was returned. In versions
819 from 0.18 onwards, each font attribute list is scored, and the
820 non-conflicting list with the highest score is returned. (A specification
821 with a class of @code{t} is considered to match any class you specify.
822 This matches Emacs's behaviour when deciding on which face attributes to
823 use, to the best of my understanding ).
825 If @var{class} is nil, then you just get get whatever
826 @code{face-attr-construct} returns; i.e., the current specification in
827 effect for @var{face}.
829 See @ref{hfy-display-class} for details of valid values for @var{class}.
840 Find face in effect at point P. If overlays are to be considered
841 (see @ref{hfy-optimisations}) then this may return a @code{defface} style
842 list of face properties instead of a face symbol.
850 (hfy-bgcol @var{color})
853 As per @ref{hfy-color} but for background colors.
855 @item hfy-kludge-cperl-mode
856 @findex hfy-kludge-cperl-mode
857 @anchor{hfy-kludge-cperl-mode}
861 (hfy-kludge-cperl-mode)
864 cperl mode does its best to not do some of its fontification when not
865 in a windowing system---we try to trick it@dots{}
873 (hfy-href @var{this-file} @var{def-files} @var{tag} @var{tag-map})
876 Return a relative href to the tag in question, based on
878 @var{this-file} @ref{hfy-link-extn} @ref{hfy-extn} @var{def-files} @var{tag} and @var{tag-map}
880 @var{this-file} is the current source file
881 @var{def-files} is a list of file containing possible link endpoints for @var{tag}
882 @var{tag} is the @var{tag} in question
883 @var{tag-map} is the entry in @ref{hfy-tags-cache}.
894 Returns a best guess at a Bourne compatible shell to use: If the current
895 shell doesn't look promising, fall back to @ref{hfy-shell-file-name}.
897 @item hfy-load-tags-cache
898 @findex hfy-load-tags-cache
899 @anchor{hfy-load-tags-cache}
903 (hfy-load-tags-cache @var{srcdir})
906 Run @ref{hfy-etags-cmd} on @var{srcdir}: load @ref{hfy-tags-cache} and @ref{hfy-tags-sortl}.
908 @item hfy-parse-tags-buffer
909 @findex hfy-parse-tags-buffer
910 @anchor{hfy-parse-tags-buffer}
914 (hfy-parse-tags-buffer @var{srcdir} @var{buffer})
917 Parse a @var{buffer} containing etags formatted output, loading the
918 @ref{hfy-tags-cache} and @ref{hfy-tags-sortl} entries for @var{srcdir}.
926 (hfy-interq @var{set-a} @var{set-b})
929 Return the intersection (using @code{eq}) of 2 lists.
937 (hfy-text-p @var{srcdir} @var{file})
940 Is @var{srcdir}/@var{file} text? Uses @ref{hfy-istext-command} to determine this.
948 (hfy-opt @var{symbol})
951 Is @ref{hfy-optimisations} member @var{symbol} set or not?
959 (hfy-dirname @var{file})
962 Return everything preceding the last @samp{/} from a relative filename,
963 on the assumption that this will produce a relative directory name. Hardly
964 bombproof, but good enough in the context in which it is being used.
966 @item hfy-html-dekludge-buffer
967 @findex hfy-html-dekludge-buffer
968 @anchor{hfy-html-dekludge-buffer}
972 (hfy-html-dekludge-buffer)
975 Transform all dangerous characters marked with the @code{hfy-quoteme} property
976 using @ref{hfy-html-quote}
978 See also @ref{hfy-html-enkludge-buffer}.
980 @item hfy-copy-and-fontify-file
981 @findex hfy-copy-and-fontify-file
982 @anchor{hfy-copy-and-fontify-file}
986 (hfy-copy-and-fontify-file @var{srcdir} @var{dstdir} @var{file})
989 Open @var{file} in @var{srcdir}---if fontified, write a fontified copy to @var{dstdir}
990 adding an extension of @ref{hfy-extn}. Fontification is actually done by
991 @ref{htmlfontify-buffer}. If the buffer is not fontified, just copy it.
999 (hfy-decor @var{tag} @var{val})
1002 Derive CSS text-decoration specifiers from various Emacs font attributes.
1010 (hfy-slant @var{slant})
1013 Derive a font-style CSS specifier from the Emacs :slant
1014 attribute---CSS does not define the reverse-* styles, so just maps
1015 those to the regular specifiers.
1017 @item hfy-tags-for-file
1018 @findex hfy-tags-for-file
1019 @anchor{hfy-tags-for-file}
1023 (hfy-tags-for-file @var{srcdir} @var{file})
1026 List of etags tags that have definitions in this @var{file}. Looks up
1027 the tags cache in @ref{hfy-tags-cache} using @var{srcdir} as the key.
1035 (hfy-width @var{width})
1038 Convert an Emacs @code{:width} attribute to a CSS font-stretch attribute.
1040 @comment /AUTOGENERATED BLOCK
1047 Important variables that are not customization items:
1051 @item hfy-tags-cache
1052 @vindex hfy-tags-cache
1053 @anchor{hfy-tags-cache}
1055 This is an alist of the form:
1058 (("/src/dir/0" . tag-hash0) ("/src/dir/1" tag-hash1) @dots{} )
1061 Each tag hash entry then contains entries of the form:
1064 "tag_string" => (("file/name.ext" line char) @dots{} )
1067 i.e., an alist mapping (relative) file paths to line and character offsets.
1069 See @ref{hfy-load-tags-cache}.
1072 @vindex hfy-tags-rmap
1073 @anchor{hfy-tags-rmap}
1075 @code{hfy-tags-rmap} is an alist of the form:
1078 (("/src/dir" . tag-rmap-hash))
1081 Where tag-rmap-hash has entries of the form:
1084 "tag_string" => ( "file/name.ext" line char )
1087 Unlike @ref{hfy-tags-cache} these are the locations of occurrences of
1088 tagged items, not the locations of their definitions.
1090 @item hfy-tags-sortl
1091 @vindex hfy-tags-sortl
1092 @anchor{hfy-tags-sortl}
1094 @code{hfy-tags-sortl} is an alist of the form:
1097 (("/src/dir" . (tag0 tag1 tag2)) @dots{} )
1100 Where the tags are stored in descending order of length.
1102 See: @ref{hfy-load-tags-cache}.
1106 @node Data Structures
1107 @section Data Structures
1108 @cindex Data Structures
1110 Some of the (informal) data structures used in Htmlfontify are detailed here:
1114 @item hfy-style-assoc
1115 @cindex hfy-style-assoc
1116 @anchor{hfy-style-assoc}
1118 An assoc representing/describing an Emacs face. Properties may be repeated,
1119 in which case later properties should be treated as if they were inherited
1120 from a ``parent'' font. (For some properties, only the first encountered value
1121 is of any importance, for others the values might be cumulative, and for
1122 others they might be cumulative in a complex way.)
1127 (hfy-face-to-style 'default) =>
1129 (("background" . "rgb(0, 0, 0)" )
1130 ("color" . "rgb(255, 255, 255)")
1131 ("font-style" . "normal" )
1132 ("font-weight" . "500" )
1133 ("font-stretch" . "normal" )
1134 ("font-family" . "misc-fixed" )
1135 ("font-size" . "13pt" )
1136 ("text-decoration" . "none" ))
1138 (hfy-face-to-style 'Info-title-3-face) =>
1140 (("font-weight" . "700" )
1141 ("font-family" . "helv" )
1142 ("font-size" . "120%" )
1143 ("text-decoration" . "none") )
1146 @item hfy-sheet-assoc
1147 @cindex hfy-sheet-assoc
1148 @anchor{hfy-sheet-assoc}
1150 An assoc with elements of the form @samp{(face-name style-name . style-string)}.
1151 The actual stylesheet for each page is derived from one of these.
1154 '((default "default" . "@{ background: black; color: white@}")
1155 (font-lock-string-face "string" . "@{ color: rgb(64,224,208) @}"))
1158 @item hfy-facemap-assoc
1159 @cindex hfy-facemap-assoc
1160 @anchor{hfy-facemap-assoc}
1162 An assoc of @code{(point . @var{face-symbol})} or
1163 @code{(point . @code{defface} attribute list)} and @code{(point
1164 . end)} elements, in descending order of point value (i.e., from the
1165 file's end to its beginning). The map is in reverse order because
1166 inserting a @samp{<style>} tag (or any other string) at @var{point}
1167 invalidates the map for all entries with a greater value of point. By
1168 traversing the map from greatest to least @var{point}, we still
1169 invalidate the map as we go, but only those points we have already
1170 dealt with (and therefore no longer care about) will be invalid at any
1175 (64744 . font-lock-comment-face)
1177 (64722 . font-lock-string-face)
1179 (64623 . font-lock-string-face)
1181 ;; Big similar section elided. You get the idea.
1183 (5431 . (:inherit font-lock-keyword-face :background "7e7e7e"))
1185 (4285 . font-lock-constant-face)
1187 (4221 . font-lock-comment-face)
1189 (4197 . font-lock-constant-face)
1191 (1 . font-lock-comment-face))
1200 The following is a lump of code I use to fontify source code on my
1201 site, @url{http://rtfm.etla.org/} (which was the reason, incidentally,
1202 that Htmlfontify was written in the first place).
1205 (defvar rtfm-section nil)
1207 ;; Constructs an appropriate header string to fit in with rtfm's
1208 ;; templating system, based on the file and the stylesheet string
1209 (defun rtfm-build-page-header (file style)
1210 (format "#define TEMPLATE red+black.html
1212 #include <build/menu-dirlist|>\n
1213 html-css-url := /css/red+black.css
1214 title := rtfm.etla.org ( %s / src/%s )
1216 head <=STYLESHEET;\n
1219 main-title := rtfm / %s / src/%s\n
1220 main-content <=MAIN_CONTENT;\n" rtfm-section file style rtfm-section file))
1223 (defun rtfm-build-page-footer (file) "\nMAIN_CONTENT\n")
1225 (defun rtfm-fontify-buffer (section)
1226 (interactive "s section[eg- emacs / p4-blame]: ")
1227 (require 'htmlfontify)
1228 (let ((hfy-page-header 'rtfm-build-page-header)
1229 (hfy-page-footer 'rtfm-build-page-footer)
1230 (rtfm-section section))
1231 (htmlfontify-buffer)
1235 ;; Here's the function I actually call---it asks me for a section label,
1236 ;; and source and destination directories, and then binds a couple of
1237 ;; customization variable in a let before calling htmlfontify:
1238 (defun rtfm-build-source-docs (section srcdir destdir)
1240 "s section[eg- emacs / p4-blame]:\nD source-dir: \nD output-dir: ")
1241 (require 'htmlfontify)
1242 (hfy-load-tags-cache srcdir)
1243 (let ((hfy-page-header 'rtfm-build-page-header)
1244 (hfy-page-footer 'rtfm-build-page-footer)
1245 (rtfm-section section)
1246 (hfy-index-file "index")
1247 (auto-mode-alist (append auto-mode-alist
1248 '(("dbi\\(shell\\|gtk\\)$" . cperl-mode)
1249 ("\\.xpm$" . c-mode ))))
1251 (htmlfontify-run-etags srcdir)
1252 (htmlfontify-copy-and-link-dir srcdir destdir ".src" ".html")))
1256 @chapter Customization
1257 @cindex variables (customization)
1259 Htmlfontify provides the following variable and customization entries:
1262 @comment AUTOGENERATED BLOCK
1264 @item hfy-link-style-fun
1265 @vindex hfy-link-style-fun
1266 @anchor{hfy-link-style-fun}
1268 Set this to a function, which will be called with one argument
1269 (a @samp{@{ foo: bar; @dots{}@}} CSS style-string)---it should return a copy of
1270 its argument, altered so as to make any changes you want made for text which
1271 is a hyperlink, in addition to being in the class to which that style would
1272 normally be applied.
1274 @item hfy-html-quote-regex
1275 @vindex hfy-html-quote-regex
1276 @anchor{hfy-html-quote-regex}
1278 Regex to match (with a single back-reference per match) strings in HTML
1279 which should be quoted with @ref{hfy-html-quote}
1280 (and @pxref{hfy-html-quote-map}) to make them safe.
1282 @item hfy-page-footer
1283 @vindex hfy-page-footer
1284 @anchor{hfy-page-footer}
1286 As @ref{hfy-page-header}, but generates the output footer
1287 (and takes only 1 argument, the filename).
1289 @item hfy-display-class
1290 @vindex hfy-display-class
1291 @anchor{hfy-display-class}
1293 Display class to use to determine which display class to use when
1294 calculating a face's attributes. This is useful when, for example, you
1295 are running Emacs on a tty or in batch mode, and want Htmlfontify to have
1296 access to the face spec you would use if you were connected to an X display.
1298 Some valid class specification elements are:
1311 Multiple values for a tag may be combined, to indicate that any one or more
1312 of these values in the specification key constitutes a match, eg:
1314 '((class color grayscale) (type tty)) would match any of:
1317 '((class grayscale))
1318 '((class color grayscale)))
1319 '((class color foo))
1321 '((type tty) (class color))
1325 @item hfy-page-header
1326 @vindex hfy-page-header
1327 @anchor{hfy-page-header}
1329 Function called with two arguments (the filename relative to the top
1330 level source directory being etag'd and fontified), and a string containing
1331 the @samp{<style>@dots{}</style>} text to embed in the document---the string
1332 returned will be used as the header for the htmlfontified version of
1335 See also: @ref{hfy-page-footer}
1337 @item hfy-src-doc-link-style
1338 @vindex hfy-src-doc-link-style
1339 @anchor{hfy-src-doc-link-style}
1341 String to add to the @samp{<style> a} variant of an Htmlfontify CSS class.
1343 @item hfy-fast-lock-save
1344 @vindex hfy-fast-lock-save
1345 @anchor{hfy-fast-lock-save}
1347 Minimum size of a buffer for cached fontification.
1348 This value is temporarily assigned to @code{fast-lock-minimum-size} during
1351 Only buffers more than this can have associated Font Lock cache files saved.
1353 If nil, means cache files are never created.
1355 If a list, each element should be a cons pair of the form
1356 @code{(@var{major-mode} . @var{size})}, where @var{major-mode}
1357 is a symbol or t (meaning the default). For example:
1362 (rmail-mode . 1048576))
1365 means that the minimum size is 25K for buffers in C or C++ modes, one megabyte
1366 for buffers in Rmail mode, and size is irrelevant (i.e., no saves) otherwise.
1368 @item hfy-split-index
1369 @vindex hfy-split-index
1370 @anchor{hfy-split-index}
1372 Whether or not to split the index @ref{hfy-index-file} alphabetically
1373 on the first letter of each tag. Useful when the index would otherwise
1374 be large and take a long time to render or be difficult to navigate.
1377 @vindex hfy-find-cmd
1378 @anchor{hfy-find-cmd}
1380 ``find'' command used to harvest a list of files to attempt to fontify.
1386 File extension used for output files
1388 @item hfy-default-face-def
1389 @vindex hfy-default-face-def
1390 @anchor{hfy-default-face-def}
1392 Fallback @code{defface} specification for the face @code{default}, used
1393 when @ref{hfy-display-class} has been set (the normal Htmlfontify way of
1394 extracting potentially non-current face information doesn't necessarily
1395 work for @code{default}).
1397 For example, I customize this to:
1400 ((t :background "black" :foreground "white" :family "misc-fixed"))
1403 @item hfy-init-kludge-hooks
1404 @vindex hfy-init-kludge-hooks
1405 @anchor{hfy-init-kludge-hooks}
1407 List of functions to call when starting htmlfontify-buffer to do any
1408 kludging necessary to get highlighting modes to behave as you want, even
1409 when not running under a window system.
1411 @item hfy-shell-file-name
1412 @vindex hfy-shell-file-name
1413 @anchor{hfy-shell-file-name}
1415 Should be set to a Bourne compatible shell, which will be invoked
1416 for the more complex shell interactions needed by Htmlfontify.
1417 Currently this is only required/used when using GNU etags, see
1418 @ref{hfy-etags-cmd-alist} for details.
1420 @item hfy-optimisations
1421 @vindex hfy-optimisations
1422 @anchor{hfy-optimisations}
1424 Optimizations to turn on. So far, the following have been implemented:
1427 @item merge-adjacent-tags
1428 If two (or more) span tags are adjacent, identical and separated by nothing
1429 more than whitespace, they will be merged into one span.
1431 @item zap-comment-links
1432 Suppress hyperlinking of tags found in comments.
1434 @item zap-string-links
1435 Suppress hyperlinking of tags found in strings.
1438 Add @samp{<div class="default"> </div>} tags around the fontified body.
1439 (Some people like this because they cut and paste the html into
1440 a page with different colors than the fontified code.)
1443 Preserve overlay highlighting (c.f. @code{ediff} or @code{goo-font-lock})
1444 as well as basic faces. Can result in extremely verbose highlighting
1445 if there are many overlays (as is the case with @code{goo-font-lock}).
1449 And the following are planned but not yet available:
1452 @item kill-context-leak
1453 Suppress hyperlinking between files highlighted by different modes.
1457 Note: like compiler optimizations, these optimize the @emph{output} of
1459 not the processing of the source itself, and are therefore likely to slow
1460 Htmlfontify down, at least a little. Except for skip-refontification,
1461 which can never slow you down, but may result in incomplete fontification.
1463 @item hfy-src-doc-link-unstyle
1464 @vindex hfy-src-doc-link-unstyle
1465 @anchor{hfy-src-doc-link-unstyle}
1467 Regex to remove from the <style> a variant of an Htmlfontify CSS class.
1470 @vindex hfy-link-extn
1471 @anchor{hfy-link-extn}
1473 File extension used for href links---useful where the Htmlfontify
1474 output files are going to be processed again, with a resulting change
1475 in file extension. If @code{nil}, then any code using this should fall back
1478 @item hfy-istext-command
1479 @vindex hfy-istext-command
1480 @anchor{hfy-istext-command}
1482 Command to run with the name of a file, to see whether it is a text file
1483 or not. The command should emit a string containing the word @samp{text} if
1484 the file is a text file, and a string not containing @samp{text} otherwise.
1486 @item hfy-etags-cmd-alist
1487 @vindex hfy-etags-cmd-alist
1488 @anchor{hfy-etags-cmd-alist}
1490 An alist of possible shell commands that will generate etags output that
1491 Htmlfontify can use. @samp{%s} will be replaced by @ref{hfy-etags-bin}.
1494 @vindex hfy-etags-bin
1495 @anchor{hfy-etags-bin}
1497 The location of the etags binary (we begin by assuming it's in your path).
1499 Note that if etags is not in your path, you will need to alter the shell
1500 commands in @ref{hfy-etags-cmd-alist}.
1502 [As of version 0.17, this requirement has been removed: it should
1506 @vindex hfy-etags-cmd
1507 @anchor{hfy-etags-cmd}
1509 An etags shell command to run in the source directory to generate a tags
1510 file for the whole source tree from there on down. The command should emit
1511 the etags output on standard output.
1513 Two canned commands are provided---they drive Emacs's etags and
1514 exuberant-ctags's etags respectively.
1516 @item hfy-etag-regex
1517 @vindex hfy-etag-regex
1518 @anchor{hfy-etag-regex}
1520 Regex used to parse an etags entry: must have 3 subexps, corresponding,
1529 The character (point) at which the tag occurs
1532 @item hfy-index-file
1533 @vindex hfy-index-file
1534 @anchor{hfy-index-file}
1536 Name (sans extension) of the index file produced during
1537 fontification-and-hyperlinking.
1539 @item hfy-instance-file
1540 @vindex hfy-instance-file
1541 @anchor{hfy-instance-file}
1543 Name (sans extension) of the tag usage index file produced during
1544 fontification-and-hyperlinking.
1546 @item hfy-html-quote-map
1547 @vindex hfy-html-quote-map
1548 @anchor{hfy-html-quote-map}
1550 An alist of character -> entity mappings used to make the text html-safe.
1552 @comment /AUTOGENERATED BLOCK
1556 @chapter Requirements
1557 @cindex Requirements, Prerequisites
1559 Htmlfontify has a couple of external requirements:
1564 GNU Emacs 20.7+ or 21.1+
1566 Other versions may work---these have been used successfully by the
1567 author. If you intend to use Htmlfontify in batch mode, 21.1+ is
1568 pretty much required. The author does not know if XEmacs, NTemacs,
1569 or J.Random Emacs will run Htmlfontify, but reports/patches/bags of
1570 money are always welcome.
1573 A copy of etags (exuberant-ctags or GNU etags). Htmlfontify attempts
1574 to autodetect the version you have and customize itself accordingly,
1575 but you should be able to override this.
1577 See: @ref{Customization}
1580 A copy of find (e.g., GNU find) that provides the @code{-path} predicate.
1582 You may be able to work around this with a suitable clever shell
1583 command and the customization entry: @ref{hfy-find-cmd}
1586 A copy of sed (e.g., GNU sed).
1589 A copy of the @code{file} command.
1593 @node GNU Free Documentation License
1594 @appendix GNU Free Documentation License
1595 @include doclicense.texi
1607 @item Variables & Customization
1612 @setchapternewpage odd