How to use the html2text.html2text function in html2text

To help you get started, we’ve selected a few html2text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bukun / TorCMS / torcms / core / tool / run_whoosh.py View on Github external
def do_for_app(rand=True, kind='', doc_type=None):
    '''
    生成whoosh,根据配置文件中类别。
    '''

    if doc_type is None:
        doc_type = {}
    if rand:
        recs = MPost.query_random(num=10, kind=kind)
    else:
        recs = MPost.query_recent(num=2, kind=kind)

    for rec in recs:
        text2 = rec.title + ',' + html2text.html2text(tornado.escape.xhtml_unescape(rec.cnt_html))
        writer = TOR_IDX.writer()
        writer.update_document(
            catid='sid' + kind,
            title=rec.title,
            type=doc_type[rec.kind],
            link='/{0}/{1}'.format(router_post[rec.kind], rec.uid),
            content=text2
        )
        writer.commit()
github gislite / maplet / script_gen_whoosh_database.py View on Github external
def do_for_post(writer, rand = True):
    mpost = MPost()
    if rand:
        recs = mpost.query_random(50)
    else:
        recs = mpost.query_recent(50)
    doc_type = '<span class="glyphicon glyphicon-list-alt" style="color:green;">[{0}]</span>'.format('文档')
    print(recs.count())
    for rec in recs:
        # sleep(0.1)
        text2 = rec.title +',' + html2text.html2text(tornado.escape.xhtml_unescape(rec.cnt_html))
        # writer.update_document(path=u"/a",content="Replacement for the first document")
        writer.update_document(
            title=rec.title,
            type= doc_type,
            link='/post/{0}.html'.format(rec.uid),
            content=text2
        )
github liberapay / liberapay.com / liberapay / models / participant.py View on Github external
def render(t, context):
                b = base_spt[t].render(context).strip() if base_spt else '$body'
                if t == 'text/plain' and t not in spt:
                    body = html2text(bodies['text/html']).strip()
                else:
                    body = spt[t].render(context).strip()
                bodies[t] = body
                return b.replace('$body', body)
        message = {}
github appressoas / django_cradmin / django_cradmin / apps / cradmin_email / emailutils.py View on Github external
def convert_html_to_plaintext(html):
    """
    Convert the given ``html`` to plain text.
    """
    return html2text.html2text(html)
github nvbn / everpad / everpad / specific / unity / lens.py View on Github external
notebooks = [self.notebook_filter_id]
        else:
            notebooks = dbus.Array([], signature='i')
        if self.place_filter_id:
            place = self.place_filter_id
        else:
            place = 0
        tags = dbus.Array(self.tag_filter_ids, signature='i')
        for note_struct in provider.find_notes(
            search, notebooks, tags, place,
            1000, Note.ORDER_TITLE, -1,
        ):
            note = Note.from_tuple(note_struct)
            results.append(json.dumps({'id': note.id, 'search': search}),
                'everpad-note', self.pin_notes if note.pinnded else self.all_notes,
                "text/html", note.title, html2text(note.content),
            '')
github pankaj28843 / html2latex / src / html2latex / utils_old.py View on Github external
def check_spelling_in_html(html):
    incorrect_words = filter(
        invalid_word_checker, set(re.findall("[a-zA-Z]+", html2text(html))))
    for word in incorrect_words:
        html = html.replace(
            word, r'<strong style="color: red; font-size: 14px;">' + word + '</strong>')
    return html
github Foo-Manroot / tweet-feed / cli / cli.py View on Github external
else
                t.replace_with (
                    p.new_string (" " + re.sub ("\n", "", t ["alt"]) + " ")
                )
        )

        # Replaces the 'a' tags with their text (without "\n")
        [ replace_anchor (parsed, x)
            for x in parsed.select ("a")
        ]
        # Replaces the 'img' tags with their alt-text (without "\n")
        [ replace_img (parsed, x)
            for x in parsed.select ("img")
        ]

        text = html2text.html2text (parsed.get_text (), bodywidth = 140)


    # Removes final new lines
    text = re.sub ("\n+$", "", text)

    # Adds tabs before each line (if needed)
    if add_tabs:
        text = re.sub (r"^", r"\t", text)
        text = re.sub (r"\n", r"\n\t", text)


    return text
github f1nnix / magplan / plan / tasks / send_idea_comment_notification.py View on Github external
def _send_email(comment, recipients):
    subject = f"Комментарий к идее «{comment.commentable}» от {comment.user}"
    html_content = render_to_string(
        "email/new_comment.html",
        {"comment": comment, "commentable_type": 'idea', "APP_URL": os.environ.get('APP_URL', None)},
    )
    text_content = html2text.html2text(html_content)
    msg = EmailMultiAlternatives(subject, text_content, config.PLAN_EMAIL_FROM, recipients)
    msg.attach_alternative(html_content, 'text/html')
    msg.send()