Skip to content

Commit

Permalink
Autopunctuation improvements: Now with correctly-handled chat markdow…
Browse files Browse the repository at this point in the history
…n! (#378)

* Autopunctuation regex fix

* Add unflavored markdown EOL checking to autopunctuation

* Combine has_no_eol_punctuation and ends_in_unflavored_markdown for less findtext() calls

* Remove unused autopunctuation regex globals and simplify pattern
  • Loading branch information
Ephemeralis authored and FFMirrorBot committed Jan 12, 2024
1 parent a860ef5 commit fcc5947
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions modular_nova/master_files/code/_globalvars/regexes.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Any EOL char that isn't appropriate punctuation
GLOBAL_DATUM_INIT(has_no_eol_punctuation, /regex, regex(@"\w$"))
//Does the line end in any EOL char that isn't appropriate punctuation OR does it end in a chat-formatted markdown sequence (+bold+, etc) without a period?
GLOBAL_DATUM_INIT(needs_eol_autopunctuation, /regex, regex(@"([a-zA-Z\d]|[^.?!~-][+|_])$"))

//All non-capitalized 'i' surrounded with whitespace (aka, 'hello >i< am a cat')
GLOBAL_DATUM_INIT(noncapital_i, /regex, regex(@"\b[i]\b", "g"))
7 changes: 4 additions & 3 deletions modular_nova/master_files/code/_globalvars/text.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// Ensures sentences end in appropriate punctuation (a period if none exist)
/// and that all whitespace-bounded 'i' characters are capitalized.
/// Ensures sentences end in appropriate punctuation (a period if none exist) and that all whitespace-bounded 'i' characters are capitalized.
/// If the sentence ends in chat-flavored markdown for bolds, italics or underscores and does not have a preceding period, exclamation mark or other flavored sentence terminator, add a period.
/// (e.g: 'Borgs are rogue' becomes 'Borgs are rogue.', '+BORGS ARE ROGUE+ becomes '+BORGS ARE ROGUE+.', '+Borgs are rogue~+' is untouched.)
/proc/autopunct_bare(input_text)
if (findtext(input_text, GLOB.has_no_eol_punctuation))
if (findtext(input_text, GLOB.needs_eol_autopunctuation))
input_text += "."

input_text = replacetext(input_text, GLOB.noncapital_i, "I")
Expand Down

0 comments on commit fcc5947

Please sign in to comment.