Skip to content

Instantly share code, notes, and snippets.

@kuanyui
Last active August 29, 2015 14:01
Show Gist options
  • Save kuanyui/9025e45c04cdd9f1f736 to your computer and use it in GitHub Desktop.
Save kuanyui/9025e45c04cdd9f1f736 to your computer and use it in GitHub Desktop.
;; This .el file provide syntax highlighting for ruby tags in Emacs's markdown-mode
(defface markdown-ruby-mark '((((class color) (background light)) (:foreground "#fff" :background "#6c0099"))
(((class color) (background dark)) (:foreground "#6c0099" :background "#d187ff"))) "" :group 'faces)
(defface markdown-ruby-title '((((class color) (background light)) (:foreground "#6c0099"))
(((class color) (background dark)) (:foreground "#d187ff"))) "" :group 'faces)
(defface markdown-ruby-content '((((class color) (background light)) (:foreground "#d187ff"))
(((class color) (background dark)) (:foreground "#8700af"))) "" :group 'faces)
(font-lock-add-keywords 'markdown-mode
'(("\{\\(rb\\)\|.+?\|.+?\}" 1 'markdown-ruby-mark)
("\{rb\|\\(.+?\\)\|.+?\}" 1 'markdown-ruby-title)
("\{rb\|.+?\|\\(.+?\\)\}" 1 'markdown-ruby-content)))
(provide 'markdown-ruby)
/*
ruby.js: A filter for Hexo to generate ruby chracters(ルビ). Place this file in /scripts/ruby.js.
========================================================================
Author: kuanyui(azazabc123[at]g~~~m~~~a~~~i~~~l[dot]com)
Date: 20140518
License: WTFPL 1.0
========================================================================
The string in article:
{rb|機巧少女|machine doll}
Will be converted to:
<ruby><rb>機巧少女</rb><rp>[</rp><rt>machine doll</rt><rp>]</rp></ruby>
*/
hexo.extend.filter.register('post', function(data, callback) {
var reRb = new RegExp('\\{rb\\|(.+?)\\|(.+?)\\}', 'g');
data.content = data.content.replace(reRb, '<ruby><rb>$1</rb><rp>[</rp><rt>$2</rt><rp>]</rp></ruby>');
callback(null, data);
});
@Yoxem
Copy link

Yoxem commented May 19, 2014

Thanks! The image of test result is at the following link.
多謝!測試結果如圖:https://pbs.twimg.com/media/Bn9n5aHIgAAAHkJ.png:large

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment