Skip to content

Commit

Permalink
Round Bold
Browse files Browse the repository at this point in the history
  • Loading branch information
un-pogaz authored Oct 9, 2020
1 parent 7102845 commit b38d1bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
19 changes: 16 additions & 3 deletions CommentsCleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def CleanBasic(text):
text = RegexLoop("(…|…)", "…", text);
text = RegexLoop("(’|’)", "’", text);

# same inline
text = RegexLoop(r"<(i|b|em|strong|span)([^>]*)>([^>]*)</\1>\s+<\1\2>", r'<\1\2>\3 ', text);
text = RegexLoop(r"<(i|b|em|strong|span)([^>]*)>([^>]*)</\1><\1\2>", r'<\1\2>\3', text);

# inline vide
innerSpace = r"<(i|b|em|strong)[^>]*>\s+</\1>";
innerEmpty = r"<(i|b|em|strong)[^>]*></\1>";
Expand Down Expand Up @@ -135,20 +139,29 @@ def CleanHTML(library_config, text):
r'(background|opacity|text-shadow|list-style-position)',
r'(position|top|bottom|left|right)',
r'(max-|z-|)(width|height|index)',
r'-{0,2}(mso-|moz-|webkit-|qt-)',
r'-{0,2}((?:mso-|moz-|webkit-|qt-)[^:]+)',
r'(font-family|font-variant|font-stretch|font-size|line-height)'
];

for atr in atr_tbl:
text = RegexLoop(r'style="([^"]*)'+ atr +'[^:]*:[^;]*;([^"]*)"', r'style="\1\3"', text);
text = RegexLoop(r'style="([^"]*)'+ atr +'\s*:[^;]*;([^"]*)"', r'style="\1\3"', text);

# font-weight
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(normal|inherit|initial)\s*;([^"]*)"', r'style="\1\3"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(?P<name>\d)[1-9]\d(?:\.\d+)?\s*;([^"]*)"', r'style="\1 font-weight: \g<name>00;\3"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(bold)\s*;([^"]*)"', r'style="\1font-weight: 600\3"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(\d){4,}(?:\.\d+)?\s*;([^"]*)"', r'style="\1font-weight: 900;\3"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(\d){1,2}(?:\.\d+)?\s*;([^"]*)"', r'style="\1font-weight: 100;\3"', text);

if library_config[cfg.KEY_FONT_WEIGHT] == 'none':
n=None;
elif library_config[cfg.KEY_FONT_WEIGHT] == 'bold':
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*[5-9]\d\d(?:\.\d+)?\s*;([^"]*)"', r'style="\1 font-weight: xxx;\2"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*xxx\s*;([^"]*)"', r'style="\1 font-weight: 600;\2"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*[1-4]\d\d(?:\.\d+)?\s*;([^"]*)"', r'style="\1\2"', text);
else: #trunc
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(?P<name>\d)\d\d(?:\.\d+)?\s*;([^"]*)"', r'style="\1 font-weight: \g<name>xx;\3"', text);
text = RegexLoop(r'style="([^"]*)font-weight\s*:\s*(?P<name>\d)xx\s*;([^"]*)"', r'style="\1 font-weight: \g<name>00;\3"', text);

# font-style
text = RegexLoop(r'style="([^"]*)font-style\s*:\s*(normal|inherit|initial)\s*;([^"]*)"', r'style="\1\3"', text);
text = RegexLoop(r'style="([^"]*)font-style\s*:\s*(oblique(?:\s+\d+deg))\s*;([^"]*)"', r'style="\1font-style: italic;\3"', text);
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ActionCommentCleaner(InterfaceActionBase):
description = _('Remove the scraps CSS in comments')
supported_platforms = ['windows', 'osx', 'linux']
author = 'un_pogaz'
version = (0, 2, 1)
version = (0, 3, 0)
minimum_calibre_version = (2, 0, 0)

#: This field defines the GUI plugin class that contains all the code
Expand Down
21 changes: 17 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

PLUGIN_ICONS = ['images/plugin.png']

STORE_NAME = 'Options'
KEY_KEEP_URL = 'keep'
KEY_FORCE_JUSTIFY = 'empty'
STORE_NAME = 'Options';
KEY_KEEP_URL = 'keepUrl';
KEY_FORCE_JUSTIFY = 'ForceJustify';
KEY_FONT_WEIGHT = 'FontWeight';

SHOW_URL = OrderedDict([('keep', _('Keep URL')),
('none', _('Delete URL'))])
Expand All @@ -32,9 +33,15 @@
('none', _('No change')),
('del', _('Delete all align'))])

FONT_WEIGHT = OrderedDict([
('trunc', _('Truncate the value to the hundred')),
('bold', _('Rounded to Bold (value 600)')),
('none', _('No change'))])

DEFAULT_LIBRARY_VALUES = {
KEY_KEEP_URL: 'keep',
KEY_FORCE_JUSTIFY: 'empty'
KEY_FORCE_JUSTIFY: 'empty',
KEY_FONT_WEIGHT: 'bold',
}

def get_library_config(db):
Expand Down Expand Up @@ -78,6 +85,11 @@ def __init__(self, plugin_action):
self.showCombo2 = KeyValueComboBox(self, FORCE_JUSTIFY, post_show3)
options_group_box_layout.addWidget(self.showCombo2, 4, 1)

options_group_box_layout.addWidget(QLabel(_('Weights:'), self), 5, 1)
post_show3 = library_config.get(KEY_FONT_WEIGHT, DEFAULT_LIBRARY_VALUES[KEY_FONT_WEIGHT])
self.showCombo3 = KeyValueComboBox(self, FONT_WEIGHT, post_show3)
options_group_box_layout.addWidget(self.showCombo3, 6, 1)

# --- Keyboard shortcuts ---
keyboard_shortcuts_button = QPushButton(_('Keyboard shortcuts...'), self)
keyboard_shortcuts_button.setToolTip(_(
Expand All @@ -92,6 +104,7 @@ def save_settings(self):

library_config[KEY_KEEP_URL] = self.showCombo1.selected_key()
library_config[KEY_FORCE_JUSTIFY] = self.showCombo2.selected_key()
library_config[KEY_FONT_WEIGHT] = self.showCombo3.selected_key()

set_library_config(db, library_config)

Expand Down

0 comments on commit b38d1bf

Please sign in to comment.