How to use the markdownify.MarkdownConverter function in markdownify

To help you get started, we’ve selected a few markdownify 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 FrenchMasterSword / RTFMbot / plugins / _ref.py View on Github external
import urllib.parse
from functools import partial
# import sys

import aiohttp
import discord
from bs4 import BeautifulSoup
from bs4.element import NavigableString
from markdownify import MarkdownConverter


# sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import _used


class DocMarkdownConverter(MarkdownConverter):
    # def convert_code(self, el, text):
    #     """Undo `markdownify`s underscore escaping."""
    #     print(el)
    #     print(el.strings)
    #     print(text)

    #     return f"`{text}`".replace('\\', '')

    def convert_pre(self, el, text):
        """Wrap any codeblocks in `py` for syntax highlighting."""

        code = ''.join(el.strings)

        return f"```py\n{code}```"
github skoczen / will / will / backends / io_adapters / slack.py View on Github external
from will import settings
from .base import IOBackend
from will.utils import Bunch, UNSURE_REPLIES, clean_for_pickling
from will.mixins import SleepMixin, StorageMixin
from multiprocessing import Process
from will.abstractions import Event, Message, Person, Channel
from slackclient import SlackClient
from slackclient.server import SlackConnectionError

SLACK_SEND_URL = "https://slack.com/api/chat.postMessage"
SLACK_SET_TOPIC_URL = "https://slack.com/api/channels.setTopic"
SLACK_PRIVATE_SET_TOPIC_URL = "https://slack.com/api/groups.setTopic"


class SlackMarkdownConverter(MarkdownConverter):

    def convert_strong(self, el, text):
        return '*%s*' % text if text else ''


class SlackBackend(IOBackend, SleepMixin, StorageMixin):
    friendly_name = "Slack"
    internal_name = "will.backends.io_adapters.slack"
    required_settings = [
        {
            "name": "SLACK_API_TOKEN",
            "obtain_at": """1. Go to https://api.slack.com/custom-integrations/legacy-tokens and sign in as yourself (or a user for Will).
2. Find the workspace you want to use, and click "Create token."
3. Set this token as SLACK_API_TOKEN."""
        }
    ]
github python-discord / bot / bot / cogs / doc.py View on Github external
async def wrapper(*args) -> Any:
            """Decorator wrapper for the caching logic."""
            key = ':'.join(args[arg_offset:])

            value = async_cache.cache.get(key)
            if value is None:
                if len(async_cache.cache) > max_size:
                    async_cache.cache.popitem(last=False)

                async_cache.cache[key] = await function(*args)
            return async_cache.cache[key]
        return wrapper
    return decorator


class DocMarkdownConverter(MarkdownConverter):
    """Subclass markdownify's MarkdownCoverter to provide custom conversion methods."""

    def convert_code(self, el: PageElement, text: str) -> str:
        """Undo `markdownify`s underscore escaping."""
        return f"`{text}`".replace('\\', '')

    def convert_pre(self, el: PageElement, text: str) -> str:
        """Wrap any codeblocks in `py` for syntax highlighting."""
        code = ''.join(el.strings)
        return f"```py\n{code}```"


def markdownify(html: str) -> DocMarkdownConverter:
    """Create a DocMarkdownConverter object from the input html."""
    return DocMarkdownConverter(bullets='•').convert(html)

markdownify

Convert HTML to markdown.

MIT
Latest version published 28 days ago

Package Health Score

88 / 100
Full package analysis

Similar packages