2019年10月4日金曜日

svg.el

 dom.elがあるならもしかしてsvg.elも……、と思ったら。

(require 'svg)
svg

 ——あった。
 というか、Emacsでsvgを表示できるとは。知らなかった。ビルドのオプション次第らしいけれど。

 しかもshr.elの

shr-insert-document is an autoloaded Lisp function in ‘shr.el’.

(shr-insert-document DOM)

Render the parsed document DOM into the current buffer.
DOM should be a parse tree as generated by
‘libxml-parse-html-region’ or similar.

 を使ってバッファに流しこめるじゃないか。image-modeを使って表示するだけではなく。

 そのうえ、昔は「libxml-parse-html-region」「libxml-parse-xml-region」でlistにしたものを元にhtmlやxmlに戻す関数は見当たらなかったのだけど。
 svg.elの中にまさにそのような関数があった。

svg-print is a compiled Lisp function in ‘svg.el’.

(svg-print DOM)

Convert DOM into a string containing the xml representation.

 いや、Emacs最高。