![]() |
#1 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
wacky reused "sgc" styles
I'm looking at tidying up the code on a ePub and find that each (of 80) xhtml file has its own style definitions. So I wanted to start by extracting these and putting them all in the common stylesheet.css file.
Then I found they reuse the same style names with different definitions : e.g.: Code:
<style type="text/css"> p.sgc-2 {font-style: italic} a.sgc-1 {font-weight: bold} </style> Code:
<style type="text/css"> p.sgc-2 {font-weight: bold} a.sgc-1 {font-weight: bold} </style> Merging two of these files in Sigil, it doesn't notice the conflict and the sgc-2 bold in the second file is now italic. Obviously global S&R will just scramble these up. Is there any way short of editing each file individually to rationalise the styles, to e.g. Code:
p.italic {font-style: italic} p.bold {font-weight: bold} (I'd rather just use <b> and <i> myself, but that would be too simple.) Last edited by AlanHK; 09-14-2014 at 12:44 AM. |
![]() |
![]() |
![]() |
#2 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Sigil will create these classes with one of its options for moving style definitions outside of the text itself.
EDIT: http://web.sigil.googlecode.com/git/...faq_formatting Quote:
regex ![]() Find: Code:
[a-zA-Z.]+ \{font-(style|weight): (italic|bold)} Code:
.\2 {font-\1: \2} Last edited by eschwartz; 09-14-2014 at 01:51 AM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
|
![]() |
![]() |
![]() |
#4 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
find any text of upper+lower letters, with a class indicator (dot) in it, followed by {font-anything: type} and replace it with .type {font-anything: type}.
Basically, convert the css selector for both to either ".bold|.italic", depending. No need to restrict it to p or a only. I think Sigil was the one to autoconvert <b> or <i> to those css styles in the first place. I don't like Tidy, I prefer to change things myself if and when I want to. Same reason I only Beautify in calibre editor after I have already validated with Check Book. Difference is, calibre editor doesn't take it upon itself to change the code, except to fix malformed xhtml. Last edited by eschwartz; 09-14-2014 at 01:58 AM. |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
That is one of the reasons I built an ePUB importer for Word in my tools. It can handle this and you would be able to fix more before building a new ePUB.
I must say that the regex is very nice. However, it only works for those cases. If there are more sgc styles, it would not work anymore. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
Tried the regex, no matches found.
But was this just targeted at the definition or the text? e.g. will <p class="p6 sgc-2">October 11</p> be changed to <p class="p6.bold">October 11</p> The problem is each file has a different meaning for "sgc-2". And your regex looks for a . but there is none. What I think I need to do is in every file with the sgc-2 {font-weight: bold} definition, to change " sgc-2">" to ".bold">" I don't know if the "Selected files" allows me to choose files by criteria or just manually. Last edited by AlanHK; 09-14-2014 at 02:47 AM. |
![]() |
![]() |
![]() |
#7 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
This is meant to only target the css, whether in a stylesheet or in <style> tags. It searches for the font-weight or -style, and ignores what sgc-class it actually is.
To fix the text (my preference), I'd use: Find: Code:
<span class="(?:(b)old|(i)talic)">([^<>]*)</span> Code:
<\1>\2</\1> |
![]() |
![]() |
![]() |
#8 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,725
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
@AlanHK: Sigil will only generate sgc styles if the HTML Tidy option was selected and Save is enabled (Preferences > Clean Source). (The recommended setting is Pretty Print Tidy.)
|
![]() |
![]() |
![]() |
#9 | ||
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
Quote:
The problem is that in one file <p class="p6 sgc-2">October 11</p> is bold, in another it would be italic. Quote:
Anyway, I think I can do this by unzipping the epub and sorting the files into groups with common style definitions, using Far file manger, then doing S&R on groups of files to make them all consistent, then making a new epub. |
||
![]() |
![]() |
![]() |
#10 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
Quote:
Well, that's an option I will never use then. I thought Calibre was annoying by creating numerous virtually identical styles with different names, which was tedious but straight forward to clean up, but doing the opposite is much, much worse. |
|
![]() |
![]() |
![]() |
#11 |
Color me gone
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
|
It is an option not to use for other reasons as well. It can clean up perfectly good text out of existence!
|
![]() |
![]() |
![]() |
#12 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,555
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
HTML Tidy is for people who don't care about what the code looks like. They only care how it renders.
It's alright to hate it and not want to use it, but it's important to remember that it often serves the WYSIWYG users of Sigil quite admirably. I'm not one of those users, mind you. I'm just aware (and tolerant) of the fact that WYSYWIG and automatic code generation features often come at the cost of control over what the underlying markup looks like. Nature of the beast. You want stuff done for you: you lose a little control over how it's done. Last edited by DiapDealer; 09-14-2014 at 09:48 AM. |
![]() |
![]() |
![]() |
#13 |
Color me gone
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
|
That is true of calibre conversions as well. They work, but heaven help you if you think you might want to tweak it. As you say, for many people, especially for their own private use, like making a family history, this is just great and the level of effort makes it something you can actually do instead of putting it off until it never gets done.
Now I know a little about it, why not spend a little effort? But in the beginning, I remembering css being hard to understand and seemed much more trouble than it was worth. |
![]() |
![]() |
![]() |
#14 | ||
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
Quote:
![]() So I can't think of a purely regex way to fix these, matching class to style. You'd have to do each class on its own. Best thing is to avoid this entirely. HTML Tidy is a really annoying crutch. |
||
![]() |
![]() |
![]() |
#15 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,031
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
I am a little (Time zone) late jumping in.
SGC # are per file (as you discovered) and are defined in between the <style> tags in the file <head> SGC # are assigned in order of usage need (Thus the seeming randomness of assignments) A little tedious way to unify/walk styles into a (Book) single stylesheet Copy the first files <styles> section contents to a new stylesheet ( ![]() Rename the style names from SGC # to something 'meaningful' (leave the old SGC# in comments /* SGC_3 */ as a reminder) Then Replace all the old SGC # in the book file with their new names Using the same NEW STYLE name, locate other book files that have a EXACT matching definition and ALSO change their defined name (remember to use : 'current file' in replace) to the new name . ( ![]() Add another files <style> to the main stylesheet (remove any of the the new name definitions that appear before the copy) repeat the copy-renaming sequence until done Once you get on a roll, it will probably take less than 30 minutes remember to link your new stylesheet to the files WARNING: If any SGC # are greater than 9, do those FIRST (Extra care is needed not to change SGC-1n's along with SGC-1) |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Feature Request: configurable space setting for "Insert blank line" in "Look & Feel" | therealjoeblow | Calibre | 15 | 07-25-2011 03:14 PM |
Calibre install -- "styles" folder on my desktop? | corona | Calibre | 2 | 10-17-2010 07:43 PM |