Skip to content

Commit

Permalink
fixed multiple instances of the same symbol within italics text not w…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
ndepaola committed Jan 29, 2022
1 parent d1c1ed7 commit bd5d409
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/format_text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function locate_symbols(input_string) {
}
}

function escape_regex(value) {
/**
* Borrowed from https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression
*/

return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}

function locate_italics(input_string, italics_strings) {
/**
* Locate all instances of italic strings in the input string and record their start and end indices.
Expand All @@ -57,7 +65,8 @@ function locate_italics(input_string, italics_strings) {
// replace symbols with their character representations in the italic string
if (italics.indexOf("}") >= 0) {
for (var symbol in symbols) {
italics = italics.replace(symbol, symbols[symbol]);
var re = new RegExp(escape_regex(symbol), "g");
italics = italics.replace(re, symbols[symbol]);
}
}

Expand Down

1 comment on commit bd5d409

@Investigamer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks buddy great work and fast response!

Please sign in to comment.