From a40ed5b24875fc6c3e159bc0d66a2ad5375f9890 Mon Sep 17 00:00:00 2001 From: Daniel Kao Date: Sun, 1 Dec 2024 20:36:00 +0800 Subject: [PATCH] feat: handle vertical read year month day with spaces in between --- app/src/main/assets/process_text_nodes.js | 21 ++++++++++++++------- app/src/main/assets/verticalReaderview.css | 4 +++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/assets/process_text_nodes.js b/app/src/main/assets/process_text_nodes.js index 247e7def..d8a0e6e0 100644 --- a/app/src/main/assets/process_text_nodes.js +++ b/app/src/main/assets/process_text_nodes.js @@ -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(''); diff --git a/app/src/main/assets/verticalReaderview.css b/app/src/main/assets/verticalReaderview.css index 1ad678ad..6a635c34 100644 --- a/app/src/main/assets/verticalReaderview.css +++ b/app/src/main/assets/verticalReaderview.css @@ -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 */ @@ -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);