Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode - wrap selected text in "<mark></mark>"

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?

like image 302
Ben Avatar asked Mar 11 '26 17:03

Ben


1 Answers

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>

enter image description here

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)

like image 153
Jason Avatar answered Mar 14 '26 13:03

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!