-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace punctuation glyphs with vertical punctuation glyphs in vertic…
…al writing mode
- Loading branch information
Lucas Wojciechowski
committed
Nov 9, 2016
1 parent
0f74511
commit d560a43
Showing
7 changed files
with
89 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
const scriptDetection = require('./script_detection'); | ||
|
||
module.exports = function verticalizePunctuation(input) { | ||
let output = ''; | ||
|
||
for (let i = 0; i < input.length; i++) { | ||
const charCode = input.charCodeAt(i); | ||
const nextCharCode = input.charCodeAt(i + 1) || null; | ||
const prevCharCode = input.charCodeAt(i - 1) || null; | ||
|
||
const canReplacePunctuation = ( | ||
(!nextCharCode || scriptDetection.charAllowsVerticalWritingMode(nextCharCode, true)) && | ||
(!prevCharCode || scriptDetection.charAllowsVerticalWritingMode(prevCharCode, true)) | ||
); | ||
|
||
if (canReplacePunctuation && lookup[input[i]]) { | ||
output += lookup[input[i]]; | ||
} else { | ||
output += input[i]; | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
const lookup = module.exports.lookup = { | ||
'。': '︒', | ||
'—': '︱', | ||
'–': '︲', | ||
'_': '︳', | ||
'(': '︵', | ||
')': '︶', | ||
'{': '︷', | ||
'}': '︸', | ||
'〔': '︹', | ||
'〕': '︺', | ||
'〘': '︹', | ||
'〙': '︺', | ||
'【': '︻', | ||
'】': '︼', | ||
'《': '︽', | ||
'》': '︾', | ||
'〈': '︿', | ||
'〉': '﹀', | ||
'「': '﹁', | ||
'」': '﹂', | ||
'『': '﹃', | ||
'』': '﹄', | ||
'「': '﹁', | ||
'」': '﹂', | ||
'[': '﹇', | ||
']': '﹈', | ||
'“': '﹁', | ||
'”': '﹂', | ||
'‘': '﹃', | ||
'’': '﹄', | ||
'.': '・' | ||
}; |
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