Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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() )
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
You can’t perform that action at this time.