diff --git a/Changelog.txt b/Changelog.txt index 7a811d6..1585793 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +0.9.5 - 2022-04-01 +-- New options for trimming leading/trailing whitespaces + 0.9.4 - 2022-04-01 -- Fixed issue #20, extra space between ؟ and ! diff --git a/negar/constants.py b/negar/constants.py index a97a9d3..fc6586d 100644 --- a/negar/constants.py +++ b/negar/constants.py @@ -1,6 +1,6 @@ from pathlib import Path -__version__ = "0.9.4" +__version__ = "0.9.5" LOGO = (Path(__file__).parent.absolute()/"logo.png").as_posix() DATAFILE = Path(__file__).parent.absolute()/"data/untouchable.dat" diff --git a/negar/gui.py b/negar/gui.py index 29a768f..049f4a8 100644 --- a/negar/gui.py +++ b/negar/gui.py @@ -121,6 +121,7 @@ def setupUi(self): self.clnup_kashidas = QCheckBox(self.tr("Cleanup &kashidas"), checked=True) self.clnup_ex_marks = QCheckBox(self.tr("Cleanup e&xtra marks"), checked=True) self.clnup_spacing = QCheckBox(self.tr("C&leanup spacing"), checked=True) + self.trim_lt_whitespaces = QCheckBox(self.tr("Tr&im Leading/Trailing Whitespaces"), checked=True) # Add to untouchable list: self.untouch_word = QLineEdit() @@ -139,22 +140,23 @@ def setupUi(self): config_box = QGroupBox(self.tr("Options")) config_layout = QGridLayout() config_layout.addWidget(self.f_dashes, 0, 0) - config_layout.addWidget(self.f_three_dots, 0, 1) + config_layout.addWidget(self.f_three_dots, 1, 0) config_layout.addWidget(self.f_english_quotes, 0, 2) - config_layout.addWidget(self.f_hamzeh, 0, 3) - config_layout.addWidget(self.f_s_spacing, 0, 4) - config_layout.addWidget(self.f_arab_num, 1, 0) + config_layout.addWidget(self.f_arab_num, 0, 1) config_layout.addWidget(self.f_eng_num, 1, 1) config_layout.addWidget(self.f_non_persian_ch, 1, 2) - config_layout.addWidget(self.f_p_spacing, 1, 3) - config_layout.addWidget(self.f_p_separate, 1, 4) - config_layout.addWidget(self.f_s_separate, 2, 0) - config_layout.addWidget(self.clnup_kashidas, 2, 1) - config_layout.addWidget(self.aggressive, 2, 2) - config_layout.addWidget(self.clnup_ex_marks, 2, 3) - config_layout.addWidget(self.clnup_spacing, 2, 4) - config_layout.addWidget(self.f_spacing_bq, 3, 0, 1, 2) - config_layout.addWidget(self.hamzeh_yeh, 3, 2, 1, 2) + config_layout.addWidget(self.f_hamzeh, 2, 0) + config_layout.addWidget(self.f_p_separate, 2, 1) + config_layout.addWidget(self.f_s_separate, 2, 2) + config_layout.addWidget(self.f_s_spacing, 3, 1) + config_layout.addWidget(self.f_p_spacing, 3, 2) + config_layout.addWidget(self.aggressive, 3, 3) + config_layout.addWidget(self.f_spacing_bq, 0, 3, 1, 2) + config_layout.addWidget(self.hamzeh_yeh, 1, 3, 1, 2) + config_layout.addWidget(self.trim_lt_whitespaces, 2, 3, 1, 2) + config_layout.addWidget(self.clnup_spacing, 0, 5) + config_layout.addWidget(self.clnup_ex_marks, 1, 5) + config_layout.addWidget(self.clnup_kashidas, 2, 5) config_box.setLayout(config_layout) # Tab widgets initializing: @@ -232,6 +234,7 @@ def setupUi(self): self.clnup_kashidas.stateChanged.connect(self.option_control) self.clnup_ex_marks.stateChanged.connect(self.option_control) self.clnup_spacing.stateChanged.connect(self.option_control) + self.trim_lt_whitespaces.stateChanged.connect(self.option_control) def keyPressEvent(self, event): if event.key() == Qt.Key.Key_Escape: @@ -320,6 +323,8 @@ def option_control(self): self.editing_options.append("cleanup-ex-marks") if not self.clnup_spacing.isChecked(): self.editing_options.append("cleanup-spacing") + if not self.trim_lt_whitespaces.isChecked(): + self.editing_options.append("trim-leading-trailing-whitespaces") def file_dialog(self): fname, _ = QFileDialog.getOpenFileName(self, 'Open File - A Plain Text') @@ -337,7 +342,7 @@ def edit_text(self): self.output_editor.append(run_PE.cleanup()) def save_to_clipboard(self): - sanitizedText = self.output_editor.toPlainText().strip() + sanitizedText = self.output_editor.toPlainText() if sanitizedText: copy(sanitizedText) diff --git a/negar/virastar.py b/negar/virastar.py index 7b1ffb2..7735ae8 100644 --- a/negar/virastar.py +++ b/negar/virastar.py @@ -32,6 +32,7 @@ def __init__(self, text, *args): self._fix_arabic_numbers = is_in_args('fix-arabic-num') self._fix_english_numbers = is_in_args('fix-english-num') self._fix_misc_non_persian_chars = is_in_args('fix-non-persian-chars') + self._trim_leading_trailing_whitespaces = is_in_args('trim-leading-trailing-whitespaces') UnTouchable() # to generate the untouchable words self.cleanup() @@ -53,6 +54,8 @@ def cleanup(self): if self._cleanup_spacing: self.cleanup_spacing() if self._fix_spacing_for_braces_and_quotes: self.fix_spacing_for_braces_and_quotes() + if self._trim_leading_trailing_whitespaces: + self.text = '\n'.join([line.strip() for line in self.text.split('\n')]) self.cleanup_redundant_zwnj() return self.text