Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 09-14-2014, 12:41 AM   #1
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
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>
and
Code:
<style type="text/css">
p.sgc-2 {font-weight: bold}
a.sgc-1 {font-weight: bold}
</style>
All the styles have "sgc" in their name. Anyone know where they come from?

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}
which I can then put in the global css?

(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.
AlanHK is offline   Reply With Quote
Old 09-14-2014, 01:32 AM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
What does sgc-1 mean in my document?

sgc indicates a Sigil class that is used to set the formatting style for certain parts of your text. sgc classes are automatically created for certain span tags and "style=" attributes if you have HTML Tidy turned on (Edit→Clean Source).

regex

Find:
Code:
[a-zA-Z.]+ \{font-(style|weight): (italic|bold)}
Replace:
Code:
.\2 {font-\1: \2}

Last edited by eschwartz; 09-14-2014 at 01:51 AM.
eschwartz is offline   Reply With Quote
Advert
Old 09-14-2014, 01:43 AM   #3
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
Quote:
Originally Posted by eschwartz View Post
Sigil will create these classes with one of its options for moving style definitions outside of the text itself.

My God, I didn't expect this mess had been actually made by Sigil.

Can you explain the intent of your regex?
I can see the what, but not why.
AlanHK is offline   Reply With Quote
Old 09-14-2014, 01:53 AM   #4
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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.
eschwartz is offline   Reply With Quote
Old 09-14-2014, 02:10 AM   #5
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
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.
Toxaris is offline   Reply With Quote
Advert
Old 09-14-2014, 02:34 AM   #6
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
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.
AlanHK is offline   Reply With Quote
Old 09-14-2014, 02:40 AM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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>
Replace:
Code:
<\1>\2</\1>
And revert it back to <b> and <i> tags.
eschwartz is offline   Reply With Quote
Old 09-14-2014, 05:43 AM   #8
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
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.)
Doitsu is offline   Reply With Quote
Old 09-14-2014, 08:22 AM   #9
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
Quote:
Originally Posted by eschwartz View Post
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.
Won't that leave all the text using those styles with undefined styles?


The problem is that in one file
<p class="p6 sgc-2">October 11</p> is bold, in another it would be italic.


Quote:
To fix the text (my preference), I'd use:

Find:
Code:
<span class="(?:(b)old|(i)talic)">([^<>]*)</span>
Replace:
Code:
<\1>\2</\1>
And revert it back to <b> and <i> tags.
That looks useful, but first I need to get all the text tagged consistently.

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.
AlanHK is offline   Reply With Quote
Old 09-14-2014, 08:25 AM   #10
AlanHK
Guru
AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.AlanHK ought to be getting tired of karma fortunes by now.
 
AlanHK's Avatar
 
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
Quote:
Originally Posted by Doitsu View Post
@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.)

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.
AlanHK is offline   Reply With Quote
Old 09-14-2014, 08:49 AM   #11
mrmikel
Color me gone
mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.
 
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!
mrmikel is offline   Reply With Quote
Old 09-14-2014, 09:42 AM   #12
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
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.
DiapDealer is offline   Reply With Quote
Old 09-14-2014, 10:03 AM   #13
mrmikel
Color me gone
mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.
 
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.
mrmikel is offline   Reply With Quote
Old 09-14-2014, 10:45 AM   #14
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by AlanHK View Post
Won't that leave all the text using those styles with undefined styles?


The problem is that in one file
<p class="p6 sgc-2">October 11</p> is bold, in another it would be italic.
Knew there was something I was forgetting.

Quote:
That looks useful, but first I need to get all the text tagged consistently.

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.
Yeah, my second regex assumes unreasonably that tidy named classes "bold" and "italic" (where did I get that from?) which I blame on the lateness of the hour.

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.
eschwartz is offline   Reply With Quote
Old 09-14-2014, 11:00 AM   #15
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
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 ( start with the file with the most SGC's defined)

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 .

( let the replace change the name inside the <style> as well. When there are no more SGC's in that <style>, it can be deleted)

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)
theducks is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 01:29 PM.


MobileRead.com is a privately owned, operated and funded community.