@ -0,0 +1,5 @@ | |||
# Vim-Checkmark | |||
This is a very early work in progress! | |||
The goal is to have a scroll-bound, updating render of markdown alongside the raw file. I'm not sure I can get there with Glow so we're experimenting with the python route. |
@ -0,0 +1,42 @@ | |||
" vim global plugin for live-preview of markdown | |||
" Author: Noah Hall | |||
if !has('python3') | |||
echo "Error: no python3 detected :(" | |||
finish | |||
endif | |||
if exists("g:loaded_VimCheckmark") || &cp | |||
finish | |||
endif | |||
let g:loaded_VimCheckmark = 1 | |||
let s:keepcpo = &cpo | |||
set cpo&vim | |||
" let's try stuff!! | |||
" setup python | |||
let s:plugin_root = fnamemodify(resolve(expand('<sfile>:p')), ':h') | |||
python << EOF | |||
import sys | |||
from os.path import normpath, join | |||
import vim | |||
plugin_root = vim.eval('s:plugin_root') | |||
python_root = normpath(join(plugin_root, '..', 'python')) | |||
sys.path.insert(0, python_root) | |||
import vim_checkmark | |||
EOF | |||
" probably doesn't even load lol | |||
function! checkmark | |||
:terminal python vim_checkmark @% | |||
endfunction | |||
let &cpo = s:keepcpo | |||
unlet s:keepcpo |
@ -0,0 +1,37 @@ | |||
#!/usr/bin/python3 | |||
import sys | |||
from rich.markdown import Markdown | |||
from textual import events | |||
from textual.app import App | |||
from textual.widgets import ScrollView | |||
class VimCheckmark(App): | |||
"""Render markdown, scrollbind, etc""" | |||
async def on_load(self) -> None: | |||
"""set up""" | |||
try: | |||
self.path = sys.argv[-1] | |||
except IndexError: | |||
raise() | |||
# self.path = "STDIN" | |||
# | |||
# if self.path == "STDIN": | |||
# for line in fileinput.input(): | |||
async def on_mount(self, event: events.Mount) -> None: | |||
"""handle rendering""" | |||
body = ScrollView(gutter=1) | |||
await self.view.dock(body) | |||
with open(self.path, 'rb') as fh: | |||
output = Markdown(fh.read(), hyperlinks=True) | |||
await body.update(output) | |||
def main() -> None: | |||
"""simple container func""" | |||
VimCheckmark.run() |