Vscode-markdown: Usage of styleByWrapping for inserting Hex-Codes

Created on 24 Apr 2020  ·  16Comments  ·  Source: yzhang-gh/vscode-markdown

Hi there,

thanks for the great package!
I wonder how to write a user defined keymapping that makes use of your "styleByWrapping"-function like the integrated "markdown.extension.editing.toggleBold".

I seek to habe a short cut likae CTRL-Shift-A that takes the selected texts and adds/removes the "right" quotation marks: e.g. „TEXT“

Cheers

Needs TagFix

All 16 comments

Thank you.

However, I am afraid it is not possible to call styleByWrapping outside the extension as it is a internal function.

A solution is to use VSCode's snippets although you will need two shortcuts for add and remove respectively.
https://code.visualstudio.com/docs/editor/userdefinedsnippets.
e.g. "${TM_SELECTED_TEXT/[„“]//g}" for removing quotations.

Thank you @yzhang-gh for your fast reply.
I try to get this running with the variable.

I thought I could be possible to make the styleByWrapping public, if the function would allow for at max two arguments "before" and "after"

This is how to use your toogle Bold in keybinding

{
    "key": "ctrl+shift+a",
    "command": "markdown.extension.editing.toggleBold"
},

Working example (@yzhang-gh 2020-10-17):

{
    "key": "ctrl+shift+a",
    "command": "markdown.extension.editing._wrapBy"
    "args": {
        "before": "„",
        "after": "“"
    }
},

I thought I could be possible to make the styleByWrapping public

Yes, just register it with VSCode like

https://github.com/yzhang-gh/vscode-markdown/blob/67fcde982a423dc990b5a5ccfba4f5f233a0ed56/src/formatting.ts#L12

However, are you editing Hex-codes in Markdown files? This extension is only activated for Markdown documents.

@yzhang-gh Indeed, however I am in favor of a solution that only uses simple user defined changes in VSC since I wonder that an update of your extension would break the hack.

I'm writing rmd-Documents with output-formats bookdown, word and powerpoint. Sometimes special characters are needed. Inserting and reverting "the right" quotation marks would come in very handy.

I mean if we add commands.registerCommand('markdown.extension.editing._wrapBy', (before, after) => styleByWrapping(before, after)) (i.e. expose the function), your idea in https://github.com/yzhang-gh/vscode-markdown/issues/663#issuecomment-619343974 will work.

@yzhang-gh That would be pretty cool! I think that would fit perfectly.

Would you mind opening a PR? You don't even need to run it locally. The CI will generate a .vsix and you can then download it for testing.

@yzhang-gh I tried to to that with github desktop

Authentication failed. You may not have permission to access the repository or the repository may have been archived. Open options and verify that you're signed in with an account that has permission to access this repository.

I gonna try it now here online and check back

@yzhang-gh I now used VSC and checked out to the "debug" branch and pulled the new line in the formatting.ts file.

Oh, the debug branch is different. Alright, let me do it for you.

It should be fixed in the dev build. Be sure to use the correct command/args names.

@yzhang-gh Sorry for the circumstances. Working with PR is quite new for me (but you've probably guessed that already, lol).

@yzhang-gh I installed from VSIX and used the keymapping as proposed.

{
    "key": "ctrl+shift+a", 
    "command": "markdown.extension.editing._wrapBy",
    "args": {
        "before": "„",
        "after": "&lddquo;"
    }    
},

The result is

test + shortcut = [object Object]test[object Object]

the function does not take the arguments.

I've checked it. It turned out that the args was not unpacked so before received

{
    "before": "„",
    "after": "&lddquo;"
}

Should be okay now.

Hi @yzhang-gh ,
thank you very much - it works like a charm!

Cheers

Was this page helpful?
0 / 5 - 0 ratings