Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2010 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/596225 to your computer and use it in GitHub Desktop.
Save anonymous/596225 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