Created
February 22, 2016 15:02
-
-
Save ikait/41b43cb15ae8d2169605 to your computer and use it in GitHub Desktop.
全角/半角約物処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MK = "{[「『(⦅〈《〔〘【〖"; | |
var AK = "}]」』)⦆〉》〕〙】〗"; | |
var KT = "、,。."; | |
var regexpMK = new RegExp("(.{1})([" + MK + "])", "g"); | |
var regexpAK = new RegExp("([" + AK + "])(.{1})", "g"); | |
var regexpKT = new RegExp("[" + KT + "]", "g"); | |
document.addEventListener("DOMContentLoaded", function () { | |
var body = document.getElementsByTagName("body")[0]; | |
Array.prototype.forEach.call(body.children, function (child) { | |
if (child.tagName.toLowerCase() === "script") { | |
return | |
} | |
child.innerHTML = child.innerHTML.replace(regexpMK, "<span style=\"letter-spacing: -0.5em;\">$1</span> $2"); | |
child.innerHTML = child.innerHTML.replace(regexpAK, "<span style=\"letter-spacing: -0.5em;\">$1</span> $2"); | |
child.innerHTML = child.innerHTML.replace(regexpKT, function (_1) { | |
if (_1 === "。") return "。 "; | |
else if (_1 === "、") return "、 "; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment