예제 #1
0
파일: events.py 프로젝트: lsma/kwky
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
파일: utils.py 프로젝트: fzeeshan/dashed
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
파일: tools.py 프로젝트: de8ug/LocalNote
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
파일: views.py 프로젝트: suesan/uknow
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
파일: views.py 프로젝트: suesan/uknow
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
파일: markdown.py 프로젝트: heyrict/cindy
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
파일: util.py 프로젝트: nickpegg/posty
    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
파일: markdown.py 프로젝트: heyrict/cindy
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
파일: app.py 프로젝트: ericmjl/resume
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
파일: server.py 프로젝트: dethos/mdvis
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
파일: sotoki.py 프로젝트: dattaz/sotoki
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
파일: dienw.py 프로젝트: GunioRobot/Dienw
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
파일: stories.py 프로젝트: stett/storygame
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
파일: vote_tags.py 프로젝트: colons/nkd.su
def markdown(text):
    return mark_safe(md(text))
def markdown(value):
    """Renders the text as markdown"""
    return mark_safe(md(value))