Skip to content

Commit

Permalink
Proper HTML encoding, foolproof publish#customize_html()
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 20, 2010
1 parent 514a5f7 commit be773a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions autoload.vim
Expand Up @@ -245,7 +245,7 @@ endfunction
function! publish#customize_html(page_title) " {{{1

" Change document title to relative pathname.
silent keepjumps %s@<title>\zs.*\ze</title>@\=a:page_title@
silent keepjumps %s@<title>\zs.*\ze</title>@\=publish#html_encode(a:page_title)@e

" Insert CSS to remove the default colors and underline from hyper links
" and to remove any padding between the browser chrome and page content.
Expand All @@ -254,11 +254,18 @@ function! publish#customize_html(page_title) " {{{1
let custom_css .= "\npre:hover a:link, pre:hover a:visited { text-decoration: underline; }"
let custom_css .= "\na:link span, a:visited span { text-decoration: inherit; }"
let custom_css .= "\n.lnr a:link, .lnr a:visited { text-decoration: none !important; }"
silent keepjumps %s@\ze\_s\+-->\_s\+</style>@\= "\n" . custom_css@
silent keepjumps %s@\ze\_s\+-->\_s\+</style>@\= "\n" . custom_css@e

" Add link anchors to line numbering.
silent keepjumps %s@<span class="lnr">\zs\s*\(\d\+\)\s*\ze</span>@<a name="l\1" href="#l\1">\0</a>@g
silent keepjumps %s@<span class="lnr">\zs\s*\(\d\+\)\s*\ze</span>@<a name="l\1" href="#l\1">\0</a>@eg

endfunction

function! publish#html_encode(s) " {{{1
let s = substitute(a:s, '&', '&amp;', 'g')
let s = substitute(s, '<', '&lt;', 'g')
let s = substitute(s, '>', '&gt;', 'g')
return s
endfunction

" vim: ts=2 sw=2 et
3 changes: 2 additions & 1 deletion publish.vim
Expand Up @@ -105,7 +105,8 @@ function! s:ConvertTagToLink(name) " {{{1
" TODO This is likely to be slow so cache the results?!
let relative = xolox#path#relative(pathname, s:current_source_directory)
let suffix = g:publish_omit_dothtml ? '' : '.html'
return '<a href="' . relative . suffix . '#l' . entry.lnum . '">' . a:name . '</a>'
let href = publish#html_encode(relative . suffix . '#l' . entry.lnum)
return '<a href="' . href . '">' . a:name . '</a>'
catch
return a:name
endtry
Expand Down

0 comments on commit be773a1

Please sign in to comment.