Skip to content

Commit

Permalink
fix: prevent digits to rotate twice
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Nov 30, 2024
1 parent 20cb9ed commit 2f6bad8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app/src/main/assets/process_text_nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ function convertToVerticalStyle(node) {
const fragment = document.createDocumentFragment();

while ((match = regex.exec(text)) !== null) {
let matchedText = match[0];
// exclude english words longer than 2 characters, e.g. "Hello" but keep a. b. c.
if (match[0].length > 1 && isLetter(match[0][0]) && isLetter(match[0][1])) { continue }
if (matchedText.length > 4 && isLetter(matchedText[0]) && isLetter(matchedText[1])) { continue }

// digits longer than 3 characters , e.g. 12345, keep 2024 similar year numbers
if (match[0].length >= 3) {
if (match[0][1] != '.') {
console.log("matchedText.length >= 3");
console.log(matchedText);
if (matchedText[1] != '.') {
if (lastIndex < match.index) {
fragment.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
}

// Create span element for the matched part
const span = document.createElement('span');
span.className = 'verticalSingleChr';
span.textContent = match[0];
span.textContent = matchedText;
fragment.appendChild(span);

lastIndex = regex.lastIndex;
Expand All @@ -33,11 +36,19 @@ function convertToVerticalStyle(node) {
fragment.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
}

// Create span element for the matched part
const span = document.createElement('span');
span.className = 'vertical';
span.textContent = match[0];
fragment.appendChild(span);
// prevent duplicate vertical text
const parentNode = node.parentNode;
const isAlreadyWrapped = parentNode && parentNode.classList && parentNode.classList.contains('vertical');

if (!isAlreadyWrapped) {
// Create span element for the matched part
const span = document.createElement('span');
span.className = 'vertical';
span.textContent = matchedText;
fragment.appendChild(span);
} else {
fragment.appendChild(document.createTextNode(match[0]));
}

lastIndex = regex.lastIndex;
}
Expand Down

0 comments on commit 2f6bad8

Please sign in to comment.