Пример #1
0
def markdown(value, autoescape=True):
    """Converts markdown text into html"""
    #if autoescape:
    #    esc = conditional_escape
    #else:
    #    esc = lambda x: x
    return mark_safe(md(conditional_escape(value)))
Пример #2
0
def markdown(s):
    s = s or ''
    return md(s, [
        'markdown.extensions.tables',
        'markdown.extensions.fenced_code',
        'markdown.extensions.codehilite',
    ])
Пример #3
0
 def save(self, *args, **kwargs):
     self.markdown = md(
         self.content,
         extensions=["fenced_code", "codehilite"],
     )
     self.slug = slugify(self.title)
     super().save(*args, **kwargs)
Пример #4
0
def parseMarkdown(
        path,
        outPath,
        articlesJsonPath,
        template,
        outpath=None,
        code_highlight=True,
        language_prefix="language-"):
    """parse markdown into html"""
    with open(path, encoding="utf-8") as f:
        src = f.read()

    title = (search(TITLE, src) or DummyMatch("タイトルなし")).group(1)
    description = (search(DESCRIPTION, src, MULTILINE | DOTALL) or DummyMatch("")).group(1)
    tags = (search(TAGS, src) or DummyMatch("")).group(1).split(',')
    date = (search(WRITTEN, src) or DummyMatch("")).group(1)
    src = sub(r"<!--(?:[^-]|-(?!->))*-->", "", src)
    addArticle(
        articlesJsonPath,
        Article(title, description, tags, date),
        outpath or splitext(basename(path))[0])
    if not exists(dirname(outPath)):
        makedirs(dirname(outPath))

    proc = md(output_format="html5", extensions=["fenced_code"])
    if code_highlight:
        src, tree = preprocess(src, language_prefix)
        proc.treeprocessors['syntax_highlighter'] = tree

    with open(outPath, 'w', encoding="utf-8") as f:
        f.write(template.format(
            title=title,
            article=proc.convert(src)))
Пример #5
0
def markdown(s):
    s = s or ''
    return md(s, [
        'markdown.extensions.tables',
        'markdown.extensions.fenced_code',
        'markdown.extensions.codehilite',
    ])
Пример #6
0
def markdown(s):
    s = md(s,
           extensions=[
               'markdown.extensions.fenced_code', 'markdown.extensions.tables'
           ])
    s = re.compile('<code[^>]*?>').sub('<code>', s)
    return s
Пример #7
0
def markdown(value):
    """
    Render text as Markdown.
    """
    # Strip HTML tags and render Markdown
    html = md(strip_tags(value), extensions=["fenced_code", "tables"])
    return mark_safe(html)
Пример #8
0
def export_pdf():
    if os.path.isfile("data/export/report.md"):
        print("Generating PDF report ...")
        with open("data/export/report.md", 'r') as f:
            html_text = md(f.read(), output_format="html4")
            pdfkit.from_string(html_text, "data/export/report.pdf")
    else:
        print("No pdf export possible: markdown report file missing.")
Пример #9
0
def markdown(value):
    """
    Run text through markdown process

    >>> markdown('*test*')
    Markup(u'<p><em>test</em></p>')
    """
    return Markup(md(value))
Пример #10
0
def markdown(raw):
    html = md(raw, extensions=['gfm'])
    if not html.strip():
        return html
    kill_tags = ['body', 'head', 'style']
    cleaner = Cleaner(kill_tags=kill_tags)
    html = cleaner.clean_html(html)
    return html
Пример #11
0
def markdown(raw):
    html = md(raw, extensions=['gfm'])
    if not html.strip():
        return html
    kill_tags = ['body', 'head', 'style']
    cleaner   = Cleaner(kill_tags = kill_tags)
    html      = cleaner.clean_html(html)
    return html
Пример #12
0
def text2md(value):
    '''
    convert markdown-like text to html.
    strip header <p> and footer </p> if p is True.
    '''
    returns = md(value, ['markdown.extensions.extra', HeaderIdExtension()])
    returns = BeautifulSoup(returns, 'html5lib').prettify()
    return returns
Пример #13
0
def parse_speaker(speaker, content):
    speaker = speaker.lower().title()
    p, created = Post.objects.get_or_create(
            thread=t, author=characters[speaker],
            content_plain=content)
    if created:
        p.content_html = sp(md(text=content, extensions=["nl2br"]))
        p.creation_date = datetime.datetime.now()  # UTC?
        p.save()
Пример #14
0
def parse_speaker(speaker, content):
    speaker = speaker.lower().title()
    p, created = Post.objects.get_or_create(thread=t,
                                            author=characters[speaker],
                                            content_plain=content)
    if created:
        p.content_html = sp(md(text=content, extensions=["nl2br"]))
        p.creation_date = datetime.datetime.now()  # UTC?
        p.save()
Пример #15
0
def strip_mdown(text):
    # Takes a Markdown-formatted string and returns it in plain text format

    from HTMLParser import HTMLParser
    from BeautifulSoup import BeautifulSoup as bs
    from markdown import markdown as md

    parser = HTMLParser()

    return parser.unescape(''.join(bs(md(text)).findAll(text=True)))
Пример #16
0
def markdown(value, header_level=1):
    html = md(value,
              output_format='html5', safe_mode='escape',
              extensions=[
                  TocExtension(baselevel=header_level),
                  CodeHiliteExtension(),
                  FencedCodeExtension(),
                  TableExtension(),
              ])
    return mark_safe(html)
Пример #17
0
def markdown(s, markup_wrap=False):
    s = s or ''
    s = md(s, [
        'markdown.extensions.tables',
        'markdown.extensions.fenced_code',
        'markdown.extensions.codehilite',
    ])
    if markup_wrap:
        s = Markup(s)
    return s
Пример #18
0
def markdown(s, markup_wrap=False):
    s = s or ''
    s = md(s, [
        'markdown.extensions.tables',
        'markdown.extensions.fenced_code',
        'markdown.extensions.codehilite',
    ])
    if markup_wrap:
        s = Markup(s)
    return s
Пример #19
0
 def save(self, *args, **kwargs):
     self.markdown = md(
         self.content,
         extensions=[
             'markdown.extensions.fenced_code',
             'markdown.extensions.codehilite',
         ],
     )
     self.slug = slugify(self.title)
     super().save(*args, **kwargs)
Пример #20
0
 def save_output(self, *args):
     path_url, _html = args
     file_name = f'{replace_symbols(path_url).rstrip("_")}.md'
     save_path = os.path.join(get_current_path(), 'output', path_url)
     full_file_path = os.path.join(save_path, file_name)
     if not os.path.exists(save_path):
         os.makedirs(save_path, exist_ok=True)
     with open(full_file_path, 'w', encoding='utf-8') as output:
         output.write(md(_html, base_url=self.base_url))
     logger.info(f'file: {full_file_path}')
Пример #21
0
def markdown(s):
    s = md(s,
           extensions=[
               'markdown.extensions.fenced_code', 'markdown.extensions.tables'
           ])
    s = re.compile('<code[^>]*?>').sub('<code>', s)
    if not check_dtd(s):
        raise Exception(
            'Unknown error about xml format caused by md translation, please email the file to [email protected]'
        )
    return s
Пример #22
0
def read_resume(markup=True):
    """
    Read the resume from disk.
    """
    with open('resume.yaml', 'r+') as f:
        resume = yaml.load(f)

    if markup:
        for exp in resume['experience']:
            exp['description'] = Markup(md(exp['description']))
    return resume
Пример #23
0
 def save(self, *args, **kwargs):
     self.message_rendered = md(self.message)
     super().save(*args, **kwargs)
     send_mail(
         'Hello from demo',
         self.message,
         '*****@*****.**',
         ['*****@*****.**'],
         fail_silently=False,
         html_message=self.message_rendered,
     )
Пример #24
0
def read_resume(markup=True):
    """
    Read the resume from disk.
    """
    with open("resume.yaml", "r+") as f:
        resume = yaml.load(f)

    if markup:
        for exp in resume["experience"]:
            exp["description"] = Markup(md(exp["description"]))
    return resume
Пример #25
0
    def markdown(text):
        jinja_env = jinja2.Environment()
        jinja_env.filters['media_url'] = media_url_func(site)
        jinja_env.filters['absolute_url'] = absolute_url_func(site)

        jinja_rendered = jinja_env.from_string(text).render()

        return md(
            jinja_rendered,
            tab_length=2,
            extensions=['markdown.extensions.fenced_code']
        )
Пример #26
0
def insert_markdown(document, markdown):
    """
    Insert markdown into docx document, best effort conversion
    """
    if not markdown:
        return
    html = md(
        markdown,
        extensions=['tables'],
    )
    root = etree.HTML(html)
    if root is None:
        return

    for element in root[0]:
        if element.tag == 'h1':
            document.add_heading(element.text, 1)
        elif element.tag == 'h2':
            document.add_heading(element.text, 2)
        elif element.tag == 'h3':
            document.add_heading(element.text, 3)

        elif element.tag == 'p':
            p = document.add_paragraph(element.text.strip())
            finish_paragraph(p, element)

        elif element.tag == 'ul':
            for li in element:
                p = document.add_paragraph(li.text, style='List Bullet')
                finish_paragraph(p, li)

        elif element.tag == 'ol':
            for li in element:
                p = document.add_paragraph(li.text, style='List Number')
                finish_paragraph(p, li)

        elif element.tag == 'table':
            thead = element[0]
            table = document.add_table(rows=0, cols=len(thead[0]))
            for td, cell in zip(thead[0], table.add_row().cells):
                cell.text = td.text

            tbody = element[1]
            for tr in tbody:
                for td, cell in zip(tr, table.add_row().cells):
                    cell.text = td.text

            format_table(table, top_color='d9d9d9')

        else:
            assert 0, element.tag
Пример #27
0
    def render(self, model=None, tmp_template=None, guess_model=False):
        config = getConfig()

        if not self.text:
            self.note = mw.col.newNote()
            return

        if tmp_template:
            template = tmp_template
        else:
            template = self.template

        if not model and not guess_model:
            note = mw.col.newNote()
        elif not model and guess_model and template.bestModel():
            best_model = mw.col.models.byName(template.bestModel())
            note = Note(mw.col, model=best_model)
        else:
            note = Note(mw.col, model=model)

        try:
            res = parse(template.gen(), self.text)
            parse_keys = res.named.keys()
        except:
            showInfo("Unable to Parse template")
            self.note = mw.col.newNote()
            return

        parse_to_key = {}
        for k in parse_keys:
            parse_to_key[k] = get_close_matches(k, template.keys())[0]

        key_to_fields, _ = template.getSimilarity(note.model()["name"])
        if not key_to_fields:
            showInfo("No mapping to Note has been found")
            return
        for k, v in res.named.items():
            if k == "Tags":
                # Uses the normal way Anki processes tag strings
                tags = mw.col.tags.canonify(mw.col.tags.split(v))
                note.tags += tags
            else:
                key = parse_to_key[k]
                if key in key_to_fields.keys():
                    field = key_to_fields[key]
                    if config["format"] == "markdown":
                        note[field] = md(v)
                    else:
                        note[field] = v

        self.note = note
Пример #28
0
def ajax_markdown_preview(request):
    d = {}
    if request.method == "POST":
        raw = request.POST.get('md','')
        raw.lstrip()
        html = md(raw, extensions=['gfm'])
        d['html'] = html
        d['code'] = 0
        d['msg']  = 'success'
        return HttpResponse(json.dumps(d),content_type="application/json")
    else:
        d['code'] = 1
        d['msg'] = 'invalid request method'
        return HttpResponse(json.dumps(d),content_type="application/json")
Пример #29
0
def waited(tv, *args):
    global mv_sec, content_
    mv_sec = None
    content_['doc-win'].hide()
    if tv.is_focus():
        winc = tv.window_to_buffer_coords(Gtk.TextWindowType.TEXT, args[0],
                                          args[1])
        it = tv.get_iter_at_location(winc[0], winc[1])[1]
        it2 = tv.get_iter_at_location(winc[0], winc[1])[1]
        if tv.get_iter_at_location(winc[0], winc[1])[0]:
            while 1:
                if it.get_char().isalpha() or it.get_char().isdigit(
                ) or it.get_char() == "_":
                    if not it.forward_char():
                        break
                elif it.get_char().isspace():
                    break
                else:
                    if not it.forward_char():
                        break
            while 1:
                if it2.get_char().isalpha() or it2.get_char().isdigit(
                ) or it2.get_char() == "_":
                    if not it2.backward_char():
                        break
                    pass
                elif it2.get_char().isspace():
                    break
                else:
                    if not it2.backward_char():
                        break

            it.backward_char()
            it2.forward_char()
            text = tv.get_buffer().get_text(it, it2, True)
            doc = _get_doc(text, tv.get_buffer(),
                           (it.get_line(), it2.get_line_index()))
            if len(doc) != 0:
                if len(doc[0].docstring(False)) > 0:
                    print(docstring_summary(doc[0].docstring(False)))
                    text = "<head><style>body{background-color: rgb(30,30,30);color: rgb(210,210,210);}code{background-color: rgb(90,90,90);border-radius: 2px;}</style>\
                        </head>\
                        <body> \n"                                   + md(str(doc[0].docstring(True)), extensions=["fenced_code", 'codehilite'])\
                        + "</body>".replace("\n","<br>")
                    content_['webview'].load_html(text)
                    #print(text)
                    content_['doc-win'].move(args[2][0], args[2][1])
                    content_['doc-win'].show()
                    content_['webview'].show_all()
    return False
Пример #30
0
def line2md(value, p=True):
    # convert all `<>` brackets to html symbol to make it html-safe.
    returns = re.sub("<", "&lt;", value)
    returns = re.sub(">", "&gt;", returns)
    returns = re.sub("(?<= ) ", "&nbsp;", returns)

    # prevent lists
    returns = re.sub("^([*+-]) ", r"\\\1 ", returns)
    returns = re.sub(r"^(\d+)\. ", r"\1\\. ", returns)

    # allow raw-text editing
    returns = re.sub("\n", "<br>", returns)
    returns = md(returns, ['markdown.extensions.extra'])
    returns = re.sub(r"</?p>", "", returns)
    return returns
Пример #31
0
Файл: home.py Проект: lsma/kwky
def render_card(card):
    title = escape(card.title)
    image = card.image.url if card.image else None
    content = mark_safe(md(conditional_escape(card.content)))
    button = card.button

    if content:
        image_height = 100
    else:
        image_height = 180

    return {'title': title,
            'image': image,
            'content': content,
            'button': button,
            'image_height': image_height,}
Пример #32
0
def markdown(*args, **kwargs):
    """
    Render input string(s) as markdown

    Parameters
    *args : str or list of strings
        String(s) to render as markdown
    **kwargs : any
        arguments supported by the markdown class

    """
    return ipywidgets.HTML(
        md(
            '\n'.join(args),
            **kwargs
        )
    )
Пример #33
0
def read_resume(markup=True):
    """
    Read the resume from disk.
    """
    with open("resume.yaml", "r+") as f:
        resume = yaml.safe_load(f)

    elaboration_content = [
        "experience",
        "education",
        "skills",
    ]

    if markup:
        for content in elaboration_content:
            for i, section in enumerate(resume[content]):
                resume[content][i]["elaboration"] = Markup(md(section["elaboration"]))
    return resume
Пример #34
0
def mdtext(text):
    mdbody = re.sub(
        '\\[\\[(.*?)\\]\\]',
        lambda match: generate_article_link(match.group(1)),
        text
        )

    mdbody = md(
        mdbody,
        extensions=[
            'markdown.extensions.tables',
            'markdown.extensions.footnotes'
        ],
        output_format='html5'
        )

    return bleach.clean(
        mdbody,
        tags=ALLOWED_TAGS
        )
Пример #35
0
	def sanitise(self, text, markdown = True):
		if markdown:
			text = md(text)
		
		dom = PyQuery(text)
		
		for a in dom.find('a[href^="javascript:"]'):
			a = PyQuery(a)
			a.replaceWith(a.text())

		for obj in UNCLEAN_TAGS:
			dom.find(obj).remove()

		for attr in UNCLEAN_ATTRS:
			dom.find('[%s]' % attr).removeAttr(attr)
		
		text = dom.outerHtml()
		if markdown:
			dom = HTML2Text()
			text = dom.handle(text)

		return text
Пример #36
0
def sanitise(text, markdown=False):
    if markdown:
        text = md(text)

    dom = PyQuery(text)

    for a in dom.find('a[href^="javascript:"]'):
        a = PyQuery(a)
        a.replaceWith(a.text())

    for obj in UNCLEAN_TAGS:
        dom.find(obj).remove()

    for attr in UNCLEAN_ATTRS:
        dom.find('[%s]' % attr).removeAttr(attr)

    text = dom.outerHtml()
    if markdown:
        dom = HTML2Text()
        text = dom.handle(text)

    return text
Пример #37
0
def markdown (value):
	return Markup(md(value))
Пример #38
0
def get_html_version(file_path):
    with open("./{}".format(file_path)) as f:
        html = Markup(md(f.read(), extensions=['gfm']))
    return html
Пример #39
0
def api_index():
    return flask.make_response(md(open('README.md','r').read()))
Пример #40
0
def gfm_markdown(value):
    from markdown import markdown as md
    html = md(value,extensions=['gfm'])
    return mark_safe(html)
Пример #41
0
def markdown(text):
    # FIXME: add postprocess step to transform 'http://' into a link
    # strip p tags
    return md(text)[3:-4]
Пример #42
0
def markdown(post):
  page = linkname(post.category.name)
  prefix = 'https://s3.amazonaws.com/vineel.me/%s/' % post.id
  return Markup(md(post.body, ['awsimage(PREFIX=%s)' % prefix, 'syntax']))
Пример #43
0
 def parsed(self):
     return md(self.content)
Пример #44
0
	def parsed(self):
		return md(self.content)
Пример #45
0
def markdown(content):
	return a_blank(md(content))
Пример #46
0
	def parsed_lead(self):
		return md(self.lead)
Пример #47
0
def markdown(s, markup_wrap=False):
    s = s or ""
    s = md(s, ["markdown.extensions.tables", "markdown.extensions.fenced_code", "markdown.extensions.codehilite"])
    if markup_wrap:
        s = Markup(s)
    return s
Пример #48
0
def markdown(value):
    return md(value)
def markdown(value):
    return md(value, extensions=['markdown.extensions.fenced_code'])
Пример #50
0
def markdown(s):
    s = md(s, extensions=['markdown.extensions.fenced_code', 'markdown.extensions.tables'])
    s = re.compile('<code[^>]*?>').sub('<code>', s)
    return s
Пример #51
0
 def parsed_lead(self):
     return md(self.lead)
Пример #52
0
def markdown(s):
    return md(s.decode('utf-8'),
              ['headerid(level=2)', 'def_list']).encode('utf-8')
Пример #53
0
def markdown(infile):
    return md(peek(infile), output_format='xhtml5', extensions=[ 'markdown.extensions.extra' ])
Пример #54
0
def markdown(value):
    return mark_safe(md(value))
Пример #55
0
program_specs = {
    "title": "Program Specifications",
    "container_id": "spec",

    "revision_history": [{
        "last_update": "10/28/2011",
        "author": "Adam Lukens",
        "description": "Initial Creation"
    }],

    "assumptions": "Document any assumptions made during the design of the program.",

    "program_specs_intro": """Program Specifications description goes here.""",
    
    "modules": [
        Opt({
            "name": "network_server.c",
            "purpose": "Server wrapping code",
            "prerequisites": "N/A",
            "function": "handle_new_connection()",
            "description": 
md(r"""
<pre>void handle_new_connection() {
    int listnum;    /* Current item in connectlist for for loops */
    int connection; /* Socket file descriptor for incoming connections */

    /* We have a new connection coming in!  We'll
    try to find a spot for it in connectlist. */
    connection = accept(sock, NULL, NULL);

    if (connection < 0) {
        <span class="addition">perror("accept");</span>
        exit(EXIT_FAILURE);
    }

    setnonblocking(connection);

    for (listnum = 0; (listnum < 5) && (connection != -1); listnum++)
        if (connectlist[listnum] == 0) {
            <span class="addition">printf("\nConnection accepted:   FD=%d; Slot=%d\n",
                connection,listnum);</span>
            <span class="deletion">printf("\nConnection accepted:   FD=%d\n",
                connection,listnum);</span>
            connectlist[listnum] = connection;
            connection = -1;
        }

    if (connection != -1) {
        /* No room left in the queue! */
        printf("\nNo room left for new client.\n");
        sock_puts(connection,"Sorry, this server is too busy.  "
                    Try again later!\r\n");
        close(connection);
    }
}</pre>
""")
        }),
        Opt({
            "name": "network_client.java",
            "purpose": "Client wrapping code",
            "prerequisites": "N\A",
            "input": "",
            "output": "",
            "system_parms": "",
            "function": "client_connect()",
            "description":
            r"""<pre>// Create a socket without a timeout
    try {
        InetAddress addr = InetAddress.getByName("java.sun.com");
        <span class="addition">int port = 80;</span>

        // This constructor will block until the connection succeeds
        <span class="deletion">Socket socket = new Socket(addr, 80);</span>
        <span class="addition">Socket socket = new Socket(addr, port);</span>
    } catch (UnknownHostException e) {
    } catch (IOException e) {
    }

    // Create a socket with a timeout
    try {
        InetAddress addr = InetAddress.getByName("java.sun.com");
        <span class="addition">int port = 80;</span>
        <span class="deletion">SocketAddress sockaddr = new InetSocketAddress(addr, 80);</span>
        <span class="addition">SocketAddress sockaddr = new InetSocketAddress(addr, port);</span>

        // Create an unbound socket
        Socket sock = new Socket();

        // This method will block no more than timeoutMs.
        // If the timeout occurs, SocketTimeoutException is thrown.
        int timeoutMs = 2000;   // 2 seconds
        sock.connect(sockaddr, timeoutMs);
    } catch (UnknownHostException e) {
    } catch (SocketTimeoutException e) {
    } catch (IOException e) {
    }"""
        }),
    ]
}
Пример #56
0
def markdown(s):
    return md(s, ['markdown.extensions.tables'])
Пример #57
0
def markdown(text):
    return mark_safe(md(text))
def markdown(value):
    """Renders the text as markdown"""
    return mark_safe(md(value))