Skip to content

Commit

Permalink
Add english support as title level 5.
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
MrOrz committed Jul 15, 2015
1 parent bc83b7f commit 3102f07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/lineMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {parseZHNumber} from 'zhutil';
import Section from './section';

const TITLE_NUMBER_HIERARCHY = [
/^([〇零壹貳參叄肆伍陸柒捌玖拾佰仟]+)\s?[、,\.,]/, // level 0
/^([〇零一兩二三四五六七八九十百千]+)\s?[、,\.,]/, // level 1
/^[((]\s?([〇零一兩二三四五六七八九十百千]+)\s?[))]/, // level 2
/^(\d+|[0123456789]+)\s?[、,\.,]/, // level 3
/^[((]\s?(\d+|[0123456789]+)\s?[))]/, // level 4
/^([甲乙丙丁戊己庚辛壬癸])\s?[、,\.,]/, // level 5
/^([〇零壹貳參叄肆伍陸柒捌玖拾佰仟]+)\s?[、,\.,]/, // level 0
/^([〇零一兩二三四五六七八九十百千]+)\s?[、,\.,]/, // level 1
/^[((]\s?([〇零一兩二三四五六七八九十百千]+)\s?[))]/, // level 2
/^(\d+|[0-9]+)\s?[、,\.,]/, // level 3
/^[((]\s?(\d+|[0-9]+)\s?[))]/, // level 4
/^([甲乙丙丁戊己庚辛壬癸a-za-zA-ZA-Z])\s?[、,\.,]/,// level 5
],
HIERARCHY_NAMES = [
'%s、', '%s、', '(%s)', '%s、', '(%s)', '%s、'
Expand Down Expand Up @@ -204,8 +204,14 @@ class LineMachine {
}
}
} else {
// 甲乙丙丁
number = HEAVENSTEM_NUMBER_MAP[input];
// 甲乙丙丁 or ABCD or full-width ABCD
if (input.match(/[a-zA-Z]/)) {
number = input.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) + 1;
} else if (input.match(/[a-zA-Z]/)) {
number = input.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) + 1;
} else {
number = HEAVENSTEM_NUMBER_MAP[input];
}
}

if (isNaN(number)) {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/lineMachineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe('LineMachine', () => {
'(十一) 標題': {level: 2, numberCH: '十一', number: 11, text: '標題'},
'31、415': {level: 3, numberCH: '31', number: 31, text: '415'},
'(21) 34': {level: 4, numberCH: '21', number: 21, text: '34'},
'甲、乙': {level: 5, numberCH: '甲', number: 1, text: '乙'}
'甲、乙': {level: 5, numberCH: '甲', number: 1, text: '乙'},
'A.apple': {level: 5, numberCH: 'A', number: 1, text: 'apple'},
'a.apple': {level: 5, numberCH: 'a', number: 1, text: 'apple'},
};

Object.keys(testMap).forEach(test => {
Expand Down

0 comments on commit 3102f07

Please sign in to comment.