Skip to content

Commit

Permalink
fix(lyricova): completed inline quote should not be hanged
Browse files Browse the repository at this point in the history
  • Loading branch information
blueset authored Nov 3, 2023
1 parent c4e3ebe commit 23e9aeb
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,29 @@ interface PlainTextHangingPunctProps {
children: string;
}

function shiftinPuncts(line: string, match: RegExpMatchArray | null, start: string, end: string ): RegExpMatchArray | null {
if (match && line.match(new RegExp(`${start}.*${end}`, "g"))) {
const front = match[1].split(start);
const back = match[3].split(end);
match[2] = `${start.repeat(front.length - 1)}${match[2]}${end.repeat(back.length - 1)}`;
match[1] = front.join("");
match[3] = back.join("");
}
return match;
}

export function PlainTextHangingPunct({
children,
}: PlainTextHangingPunctProps) {
const lines = children
.split("\n")
.map((line) => line.match(/^([\p{Ps}\p{Pi}"]*)(.*?)(\p{Po}*)$/u));
.map((line) => {
let match = line.match(/^([\p{Ps}\p{Pi}"]*)(.*?)(\p{Po}*)$/u);
match = shiftinPuncts(line, match, "「", "」");
match = shiftinPuncts(line, match, "『", "』");
match = shiftinPuncts(line, match, "「", "」");
return match;
});
return (
<>
{lines.map((line, idx) => (
Expand Down

0 comments on commit 23e9aeb

Please sign in to comment.