VSCode - wrap selected text in “<mark></mark>”

大城市里の小女人 提交于 2021-02-04 19:37:22

问题


I'm using the markdown previewer in VSCode and would like the ability to highlight some text in an ".md" file and wrap it in a "<mark></mark>" tag so that it displays highlighted when you view the markdown file in its rendered format.

Is there a quick and easy way to do this?


回答1:


A snippet should do the trick.

"wrap_mark": {
    "prefix": "wrap_mark",
    "body": [
        "<mark>$TM_SELECTED_TEXT</mark>"
    ],
    "description": "Wrap selected with <mark>"
},

Add that to your snippets/markdown.json file.

Then, add the following to your keybindings.json file

{ "key": "cmd+e 1", 
    "command": "editor.action.insertSnippet", 
    "args": { "name": "wrap_mark" } 
},

Now, in your markdown file you can highlight the text and hit cmd + e then 1 and the highlighted text gets wrapped in <mark>

I have a series of snippets mapped to cmd + e + "" - you can use any key combo you want (I'm on a Mac so I use the cmd key)




回答2:


In your user settings, add:

"emmet.excludeLanguages": [ ],
"emmet.includeLanguages": {"markdown": "html"},

This enables emmet in markdown files.

Then in the markdown file, use the Emmet: Wrap with abbreviation command:

You can also create a snippet that does this specifically for <mark/>. Take a look at the TM_SELECTED_TEXT snippet variable



来源:https://stackoverflow.com/questions/49192210/vscode-wrap-selected-text-in-mark-mark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!