diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/text_sentencecase.py | |
parent | Initial commit. (diff) | |
download | inkscape-upstream.tar.xz inkscape-upstream.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/text_sentencecase.py')
-rwxr-xr-x | share/extensions/text_sentencecase.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/share/extensions/text_sentencecase.py b/share/extensions/text_sentencecase.py new file mode 100755 index 0000000..b8bb136 --- /dev/null +++ b/share/extensions/text_sentencecase.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +"""Convert to sentence case""" + +import inkex + + +class SentenceCase(inkex.TextExtension): + """Convert text to sentence case""" + + sentence_start = True + was_punctuation = False + + def map_char(self, char): + """Turn the char into a sentence using class state""" + if char in ".!?": + self.was_punctuation = True + elif ((char.isspace() or self.newline) and self.was_punctuation) or self.newpar: + self.sentence_start = True + self.was_punctuation = False + elif char in '")': + pass + else: + self.was_punctuation = False + + if not char.isspace(): + self.newline = False + self.newpar = False + + if self.sentence_start and char.isalpha(): + self.sentence_start = False + return char.upper() + elif not self.sentence_start and char.isalpha(): + return char.lower() + return char + + +if __name__ == "__main__": + SentenceCase().run() |