Skip to content

Instantly share code, notes, and snippets.

@To1ne
Forked from anonymous/markup-emacs.rb
Created September 27, 2010 09:41
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 To1ne/598810 to your computer and use it in GitHub Desktop.
Save To1ne/598810 to your computer and use it in GitHub Desktop.
#
# A little function to add html markup around emacs commands found in text.
#
def markup_emacs(text)
# defuns are put between () # TODO nested defuns
text.gsub!(/(\([^\)]+\))/, '<code>\1</code>')
# keyboard strokes
# -> M-x some-defun
# -> and other combo's
key = '(?:&lt;[^&]+&gt;|\w\b|[^\s\w])'
stroke = "(?:[CMSs]-)+#{key}"
text.gsub!(/\b(M-x \S+|#{stroke}(?: (?:#{stroke}|#{key}))*)/, '<kbd>\1</kbd>')
text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment