diff --git a/README.md b/README.md index f90dd10..e895e52 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ Markdown files are rendered a bit more fancifully. Be sure to read the help file ![presenting.vim Markdown demo](examples/FancyMarkdown.gif) +Markdown image links where handled by converting them into ascii. + +![image2ascii markdown example](examples/image2ascii_demo.png) + ## Installation Use [pathogen][3] or [vundle][4] to install presenting.vim. diff --git a/autoload/markdown.vim b/autoload/markdown.vim index b6870af..536195d 100644 --- a/autoload/markdown.vim +++ b/autoload/markdown.vim @@ -116,6 +116,28 @@ function! markdown#format(text, last_line, state) endwhile let new_text += [' ▐ '.l:text] + " Image - Centered image2ascii for markdown image: ![alt_text](img_url?r=radius&w=width&h=height) + elseif a:text =~? '\.*\!\[.*\]\(.*\)' && g:presenting_image2ascii && executable('image2ascii') + let alt_text = matchstr(a:text, '\.*\!\[\zs[^]]\+\ze') + let img_url = matchstr(a:text, '\.*\!\[.*\](\zs[^ ?)]\+\ze') + let size_query_string = matchstr(a:text, '\.*\!\[.*\](.*?\zs[^)]\+\ze') + let r = matchstr(size_query_string, '\.*r=\zs[0-9]*[.]\?[0-9]*\ze') + let w = matchstr(size_query_string, '\.*w=\zs[0-9]*\ze') + let h = matchstr(size_query_string, '\.*h=\zs[0-9]*\ze') + let size_params = ' -w 40 -g 40' + if r != "" + let size_params = ' -r ' .. r + elseif w != "" && h != "" + let size_params = ' -w ' .. w .. ' -g ' .. h + endif + let output = system('image2ascii -f ' .. img_url .. size_params .. ' -c=false') + + if output =~? '\.*open image failed\.*' + " Show alt text if image url dose not exists + let new_text += s:Center([alt_text], '«img»') + else + let new_text += s:Center(split(output,"\n"), '«img»') + endif " Return text as is. else diff --git a/doc/presenting.txt b/doc/presenting.txt index b6016da..8f2a722 100644 --- a/doc/presenting.txt +++ b/doc/presenting.txt @@ -153,7 +153,24 @@ These fonts can be changed with the the following variables: > More information about figlets can be found at https://figlet.org and the interactive website http://patorjk.com/software/taag can be used to test out the different fonts. +------------------------------------------------------------------------------ + *presenting_image2ascii* + +Note: Currently, this applies only to Markdown files. + +Markdown image embeddings can also been rendered into ascii by a tool called +image2ascii. This is on by default, and can be turned off by setting > + :let g:presenting_image2ascii = 0 +> + +You can append size paremeters (ratio or width and height) in http query +paremeters style after the URL of the graphic file to resize it. : > + ![alt text](./image.png?r=0.4) + ![alt text](./image.png?w=55&h=35) +> +More information about image2ascii can be found at +https://github.com/qeesung/image2ascii ============================================================================== ISSUES *presenting-issues* diff --git a/examples/1200px-Vimlogo.png b/examples/1200px-Vimlogo.png new file mode 100644 index 0000000..b28cb0a Binary files /dev/null and b/examples/1200px-Vimlogo.png differ diff --git a/examples/PresentingDemo.markdown b/examples/PresentingDemo.markdown index 05e33c1..fda9113 100644 --- a/examples/PresentingDemo.markdown +++ b/examples/PresentingDemo.markdown @@ -120,6 +120,19 @@ function Factorial(n) endfunction ``` +# Images + +If [image2ascii](https://github.com/qeesung/image2ascii) is installed and enabled markdown image links are converted to ascii and displayed in the presentation buffer. +You can append `?r=ratio` or `?w=WIDTH&h=HEIGHT` after the URL of the graphic file to resize the image. + +```bash +![vim logo](./1200px-Vimlogo.png?r=0.05) +``` + +Results into: + +![vim logo](./1200px-Vimlogo.png?r=0.05) + # The End diff --git a/examples/image2ascii_demo.png b/examples/image2ascii_demo.png new file mode 100644 index 0000000..5426912 Binary files /dev/null and b/examples/image2ascii_demo.png differ diff --git a/plugin/presenting.vim b/plugin/presenting.vim index 7590d0d..41b6512 100644 --- a/plugin/presenting.vim +++ b/plugin/presenting.vim @@ -10,6 +10,8 @@ let g:presenting_figlets = get(g:, 'presenting_figlets', 1) let g:presenting_font_large = get(g:, 'presenting_font_large', 'standard') let g:presenting_font_small = get(g:, 'presenting_font_small', 'small') +let g:presenting_image2ascii = get(g:, 'presenting_image2ascii', 1) + let s:presenting_id = 0 let s:showtabline = &showtabline diff --git a/syntax/presenting_markdown.vim b/syntax/presenting_markdown.vim index d3521ab..a1ceeae 100644 --- a/syntax/presenting_markdown.vim +++ b/syntax/presenting_markdown.vim @@ -12,6 +12,10 @@ highlight default link presentingH2 markdownH2 highlight default link presentingH3 markdownH3 highlight default link presentingH4 markdownH4 +syntax match presentingImageMarker /^«img»/ conceal +syntax match presentingImage /^«img».*/ contains=presentingImageMarker +highlight default link presentingImage Normal + syntax match presentingOrderedListMarker /^\s*\d\+\./ syntax match presentingListMarker /^\s*•/ syntax match presentingCheckboxMarker /^\s*[■□]/