Skip to content

Commit

Permalink
feat: handle vertical read year month day with spaces in between
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Dec 1, 2024
1 parent 273ea63 commit a40ed5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 14 additions & 7 deletions app/src/main/assets/process_text_nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ function toChineseNumeralForDate(num) {
}

function convertDateToChinese(dateString) {
return convertMonthDayToChinese(convertYearToChinese(dateString));
return convertDayToChinese(convertMonthToChinese(convertYearToChinese(dateString)));
}

function convertMonthDayToChinese(dateString) {
const datePattern = /(\d{1,2})月(\d{1,2})日/g;
return dateString.replace(datePattern, (match, month, day) => {
const chineseMonth = toChineseNumeralForDate(parseInt(month));
function convertDayToChinese(dateString) {
const datePattern = /\s*(\d{1,2})\s*日/g;
return dateString.replace(datePattern, (match, day) => {
const chineseDay = toChineseNumeralForDate(parseInt(day));
return `${chineseMonth}${chineseDay}日`;
return `${chineseDay}日`;
});
}

function convertMonthToChinese(dateString) {
const datePattern = /\s*(\d{1,2})\s*月/g;
return dateString.replace(datePattern, (match, month) => {
const chineseMonth = toChineseNumeralForDate(parseInt(month));
return `${chineseMonth}月`;
});
}

function convertYearToChinese(dateString) {
const datePattern = /(\d{1,4})年/g;
const datePattern = /(\d{1,4})\s*/g;
return dateString.replace(datePattern, (match, year) => {
console.log(year);
const chineseYear = year.split('').map(digit => toChineseNumeral(digit)).join('');
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/assets/verticalReaderview.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

.mozac-readerview-body * {
background-color: #ffffff !important;
line-height: 1.5em !important;
}

/* Override some controls and content styles based on color scheme */
Expand Down Expand Up @@ -267,7 +268,8 @@
display: inline-block;
margin: 0.4em 0.0em !important;
letter-spacing: 0.0em;
text-indent: 0.2em;
text-indent: 0.1em;
font-size: 0.8em;
-moz-transform:rotate(-90deg);
-webkit-transform:rotate(-90deg);
-o-transform:rotate(-90deg);
Expand Down

0 comments on commit a40ed5b

Please sign in to comment.