SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents
https://www.vim.org/scripts/script.php?script_id=5620
MIT License
482 stars 13 forks source link

if reset the bold/italic/strike tokens, can't toggle it. #123

Closed Delayless closed 4 years ago

Delayless commented 4 years ago

OS type:

Vim:

As the title, let g:mkdx#settings = { 'tokens': { 'strike': '~~' } }, then I can strike the word with '~~', but can't unstrike it. Bold/Italic as the same.

SidOfc commented 4 years ago

That also definitely looks like a bug, will look into it, cheers again for reporting :+1:

SidOfc commented 4 years ago

Hello again @Delayless

I noticed an issue as well when customizing strike to ~~ but I could not reproduce the issue for bold and italic, these were my customizations:

let g:mkdx#settings = { 'tokens': { 'strike': '~~', 'bold': '__', 'italic': '_' } }

At the moment the wrapping is based on syntax highlighting, the tokens I used are the "alternatives" to what mkdx has set as default, which are:

" strike will use a HTML strike tag when empty
let g:mkdx#settings = { 'tokens': { 'strike': '', 'bold': '**', 'italic': '*' } }

Can you share what other tokens you used for bold and italic? Until that time I've fixed the strike issue at least.

Delayless commented 4 years ago

Hello again @Delayless

I noticed an issue as well when customizing strike to ~~ but I could not reproduce the issue for bold and italic, these were my customizations:

let g:mkdx#settings = { 'tokens': { 'strike': '~~', 'bold': '__', 'italic': '_' } }

At the moment the wrapping is based on syntax highlighting, the tokens I used are the "alternatives" to what mkdx has set as default, which are:

" strike will use a HTML strike tag when empty
let g:mkdx#settings = { 'tokens': { 'strike': '', 'bold': '**', 'italic': '*' } }

Can you share what other tokens you used for bold and italic? Until that time I've fixed the strike issue at least.

init.minimal.vim

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
syntax enable
set nocompatible
filetype on
filetype plugin indent on
set encoding=UTF-8

set autoindent
set nofoldenable
set foldmethod=manual

call plug#begin('~/.vim/plugged')
Plug 'SidOfc/mkdx'
call plug#end()

" ===
" === mkdx
" ===
" auto_update has BUG.
" so must disable it, as long as use the toc related settings.(:source $MYVIMRC)
" BUG2
" let g:mkdx#settings = { 'tokens'    : { 'strike': '~~' } }
set conceallevel=2
let g:tex_conceal='abdmg'
let g:mkdx#settings = { 'highlight' : { 'enable': 1 },
                      \  'tokens'    : { 'strike': '~~' },
                      \ 'enter'     : { 'enable': 1, 'o': 0 },
                      \ 'checkbox'  : { 'toggles': [' ', 'o', 'x'] } ,
                      \ 'map'       : { 'enable': 1, 'prefix': ','},
                      \ 'tab'       : { 'enable': 1 },
                      \ 'links'     : { 'external': { 'enable': 1 } },
                      \ 'image_extension_pattern': 'a\?png\|jpe\?g\|gif',
                      \ 'fold'      : { 'enable': 0, 'components': ['fence', 'toc']},
                      \ 'auto_update': { 'enable': 0 },
                      \ 'toc': { 'details': { 'summary': 'Click to expand {{toc.text}}' }} }
let g:mkdx#settings.gf_on_steroids = 1
let g:mkdx#settings.restore_visual = 0
autocmd FileType markdown nmap <CR> <Plug>(mkdx-jump-to-header)

Use minimal vimrc to open test.md nvim -u init.mininal.vim test.md This BUG can still be reproduced. but I haven't updated today's update yet.

SidOfc commented 4 years ago

Hello @Delayless,

After updating mkdx you should be able to toggle strike when using ~~, but you haven't given me the tokens you use for bold / italic so I can't investigate what's wrong with those yet. I think I'm also seeing the issue you're describing with auto_update, it seems to update the table of contents after re-sourcing the vimrc, will check that out :+1:

SidOfc commented 4 years ago

So I just pushed a commit which does not update the TOC style if it stays the same although I'm not sure if that is the real issue. If I patched something unrelated, could you be more specific about what the issue is you're facing with auto update?

Cheers for the feedback so far too :)

Delayless commented 4 years ago

Hello @Delayless,

After updating mkdx you should be able to toggle strike when using ~~, but you haven't given me the tokens you use for bold / italic so I can't investigate what's wrong with those yet. I think I'm also seeing the issue you're describing with auto_update, it seems to update the table of contents after re-sourcing the vimrc, will check that out 👍

Awesome. Thank you! Now it is normal after adding the option \ 'tokens': { 'strike': '~~', 'bold': '**', 'italic': '*' }. I personally think it would be better if the plugin automatically use the default values when I don't specify the parameters.

For another issue, when I press shift+r(be mapped to :source MYVIMRC), the mkdx will delete the previous two lines if my markdown file is just a list for TODO without titile(# title). I later found out that it's because the mkdx automatically insert a TOC at the current cursor position.

SidOfc commented 4 years ago

I see how that could happen indeed, I don't think I thought about markdown files which were just used as TODO lists when building the feature, will look into that soon too :+1:

About you thinking it would be better if the plugin automatically uses the default values, what do you mean exactly? You should not have to supply all the settings but rather, only the ones you want to override, mkdx should merge your settings into the defaults recursively. e.g. to override only the strike option in tokens, you can specify just { 'strike': '~~' } since the default values for 'bold' and 'italic' are '**' and '*' already.

Delayless commented 4 years ago

I got it. I just need to add \ ‘tokens’: { ‘strike’: ‘~~’} instead of \ 'tokens': { 'strike': '~~', 'bold': '**', 'italic': '*' }. Thanks, Let’s hope mkdx becomes perfect😊.

SidOfc commented 4 years ago

I did some more testing today and noticed that I don't see the lines being removed anymore, I think my last patch also addressed that but I'm not sure, do you still have the issue after having fully updated mkdx @Delayless?

Delayless commented 4 years ago

I said before that mkdx had problems before you updated it. Now it’s normal, awesome. I re-described it in detail to help you locate the real problem maybe.

So I just pushed a commit which does not update the TOC style if it stays the same although I'm not sure if that is the real issue.

Actually, this commit has solved it. Now no other problems have been found. The mkdx is very nice. Thank you!

SidOfc commented 4 years ago

Ahh glad to hear, always nice to get two for one :)

The real issue is not actually with auto update itself I've noticed, but seems to be related to it in the sense that updating for example toc.text or toc.details would also cause an update to toc.details.enabled. When this setting is changed, the TOC is removed and re-added in the new style (normal markdown vs html markup).

This is what caused the lines to be removed, because there was no TOC to update, but the setting was "updated" internally so mkdx tried to remove the old TOC (which wasn't there) and insert an updated one.

The fix I've applied may not be sufficient as all it does is check if the old value equals the new one, and only updates the TOC when it differs from its old setting. This means that some edge case(s) could still exist.

For now I'll close this since it has already fixed more than the described issue mentions, cheers for the feedback @Delayless, mkdx only improves because of users like you finding and reporting bugs :+1: