Skip to content

Commit

Permalink
add escape
Browse files Browse the repository at this point in the history
Signed-off-by: ふぁ <yuki@yuki0311.com>
  • Loading branch information
fa0311 committed Nov 12, 2022
1 parent e43b6a3 commit 4c6b087
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ window.addEventListener("load", (e) => {
)
).map((value) =>
attention(
value.getAttribute("data-tag-name")!,
escape(value.getAttribute("data-tag-name")!),
parseFloat(value.querySelector(attentionSpanQuery)?.innerHTML ?? "1.0")
)
);
Expand All @@ -135,7 +135,15 @@ window.addEventListener("load", (e) => {
const attention = (word: string, factor: number): string => {
if (factor == 1) return word;
if (factor == 1.1) return "(" + word + ")";
return "(word:" + factor.toFixed(1) + ")";
return "(" + word + ":" + factor.toFixed(1) + ")";
};

const escape = (word: string): string => {
return word
.replace("(", "\\(")
.replace(")", "\\)")
.replace("[", "\\[")
.replace("]", "\\]");
};

const sort = (value: Element[]): Element[] => {
Expand Down

0 comments on commit 4c6b087

Please sign in to comment.