(self)
Remove linebreaks from clipboard and paste
Remove linebreaks from clipboard and paste
Remove linebreaks from clipboard and paste
def pasteWithoutLinebreaks(self):
    """Remove linebreaks from clipboard and paste"""
    mime = self.web.mungeClip(mode=QClipboard.Clipboard)
    html = mime.html()
    text = mime.text()

    if not(text or html):
        return
    
    if html:
        content = re.sub(re_lb_open, " ", html)
        content = re.sub(re_lb_close, "", content)
    else:
        if PRESERVE_PARAGRAPHS:
            # remove EOL hyphens:
            content = re.sub(r"-\n(?!\n)", "", text) 
            # skip ends of sentences:
            content = re.sub(r"(?<!\.|\!|\:)\n(?!\n)", " ", content)
            # strip extraneous linebreaks while rejoining with <br> tags
            content = "<br />".join(i.strip() for i in content.split("\n"))
        else:
            content = content.replace("\n", " ")

    self.web.eval("""
        var pasteHTML = function(html) {
            setFormat("inserthtml", html);
        };
        var filterHTML = function(html) {
            // wrap it in <top> as we aren't allowed to change top level elements
            var top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0];
            filterNode(top);
            var outHtml = top.innerHTML;
            // get rid of nbsp
            outHtml = outHtml.replace(/&nbsp;/ig, " ");
            return outHtml;
        };
        pasteHTML(%s);
        """ % json.dumps(content))

    if TOOLTIP:
        tooltip("Pasting without linebreaks", period=500)
def pasteWithoutLinebreaks ( self ) : mime = self . web . mungeClip ( mode = QClipboard . Clipboard ) html = mime . html ( ) text = mime . text ( ) if not ( text or html ) : return if html : content = re . sub ( re_lb_open , " " , html ) content = re . sub ( re_lb_close , "" , content ) else : if PRESERVE_PARAGRAPHS : # remove EOL hyphens: content = re . sub ( r"-\n(?!\n)" , "" , text ) # skip ends of sentences: content = re . sub ( r"(?<!\.|\!|\:)\n(?!\n)" , " " , content ) # strip extraneous linebreaks while rejoining with <br> tags content = "<br />" . join ( i . strip ( ) for i in content . split ( "\n" ) ) else : content = content . replace ( "\n" , " " ) self . web . eval ( """
        var pasteHTML = function(html) {
            setFormat("inserthtml", html);
        };
        var filterHTML = function(html) {
            // wrap it in <top> as we aren't allowed to change top level elements
            var top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0];
            filterNode(top);
            var outHtml = top.innerHTML;
            // get rid of nbsp
            outHtml = outHtml.replace(/&nbsp;/ig, " ");
            return outHtml;
        };
        pasteHTML(%s);
        """ % json . dumps ( content ) ) if TOOLTIP : tooltip ( "Pasting without linebreaks" , period = 500 )