1071d4279SBram Moolenaar" Vim plugin for converting a syntax highlighted file to HTML. 2349b2fb0SBram Moolenaar" Maintainer: Ben Fritz <[email protected]> 309c6f265SBram Moolenaar" Last Change: 2019 Nov 13 4b02cbe34SBram Moolenaar" 5349b2fb0SBram Moolenaar" The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and 6349b2fb0SBram Moolenaar" $VIMRUNTIME/syntax/2html.vim 78ada2ccaSBram Moolenaar" 8251e1912SBram Moolenaarif exists('g:loaded_2html_plugin') 9251e1912SBram Moolenaar finish 10251e1912SBram Moolenaarendif 1109c6f265SBram Moolenaarlet g:loaded_2html_plugin = 'vim8.1_v2' 12251e1912SBram Moolenaar 13166af9bbSBram Moolenaar" 146c35beaaSBram Moolenaar" Changelog: {{{ 1509c6f265SBram Moolenaar" 8.1_v2 (this version): - Fix Bitbucket issue #19: fix calculation of tab 1609c6f265SBram Moolenaar" stop position to use in expanding a tab, when that 1709c6f265SBram Moolenaar" tab occurs after a syntax match which in turn 1809c6f265SBram Moolenaar" comes after previously expanded tabs. 1909c6f265SBram Moolenaar" - Set eventignore while splitting a window for the 2009c6f265SBram Moolenaar" destination file to ignore FileType events; 2109c6f265SBram Moolenaar" speeds up processing when the destination file 2209c6f265SBram Moolenaar" already exists and HTML highlight takes too long. 2309c6f265SBram Moolenaar" - Fix Bitbucket issue #20: progress bar could not be 2409c6f265SBram Moolenaar" seen when DiffDelete background color matched 2509c6f265SBram Moolenaar" StatusLine background color. Added TOhtmlProgress 2609c6f265SBram Moolenaar" highlight group for manual user override, but 2709c6f265SBram Moolenaar" calculate it to be visible compared to StatusLine 2809c6f265SBram Moolenaar" by default. 2909c6f265SBram Moolenaar" - Fix Bitbucket issue #1: Remove workaround for old 3009c6f265SBram Moolenaar" browsers which don't support 'ch' CSS unit, since 3109c6f265SBram Moolenaar" all modern browsers, including IE>=9, support it. 3209c6f265SBram Moolenaar" - Fix Bitbucket issue #10: support termguicolors 3309c6f265SBram Moolenaar" - Fix Bitbucket issue #21: default to using 3409c6f265SBram Moolenaar" generated content instead of <input> tags for 3509c6f265SBram Moolenaar" uncopyable text, so that text is correctly 3609c6f265SBram Moolenaar" prevented from being copied in chrome. Use 3709c6f265SBram Moolenaar" g:html_use_input_for_pc option to control the 3809c6f265SBram Moolenaar" method used. 3909c6f265SBram Moolenaar" - Switch to HTML5 to allow using vnu as a validator 4009c6f265SBram Moolenaar" in unit test. 4109c6f265SBram Moolenaar" - Fix fallback sizing of <input> tags for browsers 4209c6f265SBram Moolenaar" without "ch" support. 4309c6f265SBram Moolenaar" - Fix cursor on unselectable diff filler text. 4409c6f265SBram Moolenaar" 8.1_v1 (Vim 8.1.0528): - Fix Bitbucket issue #6: Don't generate empty 4509c6f265SBram Moolenaar" script tag. 4609c6f265SBram Moolenaar" - Fix Bitbucket issue #5: javascript should 47f0d58efcSBram Moolenaar" declare variables with "var". 4809c6f265SBram Moolenaar" - Fix Bitbucket issue #13: errors thrown sourcing 49f0d58efcSBram Moolenaar" 2html.vim directly when plugins not loaded. 5009c6f265SBram Moolenaar" - Fix Bitbucket issue #16: support 'vartabstop'. 51f0d58efcSBram Moolenaar" 52f0d58efcSBram Moolenaar" 7.4 updates: {{{ 53f0d58efcSBram Moolenaar" 7.4_v2 (Vim 7.4.0899): Fix error raised when converting a diff containing 5460cce2fbSBram Moolenaar" an empty buffer. Jan Stocker: allow g:html_font to 5560cce2fbSBram Moolenaar" take a list so it is easier to specfiy fallback 5660cce2fbSBram Moolenaar" fonts in the generated CSS. 5760cce2fbSBram Moolenaar" 7.4_v1 (Vim 7.4.0000): Fix modeline mangling for new "Vim:" format, and 58dd007ed5SBram Moolenaar" also for version-specific modelines like "vim>703:". 59f0d58efcSBram Moolenaar"}}} 606c35beaaSBram Moolenaar" 61dd007ed5SBram Moolenaar" 7.3 updates: {{{ 6260cce2fbSBram Moolenaar" 7.3_v14 (Vim 7.3.1246): Allow suppressing line number anchors using 6322dbc77eSBram Moolenaar" g:html_line_ids=0. Allow customizing 6431c31679SBram Moolenaar" important IDs (like line IDs and fold IDs) using 65*6c391a74SBram Moolenaar" g:html_id_expr evaluated when the buffer conversion 6631c31679SBram Moolenaar" is started. 6760cce2fbSBram Moolenaar" 7.3_v13 (Vim 7.3.1088): Keep foldmethod at manual in the generated file and 68543b7ef7SBram Moolenaar" insert modeline to set it to manual. 69543b7ef7SBram Moolenaar" Fix bug: diff mode with 2 unsaved buffers creates a 70543b7ef7SBram Moolenaar" duplicate of one buffer instead of including both. 71543b7ef7SBram Moolenaar" Add anchors to each line so you can put '#L123' 72543b7ef7SBram Moolenaar" or '#123' at the end of the URL to jump to line 123 73543b7ef7SBram Moolenaar" (idea by Andy Spencer). Add javascript to open folds 74543b7ef7SBram Moolenaar" to show the anchor being jumped to if it is hidden. 75543b7ef7SBram Moolenaar" Fix XML validation error: &nsbp; not part of XML. 76543b7ef7SBram Moolenaar" Allow TOhtml to chain together with other commands 77543b7ef7SBram Moolenaar" using |. 7860cce2fbSBram Moolenaar" 7.3_v12 (Vim 7.3.0616): Fix modeline mangling to also work for when multiple 796c35beaaSBram Moolenaar" highlight groups make up the start-of-modeline text. 806c35beaaSBram Moolenaar" Improve render time of page with uncopyable regions 816c35beaaSBram Moolenaar" by not using one-input-per-char. Change name of 826c35beaaSBram Moolenaar" uncopyable option from html_unselectable to 836c35beaaSBram Moolenaar" html_prevent_copy. Added html_no_invalid option and 846c35beaaSBram Moolenaar" default to inserting invalid markup for uncopyable 856c35beaaSBram Moolenaar" regions to prevent MS Word from pasting undeletable 866c35beaaSBram Moolenaar" <input> elements. Fix 'cpo' handling (Thilo Six). 876c35beaaSBram Moolenaar" 7.3_v12b1: Add html_unselectable option. Rework logic to 886c35beaaSBram Moolenaar" eliminate post-processing substitute commands in 896c35beaaSBram Moolenaar" favor of doing the work up front. Remove unnecessary 906c35beaaSBram Moolenaar" special treatment of 'LineNr' highlight group. Minor 916c35beaaSBram Moolenaar" speed improvements. Fix modeline mangling in 926c35beaaSBram Moolenaar" generated output so it works for text in the first 936c35beaaSBram Moolenaar" column. Fix missing line number and fold column in 946c35beaaSBram Moolenaar" diff filler lines. Fix that some fonts have a 1px 956c35beaaSBram Moolenaar" gap (using a dirty hack, improvements welcome). Add 966c35beaaSBram Moolenaar" "colorscheme" meta tag. Does NOT include support for 976c35beaaSBram Moolenaar" the new default foldtext added in v11, as the patch 986c35beaaSBram Moolenaar" adding it has not yet been included in Vim. 996c35beaaSBram Moolenaar" 7.3_v11 ( unreleased ): Support new default foldtext from patch by Christian 1006c35beaaSBram Moolenaar" Brabandt in 1016c35beaaSBram Moolenaar" http://groups.google.com/d/topic/vim_dev/B6FSGfq9VoI/discussion. 1026c35beaaSBram Moolenaar" This patch has not yet been included in Vim, thus 1036c35beaaSBram Moolenaar" these changes are removed in the next version. 10460cce2fbSBram Moolenaar" 7.3_v10 (Vim 7.3.0227): Fix error E684 when converting a range wholly inside 105251e1912SBram Moolenaar" multiple nested folds with dynamic folding on. 106251e1912SBram Moolenaar" Also fix problem with foldtext in this situation. 10760cce2fbSBram Moolenaar" 7.3_v9 (Vim 7.3.0170): Add html_pre_wrap option active with html_use_css 108251e1912SBram Moolenaar" and without html_no_pre, default value same as 109251e1912SBram Moolenaar" 'wrap' option, (Andy Spencer). Don't use 110251e1912SBram Moolenaar" 'fileencoding' for converted document encoding if 111251e1912SBram Moolenaar" 'buftype' indicates a special buffer which isn't 112251e1912SBram Moolenaar" written. 11360cce2fbSBram Moolenaar" 7.3_v8 (Vim 7.3.0100): Add html_expand_tabs option to allow leaving tab 114251e1912SBram Moolenaar" characters in generated output (Andy Spencer). 115251e1912SBram Moolenaar" Escape text that looks like a modeline so Vim 116251e1912SBram Moolenaar" doesn't use anything in the converted HTML as a 117251e1912SBram Moolenaar" modeline. Bugfixes: Fix folding when a fold starts 118251e1912SBram Moolenaar" before the conversion range. Remove fold column when 119251e1912SBram Moolenaar" there are no folds. 12060cce2fbSBram Moolenaar" 7.3_v7 (Vim 7-3-0063): see betas released on vim_dev below: 121166af9bbSBram Moolenaar" 7.3_v7b3: Fixed bug, convert Unicode to UTF-8 all the way. 122166af9bbSBram Moolenaar" 7.3_v7b2: Remove automatic detection of encodings that are not 123166af9bbSBram Moolenaar" supported by all major browsers according to 124251e1912SBram Moolenaar" http://wiki.whatwg.org/wiki/Web_Encodings and 125251e1912SBram Moolenaar" convert to UTF-8 for all Unicode encodings. Make 126251e1912SBram Moolenaar" HTML encoding to Vim encoding detection be 127166af9bbSBram Moolenaar" case-insensitive for built-in pairs. 128166af9bbSBram Moolenaar" 7.3_v7b1: Remove use of setwinvar() function which cannot be 129166af9bbSBram Moolenaar" called in restricted mode (Andy Spencer). Use 130166af9bbSBram Moolenaar" 'fencoding' instead of 'encoding' to determine by 131166af9bbSBram Moolenaar" charset, and make sure the 'fenc' of the generated 132166af9bbSBram Moolenaar" file matches its indicated charset. Add charsets for 133166af9bbSBram Moolenaar" all of Vim's natively supported encodings. 13460cce2fbSBram Moolenaar" 7.3_v6 (Vim 7.3.0000): Really fix bug with 'nowrapscan', 'magic' and other 135166af9bbSBram Moolenaar" user settings interfering with diff mode generation, 136166af9bbSBram Moolenaar" trailing whitespace (e.g. line number column) when 137166af9bbSBram Moolenaar" using html_no_pre, and bugs when using 138166af9bbSBram Moolenaar" html_hover_unfold. 139166af9bbSBram Moolenaar" 7.3_v5 ( unreleased ): Fix bug with 'nowrapscan' and also with out-of-sync 140166af9bbSBram Moolenaar" folds in diff mode when first line was folded. 14160cce2fbSBram Moolenaar" 7.3_v4 (Vim 7.3.0000): Bugfixes, especially for xhtml markup, and diff mode 14260cce2fbSBram Moolenaar" 7.3_v3 (Vim 7.3.0000): Refactor option handling and make html_use_css 143166af9bbSBram Moolenaar" default to true when not set to anything. Use strict 144166af9bbSBram Moolenaar" doctypes where possible. Rename use_xhtml option to 145166af9bbSBram Moolenaar" html_use_xhtml for consistency. Use .xhtml extension 146166af9bbSBram Moolenaar" when using this option. Add meta tag for settings. 14760cce2fbSBram Moolenaar" 7.3_v2 (Vim 7.3.0000): Fix syntax highlighting in diff mode to use both the 148166af9bbSBram Moolenaar" diff colors and the normal syntax colors 14960cce2fbSBram Moolenaar" 7.3_v1 (Vim 7.3.0000): Add conceal support and meta tags in output 1506c35beaaSBram Moolenaar"}}} 151dd007ed5SBram Moolenaar"}}} 152071d4279SBram Moolenaar 153f0d58efcSBram Moolenaar" TODO: {{{ 154f0d58efcSBram Moolenaar" * Check the issue tracker: 155f0d58efcSBram Moolenaar" https://bitbucket.org/fritzophrenic/vim-tohtml/issues?status=new&status=open 156f0d58efcSBram Moolenaar" * Options for generating the CSS in external style sheets. New :TOcss 157f0d58efcSBram Moolenaar" command to convert the current color scheme into a (mostly) generic CSS 158f0d58efcSBram Moolenaar" stylesheet which can be re-used. Alternate stylesheet support? Good start 159f0d58efcSBram Moolenaar" by Erik Falor 160f0d58efcSBram Moolenaar" ( https://groups.google.com/d/topic/vim_use/7XTmC4D22dU/discussion ). 161f0d58efcSBram Moolenaar" * Add optional argument to :TOhtml command to specify mode (gui, cterm, 162f0d58efcSBram Moolenaar" term) to use for the styling. Suggestion by "nacitar". 163f0d58efcSBram Moolenaar" * Add way to override or specify which RGB colors map to the color numbers 164f0d58efcSBram Moolenaar" in cterm. Get better defaults than just guessing? Suggestion by "nacitar". 165f0d58efcSBram Moolenaar" * Disable filetype detection until after all processing is done. 166f0d58efcSBram Moolenaar" * Add option for not generating the hyperlink on stuff that looks like a 167f0d58efcSBram Moolenaar" URL? Or just color the link to fit with the colorscheme (and only special 168f0d58efcSBram Moolenaar" when hovering)? 169f0d58efcSBram Moolenaar" * Bug: Opera does not allow printing more than one page if uncopyable 170f0d58efcSBram Moolenaar" regions is turned on. Possible solution: Add normal text line numbers with 171f0d58efcSBram Moolenaar" display:none, set to display:inline for print style sheets, and hide 172f0d58efcSBram Moolenaar" <input> elements for print, to allow Opera printing multiple pages (and 173f0d58efcSBram Moolenaar" other uncopyable areas?). May need to make the new text invisible to IE 174f0d58efcSBram Moolenaar" with conditional comments to prevent copying it, IE for some reason likes 175f0d58efcSBram Moolenaar" to copy hidden text. Other browsers too? 176f0d58efcSBram Moolenaar" * Bug: still a 1px gap throughout the fold column when html_prevent_copy is 177f0d58efcSBram Moolenaar" "fn" in some browsers. Specifically, in Chromium on Ubuntu (but not Chrome 178f0d58efcSBram Moolenaar" on Windows). Perhaps it is font related? 179f0d58efcSBram Moolenaar" * Bug: still some gaps in the fold column when html_prevent_copy contains 180f0d58efcSBram Moolenaar" 'd' and showing the whole diff (observed in multiple browsers). Only gaps 181f0d58efcSBram Moolenaar" on diff lines though. 182f0d58efcSBram Moolenaar" * Undercurl support via CSS3, with fallback to dotted or something: 183f0d58efcSBram Moolenaar" https://groups.google.com/d/topic/vim_use/BzXA6He1pHg/discussion 184f0d58efcSBram Moolenaar" * Redo updates for modified default foldtext (v11) when/if the patch is 185f0d58efcSBram Moolenaar" accepted to modify it. 186f0d58efcSBram Moolenaar" * Test case +diff_one_file-dynamic_folds+expand_tabs-hover_unfold 187f0d58efcSBram Moolenaar" +ignore_conceal-ignore_folding+no_foldcolumn+no_pre+no_progress 188f0d58efcSBram Moolenaar" +number_lines-pre_wrap-use_css+use_xhtml+whole_filler.xhtml 189f0d58efcSBram Moolenaar" does not show the whole diff filler as it is supposed to? 190f0d58efcSBram Moolenaar" * Bug: when 'isprint' is wrong for the current encoding, will generate 191f0d58efcSBram Moolenaar" invalid content. Can/should anything be done about this? Maybe a separate 192f0d58efcSBram Moolenaar" plugin to correct 'isprint' based on encoding? 193f0d58efcSBram Moolenaar" * Check to see if the windows-125\d encodings actually work in Unix without 194f0d58efcSBram Moolenaar" the 8bit- prefix. Add prefix to autoload dictionaries for Unix if not. 195f0d58efcSBram Moolenaar" * Font auto-detection similar to 196f0d58efcSBram Moolenaar" http://www.vim.org/scripts/script.php?script_id=2384 but for a variety of 197f0d58efcSBram Moolenaar" platforms. 198f0d58efcSBram Moolenaar" * Pull in code from http://www.vim.org/scripts/script.php?script_id=3113 : 199f0d58efcSBram Moolenaar" - listchars support 200f0d58efcSBram Moolenaar" - full-line background highlight 201f0d58efcSBram Moolenaar" - other? 202f0d58efcSBram Moolenaar" * Make it so deleted lines in a diff don't create side-scrolling (get it 203f0d58efcSBram Moolenaar" free with full-line background highlight above). 204f0d58efcSBram Moolenaar" * Restore open/closed folds and cursor position after processing each file 205f0d58efcSBram Moolenaar" with option not to restore for speed increase. 206f0d58efcSBram Moolenaar" * Add extra meta info (generation time, etc.)? 207f0d58efcSBram Moolenaar" * Tidy up so we can use strict doctype in even more situations 208f0d58efcSBram Moolenaar" * Implementation detail: add threshold for writing the lines to the html 209f0d58efcSBram Moolenaar" buffer before we're done (5000 or so lines should do it) 210f0d58efcSBram Moolenaar" * TODO comments for code cleanup scattered throughout 211f0d58efcSBram Moolenaar"}}} 212f0d58efcSBram Moolenaar 213b02cbe34SBram Moolenaar" Define the :TOhtml command when: 214b02cbe34SBram Moolenaar" - 'compatible' is not set 215f0d58efcSBram Moolenaar" - this plugin or user override was not already loaded 2166c35beaaSBram Moolenaar" - user commands are available. {{{ 217071d4279SBram Moolenaarif !&cp && !exists(":TOhtml") && has("user_commands") 218543b7ef7SBram Moolenaar command -range=% -bar TOhtml :call tohtml#Convert2HTML(<line1>, <line2>) 2196c35beaaSBram Moolenaarendif "}}} 220349b2fb0SBram Moolenaar 221349b2fb0SBram Moolenaar" Make sure any patches will probably use consistent indent 2226c35beaaSBram Moolenaar" vim: ts=8 sw=2 sts=2 noet fdm=marker 223