Skip to content

Instantly share code, notes, and snippets.

@ruv
Created March 21, 2019 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruv/68e9aa2ab1097c46215d4e0a81982b8a to your computer and use it in GitHub Desktop.
Save ruv/68e9aa2ab1097c46215d4e0a81982b8a to your computer and use it in GitHub Desktop.
Wrap selected text with common formatting tags
wrap_selection_with = ( tag ) ->
e = atom.workspace.getActiveTextEditor()
m = e.markBufferPosition( e.getCursorBufferPosition() )
s = e.getSelectedBufferRange()
e.setCursorBufferPosition( s.end )
e.insertText('</' + tag + '>')
e.setCursorBufferPosition( s.start )
e.insertText('<' + tag + '>')
e.setCursorBufferPosition( m.getHeadBufferPosition() )
m.destroy()
atom.commands.add 'atom-text-editor', 'html-format:bold', -> wrap_selection_with('b')
atom.commands.add 'atom-text-editor', 'html-format:italic', -> wrap_selection_with('i')
atom.commands.add 'atom-text-editor', 'html-format:strong', -> wrap_selection_with('strong')
atom.commands.add 'atom-text-editor', 'html-format:emphasis', -> wrap_selection_with('em')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment