LoginSignup
5
0

More than 5 years have passed since last update.

html-pipeline で HTML タグのエスケープ処理をしない

Posted at

html-pipeline を使ってマークダウンを変換したり、任意のテキスト処理をしたりしますが、デフォルトで組み込まれている HTML::Pipeline::MarkdownFilter<script><iframe> などのタグをエスケープ処理するようになっています。

より正確に言うと HTML::Pipeline::MarkdownFilter の内部で使っている CommonMarkertagfilter オプションで処理されています。

html-pipeline version 2.7 未満はデフォルトで指定されていましたが、それ以降はオプションを上書きできるようになりました。

こんな感じで tagfilter 以外のオプションを指定してあげると、 <script><iframe> を使うことができます。当然、悪意のあるコードが実行されてしまうので気をつけてください。

module Markdown
  class Processor
    def call(input)
      filters = [
        HTML::Pipeline::MarkdownFilter
      ]
      context = {
        commonmarker_extensions: %i[table strikethrough autolink]
      }
      HTML::Pipeline.new(filters, context).call(input)
    end
  end
end
5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0