def irc_md(): """This makes a converter from markdown to mirc color format.""" md = Markdown(output_format="irc", extensions=[ExtraExtension(), AnsiExtension()]) md.stripTopLevelTags = False return md
def to_html(self, md_exts: list = None) -> str: if md_exts is None: md_exts = [ExtraExtension()] content_txt = self._extract_block(self.source_text, "content") html = markdown.markdown(content_txt, extensions=md_exts) html = self._append_target_equals_blank(html) return html
def __init__(self): self.exts=[ ExtraExtension(), TocExtension(slugify=lambda value, separator: urllib.parse.quote(value)), Nl2BrExtension(), SuperFencesCodeExtension() ]
def detail(slug): r = db_posts.scan(FilterExpression='published = :b AND slug = :s', ExpressionAttributeValues={ ":b": True, ":s": slug }) if len(r) > 0: post = r['Items'][0] # convert post content to HTML hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() post['content'] = markdown(post['content'], extensions=[hilite, extras]) post['content'] = parse_html(post['content'], oembed_providers, urlize_all=True, maxwidth=app.config['SITE_WIDTH']) post['content'] = Markup(post['content']) return render_template('detail.html', post=post) else: flash('Post not found.', 'danger') return redirect(url_for('home'))
def html_content(self): # This function will be used to turn our biography into html code hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() content = self.converter() markdown_content = markdown(content, extensions=[hilite, extras]) return Markup(markdown_content)
def get(name=""): if not name: raise ErrInvalidName("Please provide a post name") # Parse the entry file, the file should follow the following template: # key: value with open(f"{CONTENT_DIR}/{name}.md", "r", encoding="utf-8") as input_file: text = input_file.read() hilite = CodeHiliteExtension(linenums=False, css_class="highlight") extras = ExtraExtension() md = markdown.Markdown(extensions=["meta", "fenced_code", hilite, extras], output_format="html5") html = md.convert(text) # Clean up the meta format meta = {key.lower(): value[0] for key, value in md.Meta.items()} summary = app.util.get_summary(html) if "direciton" not in meta: try: meta["direciton"] = "rtl" if langdetect.detect( summary) == "ar" else "ltr" except: meta["direciton"] = "ltr" if "cover" not in meta: meta["cover"] = app.util.get_cover(html) body = {"content": html, "summary": summary} return {**meta, **body}
def html_content(self): hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True) return Markup(oembed_content)
def html_content(self): hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) oembed_content = parse_html(markdown_content, urlize_all=True, maxwidth=app.config['SITE_WIDTH']) return Markup(oembed_content)
def xhtml(): """This makes a converter from markdown to xhtml format. It can be called like this: from errbot.rendering import xhtml md_converter = xhtml() # you need to cache the converter html = md_converter.convert(md_txt) """ return Markdown(output_format='xhtml', extensions=[ExtraExtension()])
def slack_markdown_converter(compact_output=False): """ This is a Markdown converter for use with Slack. """ enable_format('imtext', IMTEXT_CHRS, borders=not compact_output) md = Markdown(output_format='imtext', extensions=[ExtraExtension(), AnsiExtension()]) md.preprocessors['LinkPreProcessor'] = LinkPreProcessor(md) md.stripTopLevelTags = False return md
def html_content(self): """ parses markdown content """ hil = CodeHiliteExtension(linenums=True, css_class='highlight') extra = ExtraExtension() mrkdwn_content = markdown(self.text, extensions=[hil, extra]) oembed_content = parse_html( mrkdwn_content, OEMBED_PROVIDERS, urlize_all=True) return Markup(oembed_content)
def html_content(self): """ Generate HTML representation of the markdown-formatted note, and also convert any media URLs into rich media objects such as video players or images. """ hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) return Markup(markdown_content)
def html_content(self): # todo: research what all these things do hilite = CodeHiliteExtension(linenums=False, css_class="highlight") extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True, maxwidth=app.config["SITE_WIDTH"]) return Markup(oembed_content)
def slack_markdown_converter(): """ This is a Markdown converter for use with Slack. """ md = Markdown(output_format='imtext', extensions=[ExtraExtension(), AnsiExtension()]) md.preprocessors['LinkPreProcessor'] = LinkPreProcessor(md) md.stripTopLevelTags = False return md
def html_content(text): hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(text, extensions=[hilite, extras]) oembed_providers = bootstrap_basic(OEmbedCache()) oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True, maxwidth=SITE_WIDTH) return Markup(oembed_content)
def borderless_ansi(): """This makes a converter from markdown to ansi (console) format. It can be called like this: from errbot.rendering import ansi md_converter = ansi() # you need to cache the converter ansi_txt = md_converter.convert(md_txt) """ md = Markdown(output_format='borderless', extensions=[ExtraExtension(), AnsiExtension()]) md.stripTopLevelTags = False return md
def html_content(self): hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True, maxwidth=app.config["SITE_WIDTH"]) return Markup( oembed_content ) # The Markup object tells Flask that we trust the HTML content, so it will not be escaped when rendered in the template.
def markdown_content(self): ''' Convert markdown content into html ''' hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) return Markup(markdown_content)
def markdown_filter(text): """ Convert markdown to html """ md2html = markdown(text, extensions=[CodeHiliteExtension(linenums=False, css_class='highlight'), ExtraExtension(), SaneListExtension(), SmartyExtension(smart_dashes=True, smart_quotes=False, smart_angled_quotes=False, smart_ellipses=False)]) safe_html = sanitize_html(md2html) return Markup(safe_html)
def html_content(self): """Parse article bosy for markup and features.""" hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.body, extensions=[hilite, extras]) oembed_providers = bootstrap_basic(OEmbedCache) oembed_content = parse_html( markdown_content, oembed_providers, urlize_all=True) return Markup(oembed_content)
def text(): """This makes a converter from markdown to text (unicode) format. It can be called like this: from errbot.rendering import text md_converter = text() # you need to cache the converter pure_text = md_converter.convert(md_txt) """ from .ansiext import AnsiExtension md = Markdown(output_format='text', extensions=[ExtraExtension(), AnsiExtension()]) md.stripTopLevelTags = False return md
def html_content(self): """ Generate HTML representation of the markdown-formatted blog entry, and also convert any media URLs into rich media objects such as video players or images.""" hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True, maxwidth=app.config['SITE_WIDTH']) return Markup(oembed_content)
def html_content(self): # This function will be use to turn our post content into html hilite = CodeHiliteExtension(linenums=False, css_class='highlight') extras = ExtraExtension() content = self.converter() markdown_content = markdown(content, extensions=[hilite, extras]) # oembed_content = parse_html( # markdown_content, # oembed_providers, # urlize_all=True, # maxwidth=SITE_WIDTH) return Markup(markdown_content)
def imtext(): """This makes a converter from markdown to imtext (unicode) format. imtest is the format like gtalk, slack or skype with simple _ or * markup. It can be called like this: from errbot.rendering import imtext md_converter = imtext() # you need to cache the converter im_text = md_converter.convert(md_txt) """ from .ansiext import AnsiExtension md = Markdown(output_format='imtext', extensions=[ExtraExtension(), AnsiExtension()]) md.stripTopLevelTags = False return md
def html_content_preview(self, limit): hilite = CodeHiliteExtension(linenums=False, css_class="highlight") extras = ExtraExtension() # adding ellipsis if necessary, otherwise entire content is the preview if (len(self.content) <= limit): markdown_content = markdown(self.content, extensions=[hilite, extras]) else: markdown_content = markdown(self.content[:limit - 3] + "…", extensions=[hilite, extras]) oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True, maxwidth=app.config["SITE_WIDTH"]) return Markup(oembed_content)
def get(name=""): if not name: raise ErrInvalidName("Please provide a book name") # Parse the entry file, the file should follow the following template: # key: value with open(f"{CONTENT_DIR}/{name}.md", "r", encoding="utf-8") as input_file: text = input_file.read() hilite = CodeHiliteExtension(linenums=False, css_class="highlight") extras = ExtraExtension() md = markdown.Markdown(extensions=["meta", "fenced_code", hilite, extras], output_format="html5") html = md.convert(text) meta = {key: value[0] for key, value in md.Meta.items()} body = {"content": html} return {**meta, **body}
def util_html_content(self): """Converts markdown into html and media urls into embeds. Generates HTML representation of the markdown-formatted blog entry, and also convert any media URLs into rich media objects such as video players or images. Returns ------- class 'flask.Markup' Returns markup objects so that the passed string can't be double escaped. """ hilite = CodeHiliteExtension(linenums=False) extras = ExtraExtension() markdown_content = markdown(self.content, extensions=[hilite, extras]) oembed_content = parse_html( markdown_content, oembed_providers, urlize_all=True) # If your returned 'oembed_content' without using 'Markup()' the html # would be shown as text on the page instead of being rendered. return Markup(oembed_content)
def html_content(self): # used for code/syntax highlighting # css_class -- name of css class used for div hilite = CodeHiliteExtension(linenums=True, css_class='highlight') # all the extensions found here: # https://python-markdown.github.io/extensions/extra/ extras = ExtraExtension() # utilizes the above extensions and converts the markdown to html markdown_content = markdown(self.content, extensions=[hilite, extras]) # parse_html -- Parse HTML intelligently, rendering items on their own # within block elements as full content (e.g. a video player) # urlize_all -- constructs a simple link when provider is not found oembed_content = parse_html(markdown_content, oembed_providers, urlize_all=True, maxwidth=app.config['SITE_WIDTH']) # Markup returns a string that is ready to be safely inserted into # an HTML document return Markup(oembed_content)
def html_content(self): code_css_class = "friendly" hilite = CodeHiliteExtension(linenums=False, noclasses=True, pygments_style=code_css_class) extras = ExtraExtension() pre_sanistised_markup = Markup(self.content) markdown_content = markdown(pre_sanistised_markup, extensions=[hilite, extras]) post_sanitised_markup = bleach.clean(markdown_content, tags=markdown_tags, attributes=markdown_attributes, styles=markdown_styles, strip=False) oembed_content = parse_html(post_sanitised_markup, oembed_providers, urlize_all=True, maxwidth=app.config['SITE_WIDTH']) post_markup = Markup(oembed_content) return post_markup
def __init__(self): self.markdown = Markdown(extensions=[ ExtraExtension(), TocExtension(), CodeHiliteExtension(guess_lang=False), ])