How to use the html2text.utils.escape_md 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 JimmXinu / FanFicFare / included_dependencies / html2text / __init__.py View on Github external
else:
                        self.o("[")
                        self.maybe_automatic_link = None
                        self.empty_link = False

                # If we have images_to_alt, we discard the image itself,
                # considering only the alt text.
                if self.images_to_alt:
                    self.o(escape_md(alt))
                else:
                    self.o("![" + escape_md(alt) + "]")
                    if self.inline_links:
                        href = attrs.get('href') or ''
                        self.o(
                            "(" +
                            escape_md(
                                urlparse.urljoin(
                                    self.baseurl,
                                    href
                                )
                            ) +
                            ")"
                        )
                    else:
                        i = self.previousIndex(attrs)
                        if i is not None:
                            attrs = self.a[i]
                        else:
                            self.acount += 1
                            attrs['count'] = self.acount
                            attrs['outcount'] = self.outcount
                            self.a.append(attrs)
github JimmXinu / FanFicFare / included_dependencies / html2text / __init__.py View on Github external
if self.maybe_automatic_link is not None:
                    href = self.maybe_automatic_link
                    if self.images_to_alt and escape_md(alt) == href and \
                            self.absolute_url_matcher.match(href):
                        self.o("<" + escape_md(alt) + ">")
                        self.empty_link = False
                        return
                    else:
                        self.o("[")
                        self.maybe_automatic_link = None
                        self.empty_link = False

                # If we have images_to_alt, we discard the image itself,
                # considering only the alt text.
                if self.images_to_alt:
                    self.o(escape_md(alt))
                else:
                    self.o("![" + escape_md(alt) + "]")
                    if self.inline_links:
                        href = attrs.get('href') or ''
                        self.o(
                            "(" +
                            escape_md(
                                urlparse.urljoin(
                                    self.baseurl,
                                    href
                                )
                            ) +
                            ")"
                        )
                    else:
                        i = self.previousIndex(attrs)
github JimmXinu / FanFicFare / included_dependencies / html2text / __init__.py View on Github external
self.o("<img in="" src="&quot; + attrs[&quot;src&quot;] + &quot;">")
                    return

                # If we have a link to create, output the start
                if self.maybe_automatic_link is not None:
                    href = self.maybe_automatic_link
                    if self.images_to_alt and escape_md(alt) == href and \
                            self.absolute_url_matcher.match(href):
                        self.o("&lt;" + escape_md(alt) + "&gt;")
                        self.empty_link = False
                        return
                    else:
                        self.o("[")
                        self.maybe_automatic_link = None
                        self.empty_link = False

                # If we have images_to_alt, we discard the image itself,
                # considering only the alt text.
                if self.images_to_alt:
                    self.o(escape_md(alt))
                else:
                    self.o("![" + escape_md(alt) + "]")
                    if self.inline_links:
                        href = attrs.get('href') or ''
                        self.o(
github JimmXinu / FanFicFare / included_dependencies / html2text / __init__.py View on Github external
else:
                    self.astack.append(None)
            else:
                if self.astack:
                    a = self.astack.pop()
                    if self.maybe_automatic_link and not self.empty_link:
                        self.maybe_automatic_link = None
                    elif a:
                        if self.empty_link:
                            self.o("[")
                            self.empty_link = False
                            self.maybe_automatic_link = None
                        if self.inline_links:
                            try:
                                title = a['title'] if a['title'] else ''
                                title = escape_md(title)
                            except KeyError:
                                link_url(self, a['href'], '')
                            else:
                                link_url(self, a['href'], title)
                        else:
                            i = self.previousIndex(a)
                            if i is not None:
                                a = self.a[i]
                            else:
                                self.acount += 1
                                a['count'] = self.acount
                                a['outcount'] = self.outcount
                                self.a.append(a)
                            self.o("][" + str(a['count']) + "]")

        if tag == "img" and start and not self.ignore_images:
github JimmXinu / FanFicFare / included_dependencies / html2text / __init__.py View on Github external
def link_url(self, link, title=""):
            url = urlparse.urljoin(self.baseurl, link)
            title = ' "{0}"'.format(title) if title.strip() else ''
            self.o(']({url}{title})'.format(url=escape_md(url),
                                            title=title))