LoginSignup
1
1

More than 5 years have passed since last update.

タグの入れ子内にある<script>がmarkedで変換すると実行されないのを回避する方法

Last updated at Posted at 2016-01-25

マークダウンファイル中の以下のような記述をmarked.jsで変換すると・・・

<div>
  <script>alert('bar');</script>
</div>

エスケープされてしまいJavaScriptが実行されない。

<div>
  <script>alert(&#39;bar&#39;);</script>
</div>

タグの入れ子だとダメで以下のように書けば実行される。

<script>alert('bar');</script>

以下のようにソースをいじることで入れ子内の<script>でも実行できるようになる。
https://github.com/chjj/marked/blob/88ce4df47c4d994dc1b1df1477a21fb893e11ddc/lib/marked.js#L364

pre: !this.options.sanitizer,
//↓コメントアウト
// && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
1
1
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
1
1