Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To pdf #5

Merged
merged 9 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Draft.vim
Quickly writeup and save drafts for messaging apps in your favorite editor
Quickly writeup and save drafts for messaging apps in your favorite editor [vimawesome.com/plugin/draft-vim](https://vimawesome.com/plugin/draft-vim)

## Why use Draft.vim
I often write important messages in a vim buffer before I send it.
- The main reason for this is because it is simply faster.
- The second reason is you might want syntax highlighting or auto formating.
- Also, sometimes you want to write a message without worrying about accidentally sending it.

- The main reason for this is because it is simply faster.
- The second reason is you might want syntax highlighting or auto formating.
- Also, sometimes you want to write a message without worrying about accidentally sending it.

## Features
- Quickly open a new file, well named
- File contains attributes like date, title, and platform that can be searchable
- Quickly open a new file, well named
- File contains attributes like date, title, and platform that can be searchable

## Setup and Config

#### Make a drafts directory
- Add the command to setup a drafts directory
- Add the command to setup a drafts directory
```vim
let g:drafts_directory = "/path/to/drafts/"
```
Expand All @@ -41,22 +42,22 @@ nnoremap <Leader>z :call OpenDrafts()<CR>

### Commands

| Command | Description |
|----------------------|-------------------------------------------------|
| Draft | Open a blanck new draft |
| Draft "title" | Open a draft with a title |
| DraftExt "extension" | Change the file extension of a draft |
| Drafts | Open the draft directory in a buffer |
| DraftCopy | Copy the contents of the draft to the clipboard |
| Command | Description |
|------------------------|-------------------------------------------------|
| Draft | Open a blanck new draft |
| Draft `"title"` | Open a draft with a title |
| DraftExt `"extension"` | Change the file extension of a draft |
| Drafts | Open the draft directory in a buffer |
| DraftCopy | Copy the contents of the draft to the clipboard |

### More info

- New draft: run `:Draft` or `:Draft "<Title>"` to auto name with the date and time
- Edit the file extension: run `:DraftExt .md` to change the file to markdown
- Open the drafts directory: run `:Drafts`
- Copy the contents of the current draft `:DraftCopy`
- Draft will open a new file in a specific directory, with a unique name
- The file will be based on a template with stuff like the title and datetime
- New draft: run `:Draft` or `:Draft "<Title>"` to auto name with the date and time
- Edit the file extension: run `:DraftExt .md` to change the file to markdown
- Open the drafts directory: run `:Drafts`
- Copy the contents of the current draft `:DraftCopy`
- Draft will open a new file in a specific directory, with a unique name
- The file will be based on a template with stuff like the title and datetime

## Install
#### Vim-Plug
Expand All @@ -82,9 +83,16 @@ nnoremap <Leader>z :call OpenDrafts()<CR>
- Add `ClipDraft()` or `DraftCopy`
- Add `Buffer reload for DraftExt`

#### 0.4 draft.vim - convert features
- Add `ConvertMDToHTML()` for `DraftToHTML`
- Add `ConvertMDToPDF()` for `DraftToPDF`
- Add `ConvertHTMLToPDF` and `ConvertToPDFFromTemplate()` for `DraftToTemplatePDF`
- Add template for html conversion
- Change readme format a little
- Add vimawesome link!

## TODO
- Keybind or function call to copy contents without header to file
- Make a convert to pdf for markdown

## Maybe TODO
- Make a draft file type with metadata and parse out the metadata when opened in vim, then use this data to search for notes better and stuff, like have raw data for python to search better with
24 changes: 22 additions & 2 deletions plugin/draft.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" draft.vim - Quickly writeup and save drafts for messaging apps in your favorite editor
" Authors: Jake Roggenbuck
" Version: 0.3
" Version: 0.4
" License: MIT

if exists('g:loaded_draft_plugin') || &compatible || v:version < 700
Expand All @@ -11,7 +11,6 @@ let g:loaded_draft_plugin = 1

let s:plugin_root_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h')


func! g:OpenDrafts()
execute ":edit" . g:drafts_directory
endfunc
Expand All @@ -29,6 +28,24 @@ func! g:ClipDraft()
execute ':silent !command xclip -sel clip ' . expand('%:p')
endfunc

func! g:ConvertMDToHTML()
:w
execute ':silent !command pandoc --standalone --template ' . s:plugin_root_dir . '/resources/template.html ' . expand('%:p') . ' -o ' . expand('%:p') . '.html --metadata pagetitle="' . expand('%:r') . '"'
endfunc

func! g:ConvertMDToPDF()
:w
execute ':silent !command pandoc ' . expand('%:p') . ' --pdf-engine=wkhtmltopdf --output ' . expand('%:p') . '.pdf'
endfunc

func! g:ConvertHTMLToPDF()
execute ':silent !command wkhtmltopdf ' . expand('%:p') . '.html ' . expand('%:p') . '.pdf'
endfunc

func! g:ConvertToPDFFromTemplate()
call ConvertMDToHTML()
call ConvertHTMLToPDF()
endfunc

func! s:SourcePython()
py3 << EOF
Expand Down Expand Up @@ -77,3 +94,6 @@ command! -bar -bang -nargs=? Draft call NewDraft(<q-args>)
command! -bar -bang -nargs=? DraftExt call ChangeFileExt(<q-args>)
command! -bar -bang DraftCopy call ClipDraft()
command! -bar -bang Drafts call OpenDrafts()
command! -bar -bang DraftToHTML call ConvertMDToHTML()
command! -bar -bang DraftToPDF call ConvertMDToPDF()
command! -bar -bang DraftToTemplatePDF call ConvertToPDFFromTemplate()
23 changes: 23 additions & 0 deletions plugin/resources/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta name="date" content='$date-meta$'>
<meta name="title" content="My Title">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<style>
:root {
--light-background: #ffffff;
--light-text: #121212;
--light-primary: #3498db;
--light-secondary: #52be80;
}
* { font-family: 'Open Sans', sans-serif; }
a { color: var(--light-primary); }
h1 { font-weight: bold; }
</style>
</head>
<body>
$body$
</body>
</html>