Skip to content

Instantly share code, notes, and snippets.

@jkap
Created June 6, 2016 17:11
Show Gist options
  • Save jkap/c3eea696e0a68b03bd9c7e8ec93c223f to your computer and use it in GitHub Desktop.
Save jkap/c3eea696e0a68b03bd9c7e8ec93c223f to your computer and use it in GitHub Desktop.
put this in a drafts action to replace yr draft with its full-width equivalent
function fullWidth(input) {
var
dict = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}",
offset = 65281,
out = "",
n,
letter,
codePoints = [],
index;
for (n = 0; n < input.length; n++) {
letter = input.charAt(n)
if (letter === " ") {
letter = 0x3000;
} else {
index = dict.indexOf(letter)
if (index !== -1) {
letter = offset + index;
} else {
letter = input.charCodeAt(n);
}
}
codePoints.push(letter)
}
out = String.fromCharCode.apply(String, codePoints);
return out
}
draft.content = fullWidth(draft.content);
commit(draft);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment