View Single Post
Old 05-22-2014, 08:03 PM   #6
Section8
Addict
Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.
 
Section8's Avatar
 
Posts: 254
Karma: 2092424
Join Date: Oct 2011
Location: Arlington, TX
Device: Kindle PW4, Moon+ Reader on a cheap Android tablet
I have a nook, and the only real regexes I've written are for fixing stylesheets to work around its margin bug: if "publisher defaults" are disabled, the nook doesn't handle the css "margin" setting. I've been using these to convert all 4 forms of "margin" to the equivalent margin-top, margin-right, etc. These were written for Sigil, but I *think* they work in the calibre editor.

First: find margin:
Find: margin *:

Convert margin: a (single value):
Find: margin *: *([^\s;]+)(\s*(;|}))
Replace: margin-top: \1; margin-right: \1; margin-bottom: \1; margin-left: \1\2

Convert margin: a, b (2 values)
Find: margin *: *([^\s;]+) +([^\s;]+)([\s]*(;|}))
Replace: margin-top: \1; margin-right: \2; margin-bottom: \1; margin-left: \2\3

Convert margin a, b, c (3 values)
Find: margin *: *([^\s;]+) +([^\s;]+) +([^\s;]+)([\s]*(;|}))
Replace: margin-top: \1; margin-right: \2; margin-bottom: \3; margin-left: \2\4

Convert margin a, b, c, d (4 values)
Find: margin *: *([^\s;]+) +([^\s;]+) +([^\s;]+) +([^\s;]+)(\s*(;|}))
Replace: margin-top: \1; margin-right: \2; margin-bottom: \3; margin-left: \4\5
Section8 is offline   Reply With Quote