= 第1部 = == 章1 == === 節1 === ===節2=== ==== 項1==== ==== 項2 ==== ===== 目1 ===== ===== 目2 ===== ====== 条1 ====== ====== 条2 ====== ==== 項3 ==== ===== 目1 ===== ====== 条1 ====== ====== 条2 ====== ===== 目2 ===== == 章2 == = 第2部 =という文書を、
* 第1部 ** 章1 *** 節1 *** 節2 **** 項1 **** 項2 ***** 目1 ***** 目2 ****** 条1 ****** 条2 **** 項3 ***** 目1 ****** 条1 ****** 条2 ***** 目2 ** 章2 * 第2部という文書に変換する。
(require 'cl)
(setq aka:transformation-table-1
'(("^=\\( *\\)\\([^ =].*[^ =]\\)\\( *\\)= *$" . "* \\2")
("^==\\( *\\)\\([^ =].*[^ =]\\)\\( *\\)== *$" . "** \\2")
("^===\\( *\\)\\([^ =].*[^ =]\\)\\( *\\)=== *$" . "*** \\2")
("^====\\( *\\)\\([^ =].*[^ =]\\)\\( *\\)==== *$" . "**** \\2")
("^=====\\( *\\)\\([^ =].*[^ =]\\)\\( *\\)===== *$" . "***** \\2")
("^======\\( *\\)\\([^ =].*[^ =]\\)\\( *\\)====== *$" . "****** \\2")))
(defun aka:transform-headings (match-pattern print-format)
"Transform a kind of headings"
(interactive)
(save-excursion
(save-restriction
(save-match-data
(widen)
(goto-char (point-min))
(while (search-forward-regexp match-pattern (point-max) t)
(replace-match print-format t nil))
)))
nil)
(defun aka:transform-all-headings ()
"Transform all headings"
(interactive)
(mapcar #'(lambda (rule)
(aka:transform-headings (car rule)
(cdr rule)))
aka:transformation-table-1))