发博文
个人资料
  • 博客访问:1242858
  • 博文数量:422
  • 博客积分:10102
  • 博客等级:上将
  • 关注人气: 1
  • 注册时间:2005-07-04 20:28:15
订阅我的博客
  • 订阅
  • 订阅到鲜果
  • 订阅到抓虾
  • 订阅到Google
字体大小: 博文
分类: emacs怪兽

code

使用source-highlight在Muse中高亮代码

在你的.emacs中加入下列代码

;; add a <source> tag, which use source-highlight
(defun muse-publish-source-tag (beg end attrs)
(let ((lang (cdr (assoc "lang" attrs)))
(style (muse-style-element :base))
hcodes)
(if (string-equal style "pdf") (setq style "latex"))
(if lang
(progn
(muse-publish-command-tag
beg end
(cons (cons "interp" (format "echo \"<literal><pre class=\"example\">
$(source-highlight -s %s -f %s)
</pre></literal>\"" lang style))
attrs))
(muse-publish-mark-read-only beg (point)))
(error "No lang attribute specified in <source> tag"))))

(add-to-list
'muse-publish-markup-tags '("source" t t nil muse-publish-source-tag))

然后即可在你的muse文件中高亮代码了


#include <stdlib.h>

const char so_interp[] __attribute__((section(".interp")))
= "/lib/ld-linux.so.2";

int soso(int i){
return i*i;
}

void so_start(void){
int argc;
__asm__ (
"movl 0x14(%%esp), %%eax\n"
: "=a" (argc));
exit(argc);hcodes))
}

上面效果的muse源文件:

* 使用source-highlight在Muse中高亮代码

** 在你的.emacs中加入下列代码
<example>
;; add a <source> tag, which use source-highlight
(defun muse-publish-source-tag (beg end attrs)
(let ((lang (cdr (assoc "lang" attrs)))
(style (muse-style-element :base))
hcodes)
(if (string-equal style "pdf") (setq style "latex"))
(if lang
(progn
(muse-publish-command-tag
beg end
(cons (cons "interp" (format "echo \"<literal><pre class=\"example\">
$(source-highlight -s %s -f %s)
</pre></literal>\"" lang style))
attrs))
(muse-publish-mark-read-only beg (point)))
(error "No lang attribute specified in <source> tag"))))

(add-to-list
'muse-publish-markup-tags '("source" t t nil muse-publish-source-tag))
</example>

** 然后即可在你的muse文件中高亮代码了
<source lang="c">
#include <stdlib.h>

const char so_interp[] __attribute__((section(".interp")))
= "/lib/ld-linux.so.2";

int soso(int i){
return i*i;
}

void so_start(void){
int argc;
__asm__ (
"movl 0x14(%%esp), %%eax\n"
: "=a" (argc));
exit(argc);hcodes))
}
</source>




我的更多文章
亲,您还没有登录,请[登录][注册]后再进行评论