Ejemplo n.º 1
0
def convert_markdown_to_html(clean_md):
    """
    Take a string `clean_md` and return a string where the Markdown syntax is
    converted to HTML.
    """

    assert isinstance(clean_md, unicode), "Input `clean_md` is not Unicode"

    new_html = markdown.markdown(clean_md,
                                 output_format="xhtml1",
                                 extensions=[
                                     SmartEmphasisExtension(),
                                     FencedCodeExtension(),
                                     FootnoteExtension(),
                                     AttrListExtension(),
                                     DefListExtension(),
                                     TableExtension(),
                                     AbbrExtension(),
                                     Nl2BrExtension(),
                                     CodeHiliteExtension(
                                         noclasses=True,
                                         pygments_style=preferences.PREFS.get(
                                             const.MARKDOWN_SYNTAX_STYLE),
                                         linenums=preferences.PREFS.get(
                                             const.MARKDOWN_LINE_NUMS)),
                                     SaneListExtension()
                                 ],
                                 lazy_ol=False)

    assert isinstance(new_html, unicode)

    return new_html
Ejemplo n.º 2
0
def format_text(
    text,
    useMarkdown,
    markdownStyle,
    markdownLineNums,
    markdownTabLength,
):
    if useMarkdown:
        noclasses = markdownStyle != 'default'
        html_ish = markdown.markdown(
            text,
            output_format="xhtml1",
            extensions=[
                SmartEmphasisExtension(),
                FencedCodeExtension(),
                FootnoteExtension(),
                AttrListExtension(),
                DefListExtension(),
                TableExtension(),
                AbbrExtension(),
                Nl2BrExtension(),
                CodeHiliteExtension(noclasses=noclasses,
                                    pygments_style=markdownStyle,
                                    linenums=markdownLineNums),
                SaneListExtension(),
                SmartyExtension()
            ],
            lazy_ol=False,
            tab_length=markdownTabLength,
        )
    else:
        # Preserve whitespace.
        html_ish = text.replace('\n', '<br>').replace(' ', '&nbsp;')
    return html_ish
Ejemplo n.º 3
0
def parse_markdown(text, noclasses, style, line_nums, tab_len, mathext):
    extensions = []
    if mathext: extensions.append(MathExtension())
    extensions.extend([
        FencedCodeExtension(),
        FootnoteExtension(),
        AttrListExtension(),
        DefListExtension(),
        TableExtension(),
        AbbrExtension(),
        Nl2BrExtension(),
        CodeHiliteExtension(
            noclasses=noclasses,
            pygments_style=style,
            linenums=line_nums,
        ),
        SaneListExtension(),
        SmartyExtension()
    ])
    return markdown.markdown(
        text,
        output_format="xhtml1",
        extensions=extensions,
        lazy_ol=False,
        tab_length=tab_len,
    )
Ejemplo n.º 4
0
def editPage(pgid):
  page = Page.objects.get(id=pgid)
  text = bleach.clean(page.text)
  text = markdown.markdown(text, [WikiExtension(page), AttrListExtension()])
  if page.canEdit(g.user):
    return render_template('pages/editpage.html', page=page, text=text, form=PageImageForm())
  else:
    abort(403)
Ejemplo n.º 5
0
def viewPage(pgid):
  page = Page.objects.get(id=pgid)
  text = bleach.clean(page.text)
  text = markdown.markdown(text, [WikiExtension(page), AttrListExtension()])
  if page.canView(g.user):
    return render_template('pages/viewpage.html', page=page, text=text)
  else:
    abort(403)
Ejemplo n.º 6
0
def render_markdown(markdown_doc):
    """
        Render given markdown document and return (html, table_of_contents, meta)
    """

    md = markdown.Markdown(extensions=[
        TocExtension(baselevel=2, marker=''),
        AttrListExtension(),
        listStyleExtension(), 'meta'
    ])
    html = md.convert(markdown_doc.lstrip())
    toc = md.toc.replace('<a ', '<a class="list-group-item" ').replace(
        '<li', '<li class="doc-toc-item"')
    toc = "".join(
        toc.splitlines(True)[2:-2]
    )  # strip <div><ul> around toc by dropping first and last two lines
    meta = {k: ' '.join(v) for k, v in md.Meta.items()}
    return html, toc, meta
Ejemplo n.º 7
0
def grutorPreview():
    '''
  Funcion Type: Callback-AJAX Function
  Called By: grutor/gradesubmission.html:$("#previewBtn").click(...)
  Purpose: Produce HTML from a given markdown string.

  Inputs: None

  POST Values: A json object containing one field called "text" which contains
  the markdown formatted string.

  Outputs:
    res: The resulting html generated from the markdown
  '''
    content = request.get_json()
    html = markdown.markdown(bleach.clean(content["text"]),
                             [AttrListExtension()])
    return jsonify(res=html)
Ejemplo n.º 8
0
def pagePreview(pgid):
  '''
  Funcion Type: Callback-AJAX Function
  Called By: grutor/gradesubmission.html:$("#previewBtn").click(...)
  Purpose: Produce HTML from a given markdown string.

  Inputs:
    pgid: The page that this preview is of. This is used for dealing with links

  POST Values: A json object containing one field called "text" which contains
  the markdown formatted string.

  Outputs:
    res: The resulting html generated from the markdown
  '''
  content = request.get_json()
  try:
    pg = Page.objects.get(id=pgid)
    pg.text = bleach.clean(content["text"])
    html = markdown.markdown(pg.text, [WikiExtension(pg), AttrListExtension()])
    return jsonify(res=html)
  except Exception as e:
    return jsonify(res=str(e))
Ejemplo n.º 9
0
    if users.is_current_user_admin():
        return True

    try:
        if oauth.is_current_user_admin():
            return True
    except oauth.OAuthRequestError:
        pass

    return False


md = markdown.Markdown(
    extensions=[
        md_wikilink.WikiLinkExtension(),
        md_itemprop.ItemPropExtension(),
        md_url.URLExtension(),
        md_mathjax.MathJaxExtension(),
        md_strikethrough.StrikethroughExtension(),
        md_partials.PartialsExtension(),
        md_tables.TableExtension(),
        md_section.SectionExtension(),
        md_embed.EmbedExtension(),
        DefListExtension(),
        AttrListExtension(),
    ],
    safe_mode=False,
    smart_emphasis=False,
)
from flask import Flask
from flask import redirect, render_template, send_from_directory, url_for

from flask_login import UserMixin, LoginManager, login_user, logout_user
from flask_blogging import BloggingEngine
from flask_blogging.dynamodbstorage import DynamoDBStorage
from flask_fileupload.storage.s3storage import S3Storage
from flask_fileupload import FlaskFileUpload

from markdown.extensions.attr_list import AttrListExtension
from markdown.extensions.extra import ExtraExtension
from markdown.extensions.meta import MetaExtension


extn1 = AttrListExtension()
extn3 = ExtraExtension()
extn4 = MetaExtension()

app = Flask(__name__)

app.config["SECRET_KEY"] = "secret"  # for WTF-forms and login
app.config["BLOGGING_URL_PREFIX"] = "/blog"
# app.config["BLOGGING_DISQUS_SITENAME"] = "test"
app.config["BLOGGING_SITEURL"] = "http://localhost:8000"
app.config["BLOGGING_SITENAME"] = "Jeremy Clewell"
# app.config["BLOGGING_TWITTER_USERNAME"] = "******"
app.config["FILEUPLOAD_S3_BUCKET"]='jeremyclewell-site'
app.config["FILEUPLOAD_PREFIX"] = "/upload"
app.config["FILEUPLOAD_ALLOWED_EXTENSIONS"] = ["png", "jpg", "jpeg", "gif"]
app.config["BLOGGING_ESCAPE_MARKDOWN"] = False
app.config["BLOGGING_GOOGLE_ANALYTICS"] = "UA-15169356-1"