Created
March 21, 2019 02:20
-
-
Save ruv/68e9aa2ab1097c46215d4e0a81982b8a to your computer and use it in GitHub Desktop.
Wrap selected text with common formatting tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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