Skip to content

Instantly share code, notes, and snippets.

@gutchom
Last active June 28, 2019 05:57
Show Gist options
  • Save gutchom/d9cfbf77f8818fbb4471c6329fb5898f to your computer and use it in GitHub Desktop.
Save gutchom/d9cfbf77f8818fbb4471c6329fb5898f to your computer and use it in GitHub Desktop.
縦書きのツイート作るよ最上川
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Verticalizer</title>
</head>
<body>
<form>
<textarea id="source" cols="40" rows="16">
縦書きの
ツイート作るよ
最上川
字面合わせに
全角スペースで埋めるので
実字数は増えます</textarea>
<br>
<button id="convert" type="button">縦書きにする</button>
<br>
<output id="result"></output>
</form>
<script>
convert.onclick = e => result.innerHTML = source.value
.split('\n')
.reduce((lines, line) => [...lines, [...line.padEnd(lines.length && lines[lines.length - 1].length, '\u3000')]], [])
.reduceRight((lines, line) => lines.map((char, index) => index < line.length ? char + line[index] : char))
.join('<br>')
.replace(/ー/g, ' | ')
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment