xref: /vim-8.2.3635/runtime/plugin/tohtml.vim (revision 60cce2fb)
1071d4279SBram Moolenaar" Vim plugin for converting a syntax highlighted file to HTML.
2349b2fb0SBram Moolenaar" Maintainer: Ben Fritz <[email protected]>
3*60cce2fbSBram Moolenaar" Last Change: 2015 Sep 08
4b02cbe34SBram Moolenaar"
5349b2fb0SBram Moolenaar" The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and
6349b2fb0SBram Moolenaar" $VIMRUNTIME/syntax/2html.vim
78ada2ccaSBram Moolenaar"
86c35beaaSBram Moolenaar" TODO: {{{
9543b7ef7SBram Moolenaar"   * Options for generating the CSS in external style sheets. New :TOcss
10543b7ef7SBram Moolenaar"     command to convert the current color scheme into a (mostly) generic CSS
11543b7ef7SBram Moolenaar"     stylesheet which can be re-used. Alternate stylesheet support? Good start
12543b7ef7SBram Moolenaar"     by Erik Falor
13543b7ef7SBram Moolenaar"     ( https://groups.google.com/d/topic/vim_use/7XTmC4D22dU/discussion ).
14543b7ef7SBram Moolenaar"   * Add optional argument to :TOhtml command to specify mode (gui, cterm,
15543b7ef7SBram Moolenaar"     term) to use for the styling. Suggestion by "nacitar".
16543b7ef7SBram Moolenaar"   * Add way to override or specify which RGB colors map to the color numbers
17543b7ef7SBram Moolenaar"     in cterm. Get better defaults than just guessing? Suggestion by "nacitar".
18543b7ef7SBram Moolenaar"   * Disable filetype detection until after all processing is done.
19543b7ef7SBram Moolenaar"   * Add option for not generating the hyperlink on stuff that looks like a
20543b7ef7SBram Moolenaar"     URL? Or just color the link to fit with the colorscheme (and only special
21543b7ef7SBram Moolenaar"     when hovering)?
22543b7ef7SBram Moolenaar"   * Bug: Opera does not allow printing more than one page if uncopyable
23543b7ef7SBram Moolenaar"     regions is turned on. Possible solution: Add normal text line numbers with
24543b7ef7SBram Moolenaar"     display:none, set to display:inline for print style sheets, and hide
25543b7ef7SBram Moolenaar"     <input> elements for print, to allow Opera printing multiple pages (and
26543b7ef7SBram Moolenaar"     other uncopyable areas?). May need to make the new text invisible to IE
27543b7ef7SBram Moolenaar"     with conditional comments to prevent copying it, IE for some reason likes
28543b7ef7SBram Moolenaar"     to copy hidden text. Other browsers too?
296c35beaaSBram Moolenaar"   * Bug: still a 1px gap throughout the fold column when html_prevent_copy is
306c35beaaSBram Moolenaar"     "fn" in some browsers. Specifically, in Chromium on Ubuntu (but not Chrome
316c35beaaSBram Moolenaar"     on Windows). Perhaps it is font related?
326c35beaaSBram Moolenaar"   * Bug: still some gaps in the fold column when html_prevent_copy contains
336c35beaaSBram Moolenaar"     'd' and showing the whole diff (observed in multiple browsers). Only gaps
346c35beaaSBram Moolenaar"     on diff lines though.
356c35beaaSBram Moolenaar"   * Undercurl support via CSS3, with fallback to dotted or something:
366c35beaaSBram Moolenaar"	https://groups.google.com/d/topic/vim_use/BzXA6He1pHg/discussion
376c35beaaSBram Moolenaar"   * Redo updates for modified default foldtext (v11) when/if the patch is
386c35beaaSBram Moolenaar"     accepted to modify it.
396c35beaaSBram Moolenaar"   * Test case +diff_one_file-dynamic_folds+expand_tabs-hover_unfold
406c35beaaSBram Moolenaar"		+ignore_conceal-ignore_folding+no_foldcolumn+no_pre+no_progress
416c35beaaSBram Moolenaar"		+number_lines-pre_wrap-use_css+use_xhtml+whole_filler.xhtml
42543b7ef7SBram Moolenaar"     does not show the whole diff filler as it is supposed to?
436c35beaaSBram Moolenaar"   * Bug: when 'isprint' is wrong for the current encoding, will generate
446c35beaaSBram Moolenaar"     invalid content. Can/should anything be done about this? Maybe a separate
456c35beaaSBram Moolenaar"     plugin to correct 'isprint' based on encoding?
466c35beaaSBram Moolenaar"   * Check to see if the windows-125\d encodings actually work in Unix without
476c35beaaSBram Moolenaar"     the 8bit- prefix. Add prefix to autoload dictionaries for Unix if not.
486c35beaaSBram Moolenaar"   * Font auto-detection similar to
496c35beaaSBram Moolenaar"     http://www.vim.org/scripts/script.php?script_id=2384 but for a variety of
506c35beaaSBram Moolenaar"     platforms.
516c35beaaSBram Moolenaar"   * Error thrown when sourcing 2html.vim directly when plugins are not loaded.
528e5af3e5SBram Moolenaar"   * Pull in code from http://www.vim.org/scripts/script.php?script_id=3113 :
538e5af3e5SBram Moolenaar"	- listchars support
548e5af3e5SBram Moolenaar"	- full-line background highlight
558e5af3e5SBram Moolenaar"	- other?
566c35beaaSBram Moolenaar"   * Make it so deleted lines in a diff don't create side-scrolling (get it
576c35beaaSBram Moolenaar"     free with full-line background highlight above).
588df7f888SBram Moolenaar"   * Restore open/closed folds and cursor position after processing each file
596c35beaaSBram Moolenaar"     with option not to restore for speed increase.
602a8a3ecbSBram Moolenaar"   * Add extra meta info (generation time, etc.)?
612a8a3ecbSBram Moolenaar"   * Tidy up so we can use strict doctype in even more situations
628df7f888SBram Moolenaar"   * Implementation detail: add threshold for writing the lines to the html
638df7f888SBram Moolenaar"     buffer before we're done (5000 or so lines should do it)
648ada2ccaSBram Moolenaar"   * TODO comments for code cleanup scattered throughout
656c35beaaSBram Moolenaar"}}}
66251e1912SBram Moolenaar
67251e1912SBram Moolenaarif exists('g:loaded_2html_plugin')
68251e1912SBram Moolenaar  finish
69251e1912SBram Moolenaarendif
70*60cce2fbSBram Moolenaarlet g:loaded_2html_plugin = 'vim7.4_v2'
71251e1912SBram Moolenaar
72166af9bbSBram Moolenaar"
736c35beaaSBram Moolenaar" Changelog: {{{
74*60cce2fbSBram Moolenaar"   7.4_v2  (this version): Fix error raised when converting a diff containing
75*60cce2fbSBram Moolenaar"                           an empty buffer. Jan Stocker: allow g:html_font to
76*60cce2fbSBram Moolenaar"                           take a list so it is easier to specfiy fallback
77*60cce2fbSBram Moolenaar"                           fonts in the generated CSS.
78*60cce2fbSBram Moolenaar"   7.4_v1  (Vim 7.4.0000): Fix modeline mangling for new "Vim:" format, and
79dd007ed5SBram Moolenaar"			    also for version-specific modelines like "vim>703:".
806c35beaaSBram Moolenaar"
81dd007ed5SBram Moolenaar"   7.3 updates: {{{
82*60cce2fbSBram Moolenaar"   7.3_v14 (Vim 7.3.1246): Allow suppressing line number anchors using
8322dbc77eSBram Moolenaar"			    g:html_line_ids=0. Allow customizing
8431c31679SBram Moolenaar"			    important IDs (like line IDs and fold IDs) using
8531c31679SBram Moolenaar"			    g:html_id_expr evalutated when the buffer conversion
8631c31679SBram Moolenaar"			    is started.
87*60cce2fbSBram Moolenaar"   7.3_v13 (Vim 7.3.1088): Keep foldmethod at manual in the generated file and
88543b7ef7SBram Moolenaar"			    insert modeline to set it to manual.
89543b7ef7SBram Moolenaar"			    Fix bug: diff mode with 2 unsaved buffers creates a
90543b7ef7SBram Moolenaar"			    duplicate of one buffer instead of including both.
91543b7ef7SBram Moolenaar"			    Add anchors to each line so you can put '#L123'
92543b7ef7SBram Moolenaar"			    or '#123' at the end of the URL to jump to line 123
93543b7ef7SBram Moolenaar"			    (idea by Andy Spencer). Add javascript to open folds
94543b7ef7SBram Moolenaar"			    to show the anchor being jumped to if it is hidden.
95543b7ef7SBram Moolenaar"			    Fix XML validation error: &nsbp; not part of XML.
96543b7ef7SBram Moolenaar"			    Allow TOhtml to chain together with other commands
97543b7ef7SBram Moolenaar"			    using |.
98*60cce2fbSBram Moolenaar"   7.3_v12 (Vim 7.3.0616): Fix modeline mangling to also work for when multiple
996c35beaaSBram Moolenaar"			    highlight groups make up the start-of-modeline text.
1006c35beaaSBram Moolenaar"			    Improve render time of page with uncopyable regions
1016c35beaaSBram Moolenaar"			    by not using one-input-per-char. Change name of
1026c35beaaSBram Moolenaar"			    uncopyable option from html_unselectable to
1036c35beaaSBram Moolenaar"			    html_prevent_copy. Added html_no_invalid option and
1046c35beaaSBram Moolenaar"			    default to inserting invalid markup for uncopyable
1056c35beaaSBram Moolenaar"			    regions to prevent MS Word from pasting undeletable
1066c35beaaSBram Moolenaar"			    <input> elements. Fix 'cpo' handling (Thilo Six).
1076c35beaaSBram Moolenaar"		 7.3_v12b1: Add html_unselectable option. Rework logic to
1086c35beaaSBram Moolenaar"			    eliminate post-processing substitute commands in
1096c35beaaSBram Moolenaar"			    favor of doing the work up front. Remove unnecessary
1106c35beaaSBram Moolenaar"			    special treatment of 'LineNr' highlight group. Minor
1116c35beaaSBram Moolenaar"			    speed improvements. Fix modeline mangling in
1126c35beaaSBram Moolenaar"			    generated output so it works for text in the first
1136c35beaaSBram Moolenaar"			    column. Fix missing line number and fold column in
1146c35beaaSBram Moolenaar"			    diff filler lines. Fix that some fonts have a 1px
1156c35beaaSBram Moolenaar"			    gap (using a dirty hack, improvements welcome). Add
1166c35beaaSBram Moolenaar"			    "colorscheme" meta tag. Does NOT include support for
1176c35beaaSBram Moolenaar"			    the new default foldtext added in v11, as the patch
1186c35beaaSBram Moolenaar"			    adding it has not yet been included in Vim.
1196c35beaaSBram Moolenaar"   7.3_v11 ( unreleased ): Support new default foldtext from patch by Christian
1206c35beaaSBram Moolenaar"			    Brabandt in
1216c35beaaSBram Moolenaar"			    http://groups.google.com/d/topic/vim_dev/B6FSGfq9VoI/discussion.
1226c35beaaSBram Moolenaar"			    This patch has not yet been included in Vim, thus
1236c35beaaSBram Moolenaar"			    these changes are removed in the next version.
124*60cce2fbSBram Moolenaar"   7.3_v10 (Vim 7.3.0227): Fix error E684 when converting a range wholly inside
125251e1912SBram Moolenaar"			    multiple nested folds with dynamic folding on.
126251e1912SBram Moolenaar"			    Also fix problem with foldtext in this situation.
127*60cce2fbSBram Moolenaar"   7.3_v9  (Vim 7.3.0170): Add html_pre_wrap option active with html_use_css
128251e1912SBram Moolenaar"			    and without html_no_pre, default value same as
129251e1912SBram Moolenaar"			    'wrap' option, (Andy Spencer). Don't use
130251e1912SBram Moolenaar"			    'fileencoding' for converted document encoding if
131251e1912SBram Moolenaar"			    'buftype' indicates a special buffer which isn't
132251e1912SBram Moolenaar"			    written.
133*60cce2fbSBram Moolenaar"   7.3_v8  (Vim 7.3.0100): Add html_expand_tabs option to allow leaving tab
134251e1912SBram Moolenaar"			    characters in generated output (Andy Spencer).
135251e1912SBram Moolenaar"			    Escape text that looks like a modeline so Vim
136251e1912SBram Moolenaar"			    doesn't use anything in the converted HTML as a
137251e1912SBram Moolenaar"			    modeline. Bugfixes: Fix folding when a fold starts
138251e1912SBram Moolenaar"			    before the conversion range. Remove fold column when
139251e1912SBram Moolenaar"			    there are no folds.
140*60cce2fbSBram Moolenaar"   7.3_v7  (Vim 7-3-0063): see betas released on vim_dev below:
141166af9bbSBram Moolenaar"		  7.3_v7b3: Fixed bug, convert Unicode to UTF-8 all the way.
142166af9bbSBram Moolenaar"		  7.3_v7b2: Remove automatic detection of encodings that are not
143166af9bbSBram Moolenaar"			    supported by all major browsers according to
144251e1912SBram Moolenaar"			    http://wiki.whatwg.org/wiki/Web_Encodings and
145251e1912SBram Moolenaar"			    convert to UTF-8 for all Unicode encodings. Make
146251e1912SBram Moolenaar"			    HTML encoding to Vim encoding detection be
147166af9bbSBram Moolenaar"			    case-insensitive for built-in pairs.
148166af9bbSBram Moolenaar"		  7.3_v7b1: Remove use of setwinvar() function which cannot be
149166af9bbSBram Moolenaar"			    called in restricted mode (Andy Spencer). Use
150166af9bbSBram Moolenaar"			    'fencoding' instead of 'encoding' to determine by
151166af9bbSBram Moolenaar"			    charset, and make sure the 'fenc' of the generated
152166af9bbSBram Moolenaar"			    file matches its indicated charset. Add charsets for
153166af9bbSBram Moolenaar"			    all of Vim's natively supported encodings.
154*60cce2fbSBram Moolenaar"   7.3_v6  (Vim 7.3.0000): Really fix bug with 'nowrapscan', 'magic' and other
155166af9bbSBram Moolenaar"			    user settings interfering with diff mode generation,
156166af9bbSBram Moolenaar"			    trailing whitespace (e.g. line number column) when
157166af9bbSBram Moolenaar"			    using html_no_pre, and bugs when using
158166af9bbSBram Moolenaar"			    html_hover_unfold.
159166af9bbSBram Moolenaar"   7.3_v5  ( unreleased ): Fix bug with 'nowrapscan' and also with out-of-sync
160166af9bbSBram Moolenaar"			    folds in diff mode when first line was folded.
161*60cce2fbSBram Moolenaar"   7.3_v4  (Vim 7.3.0000): Bugfixes, especially for xhtml markup, and diff mode
162*60cce2fbSBram Moolenaar"   7.3_v3  (Vim 7.3.0000): Refactor option handling and make html_use_css
163166af9bbSBram Moolenaar"			    default to true when not set to anything. Use strict
164166af9bbSBram Moolenaar"			    doctypes where possible. Rename use_xhtml option to
165166af9bbSBram Moolenaar"			    html_use_xhtml for consistency. Use .xhtml extension
166166af9bbSBram Moolenaar"			    when using this option. Add meta tag for settings.
167*60cce2fbSBram Moolenaar"   7.3_v2  (Vim 7.3.0000): Fix syntax highlighting in diff mode to use both the
168166af9bbSBram Moolenaar"			    diff colors and the normal syntax colors
169*60cce2fbSBram Moolenaar"   7.3_v1  (Vim 7.3.0000): Add conceal support and meta tags in output
1706c35beaaSBram Moolenaar"}}}
171dd007ed5SBram Moolenaar"}}}
172071d4279SBram Moolenaar
173b02cbe34SBram Moolenaar" Define the :TOhtml command when:
174b02cbe34SBram Moolenaar" - 'compatible' is not set
175b02cbe34SBram Moolenaar" - this plugin was not already loaded
1766c35beaaSBram Moolenaar" - user commands are available. {{{
177071d4279SBram Moolenaarif !&cp && !exists(":TOhtml") && has("user_commands")
178543b7ef7SBram Moolenaar  command -range=% -bar TOhtml :call tohtml#Convert2HTML(<line1>, <line2>)
1796c35beaaSBram Moolenaarendif "}}}
180349b2fb0SBram Moolenaar
181349b2fb0SBram Moolenaar" Make sure any patches will probably use consistent indent
1826c35beaaSBram Moolenaar"   vim: ts=8 sw=2 sts=2 noet fdm=marker
183