'Takes string a user supplies and wraps it in markup that will be centered with
appropriate margins.  <hr> and <img> tags are allowed.  If the user specifies
a style with width attributes in the <hr> tag then the appropriate margins are
applied to wrapping divs.  This is because many ebook devices don\'t support margin:auto
All other html is converted to text.'

def markup_user_break(self, replacement_break):

    hr_open = '<div    id="scenebreak"    style="margin-left:    45%;    margin-right:    45%;    margin-top:1.5em;    margin-bottom:1.5em;    page-break-before:avoid">'
    if re.findall('(<|>)', replacement_break):
        if re.match('^<hr', replacement_break):
            if (replacement_break.find('width') != (-1)):
                try:
                    width = int(re.sub('.*?width(:|=)(?P<wnum>\\d+).*', '\\g<wnum>', replacement_break))
                except:
                    scene_break = (hr_open + '<hr    style="height:    3px;    background:#505050"    /></div>')
                    self.log.warn('Invalid    replacement    scene    break    expression,    using    default')
                else:
                    replacement_break = re.sub('(?i)(width=\\d+\\%?|width:\\s*\\d+(\\%|px|pt|em)?;?)', '', replacement_break)
                    divpercent = ((100 - width) / 2)
                    hr_open = re.sub('45', unicode(divpercent), hr_open)
                    scene_break = ((hr_open + replacement_break) + '</div>')
            else:
                scene_break = (hr_open + '<hr    style="height:    3px;    background:#505050"    /></div>')
        elif re.match('^<img', replacement_break):
            scene_break = ((self.scene_break_open + replacement_break) + '</p>')
        else:
            from calibre.utils.html2text import html2text
            replacement_break = html2text(replacement_break)
            replacement_break = re.sub('\\s', '&nbsp;', replacement_break)
            scene_break = ((self.scene_break_open + replacement_break) + '</p>')
    else:
        replacement_break = re.sub('\\s', '&nbsp;', replacement_break)
        scene_break = ((self.scene_break_open + replacement_break) + '</p>')
    return scene_break
