MathJaxのCDNが変更になる。古いページには
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"> </script>
や
<script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"> </script>
や,あるいは1行で
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
のような記述をしたものがたくさんある。これを
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_CHTML"></script>
に書き直したい。そのため,次のようなスクリプト(fix.rb)を用意した:
#! /usr/bin/ruby
# coding: utf-8
ARGV.each do |file|
x = File.open(file, "r") do |f|
f.read
end
y = x.sub(%r|<script (async )?src="https://cdn.mathjax.org/mathjax/latest/MathJax.js\?config=TeX-AMS_CHTML">\n?</script>|m, %q|<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_CHTML"></script>|)
if y != x
File.open(file, "w") do |f|
f.write(y)
end
end
end
これで
./fix.rb *.html
とすれば一斉に書き直しできる。