Skip to content

Commit

Permalink
trim leading/trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
javadr committed Apr 1, 2022
1 parent 02f19fe commit 4671f31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -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 !

Expand Down
2 changes: 1 addition & 1 deletion negar/constants.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
33 changes: 19 additions & 14 deletions negar/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions negar/virastar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 4671f31

Please sign in to comment.