從org生成ikiwiki markdown
我的网页仍然在ikiwiki中,但最近开始在org-mode中编写任务和讲座,这样我就可以利用一些文学编程的功能。虽然org-mode内置了导出功能,但它只会将源代码块导出为示例(即未突出显示的verbatim)。我添加了一个自定义导出器,以一种ikiwiki可以理解的方式标记源代码块。幸运的是,这次并不太难 (opens new window)。
(with-eval-after-load "ox-md"
(org-export-define-derived-backend 'ik 'md
:translate-alist '((src-block . ik-src-block))
:menu-entry '(?m 1 ((?i "ikiwiki" ik-export-to-ikiwiki)))))
(defun ik-normalize-language (str)
(cond
((string-equal str "plait") "racket")
((string-equal str "smol") "racket")
(t str)))
(defun ik-src-block (src-block contents info)
"Transcode a SRC-BLOCK element from Org to beamer
CONTENTS is nil. INFO is a plist 用作通信渠道。"
(let* ((body (org-element-property :value src-block))
(lang (ik-normalize-language (org-element-property :language src-block))))
(format "[[!format <span class="error">错误:不支持的页面格式%s</span>]]" lang body)))
(defun ik-export-to-ikiwiki
(&optional async subtreep visible-only body-only ext-plist)
"将当前缓冲区导出为ikiwiki markdown文件。
有关完整文档,请参见org-md-export-to-markdown"
(require 'ox)
(interactive)
(let ((file (org-export-output-file-name ".mdwn" subtreep)))
(org-export-to-file 'ik file
async subtreep visible-only body-only ext-plist)))```