Last active
December 19, 2015 07:59
-
-
Save dcvezzani/5922851 to your computer and use it in GitHub Desktop.
Clean up my quick text file journal entries into html I can slap into my blog. Put this in your ~/.vimrc file or create a vim script file that can be included in ~/.vimrc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ************* basic conversion script ****************** | |
" the '/e' regexp flag in vim allows subsequent regexp to be | |
" run even if the current regexp doesn't have any hits | |
function! JournalBasicConversion(...) | |
" isolate each code block and surround with <pre... | |
:%s/^}}/ç/g | |
:%s/\n{{\(\([\r\n]\+[^ç]\+.*\)\+\)\nç/\r<pre class=\"code\">\1\r<\/pre>/eg | |
" create titles | |
:%s/^==\+ \(.\+\)$/<h4>\1<\/h4>/eg | |
" create hyperlinks | |
:%s/^\[\([^\]]\+\)\]$/<a href=\"\1\" target=\"_new\">\1<\/a>/eg | |
" create lines between elements | |
:%s/>\n\n/>\r<br \/>\r\r/eg | |
endfunction | |
" ************* basic conversion script ****************** | |
" select code blocks and then clean them up, individually, | |
" escaping the less than character | |
function! JournalCleanUpCodeBlock(...) | |
" puts single space between tab and less than | |
" otherwise, won't render < correctly in Blogger | |
:s/\t</\t \</eg | |
" gets rid of <br /> tags inside of code block example | |
:*s/^<br \/>\n//eg | |
" escapes less than, typically part of end tag | |
:*s/</\</eg | |
endfunction | |
" ************* basic conversion script ****************** | |
" same as JournalCleanUpCodeBlock, only stand-alone <br /> | |
" tags are left included | |
function! JournalCleanUpCodeBlockIncludeBr(...) | |
:s/\t</\t \</eg | |
:*s/</\</eg | |
endfunction | |
" ************* example using macro style notation ****************** | |
" <CR> represents an actual carriage return character (and not simply an escaped representation such as '\r') | |
" <CR> is rendered as '^M' on my version of MacVim | |
":map <C-J>,c :%s/^}}/ç/g<CR>:%s/\n{{\(\([\r\n]\+[^ç]\+.*\)\+\)\nç/\r<pre class=\"code\">\1\r<\/pre>/eg<CR>:%s/^==\+ \(.\+\)$/<h4>\1<\/h4>/eg<CR>:%s/^\[\([^\]]\+\)\]$/<a href=\"\1\" target=\"_new\">\1<\/a>/eg | |
:%s/>\n\n/>\r<br \/>\r\r/eg | |
" ************* mappings ****************** | |
" <CR> represents an actual carriage return character (and not simply an escaped representation such as '\r') | |
" :vnoremap - mappings that are only available in <visual> mode | |
" gv - reselect the last selection | |
:map <C-J>,c :call JournalBasicConversion()<CR>gv | |
gv | |
:map <C-J>,fp /<pre class=\"code\"<CR>gv | |
:vnoremap <C-J>,b :call JournalCleanUpCodeBlock()<CR>gv | |
gv | |
:vnoremap <C-J>,B :call JournalCleanUpCodeBlockIncludeBr()<CR>gv | |
gv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment