Emacs

EmacsでHTMLの特殊文字(<、>、&)を文字参照に置換する

更新日:

HTMLの特殊文字(<、>、&)を文字参照に置換する

Emacsで<、>、&などのHTMLの特殊文字を文字参照へと置換するにはsgml-quoteコマンドが使えます。 置換したい範囲を選択した後、次のようにコマンドを実行します。

M-x sgml-quote

sgml-quoteコマンドのドキュメントを見てみる

Emacsでsgml-quoteコマンドのドキュメントを見てみます。

sgml-quote is an interactive compiled Lisp function in ‘sgml-mode.el’.

(sgml-quote START END &optional UNQUOTEP)

Quote SGML text in region START ... END.
Only &, <, >, ’ and " characters are quoted, the rest is left
untouched.  This is sufficient to use quoted text as SGML argument.

With prefix argument UNQUOTEP, unquote the region.  All numeric entities,
"amp", "lt", "gt" and "quot" named entities are unquoted.
    

ドキュメントによると変換される特殊文字は「&、<、>、'、"」の5つの文字だけです。ほかは何を言っているのかよくわかりませんでしたが、次のように前置引数を指定してコマンドを実行すると、元の文字へ戻せるようです。

C-u M-x sgml-quote

以上、特殊文字の変換方法でした。

-Emacs

Copyright© アナグマのモノローグ , 2024 All Rights Reserved Powered by STINGER.