-
-
Save To1ne/598810 to your computer and use it in GitHub Desktop.
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
# | |
# 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 = '(?:<[^&]+>|\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