本文整理汇总了Python中misaka.html函数的典型用法代码示例。如果您正苦于以下问题:Python html函数的具体用法?Python html怎么用?Python html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了html函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, *args, **options):
names = os.listdir("docs/other")
paths = [os.path.join("docs/other", x) for x in names]
paths += ["README.md"]
mkdir_p("docs/static/docs/img")
for path in paths:
text = "".join(open(path, "r").readlines())
if path.endswith("_plain.md"):
c = Context({
"docs": misaka.html(text),
"STATIC_URL": settings.STATIC_URL,
})
t = loader.get_template("docs/content.html")
page = os.path.split(path)[1].replace("_plain.md", ".html")
else:
tree = misaka.html(text, render_flags=misaka.HTML_TOC_TREE)
body = misaka.html(text, render_flags=misaka.HTML_TOC)
c = Context({
"toc": postprocess_toc(tree, "#"),
"docs": postprocess_toc(body, 'id="'),
"STATIC_URL": settings.STATIC_URL,
})
t = loader.get_template("docs/index.html")
page = os.path.split(path)[1].replace(".md", ".html")
page = page.replace("README", "technical")
with open(os.path.join("docs/static/docs", page), "w") as f:
rendered = t.render(c)
new_rendered = self.get_and_replace_images(rendered)
f.write(new_rendered)
示例2: postRead
def postRead(args=dict()):
getPostList = post.getPostList(boardname=args.get('board'))
if(getPostList is None):
viewPost = {'postSrl': 'getPost.postSrl', 'postTitle': 'getPost.title', 'postText': 'getPost.text', 'postWriter': 'getPost.writer', 'postWriten': 'getPost.writeTime', 'files': 'getPost.files'}
else:
postList = list()
for getPost in getPostList:
t = time.localtime(getPost.writeTime)
writen = str(t[1])+'월'+str(t[2])+'일 '+str(t[3])+':'+str(t[4])
rendered = misaka.html(getPost.text)
commentList = comment.getComment(getPost.postSrl)
comments = list()
for commentTemp in commentList:
ct = time.localtime(commentTemp.writeTime)
commentWriten = str(ct[1])+'월'+str(ct[2])+'일 '+str(ct[3])+':'+str(ct[4])
commentR = misaka.html(commentTemp.comment)
temp = {'commentWriter': commentTemp.writer, 'commentWriten': commentWriten, 'comment': commentR, 'commentSrl': commentTemp.commentSrl}
comments.append(temp)
fileDict = fileUploader.serving(getPost.files)
viewPost = {'postSrl': getPost.postSrl, 'postTitle': getPost.title, 'postText': rendered,\
'postWriter': getPost.writer, 'postWriten': writen,\
'board': getPost.board, 'commentCount': getPost.commentCount,\
'comments': comments, 'fileList': fileDict}
postList.append(viewPost)
postList.reverse()
return render_template('postView.jinja', postList=postList, isBoard=True, getBoard=args.get('board'))
示例3: save
def save(self, *args, **kwargs):
self.intro_html = mi.html(self.intro,
extensions=mi.EXT_NO_INTRA_EMPHASIS | mi.EXT_FENCED_CODE | mi.HTML_HARD_WRAP)
self.body_html = mi.html(self.body,
extensions=mi.EXT_NO_INTRA_EMPHASIS | mi.EXT_FENCED_CODE | mi.HTML_HARD_WRAP)
self.transcript_html = mi.html(self.transcript,
extensions=mi.EXT_NO_INTRA_EMPHASIS | mi.EXT_FENCED_CODE | mi.HTML_HARD_WRAP)
super(Translation, self).save(*args, **kwargs)
示例4: post
def post(self):
timeLimit = int(self.get_argument("timeLimit", ""))*1000
stars = int(self.get_argument("stars", ""))
title = self.get_argument("title", "")
proDes = misaka.html( self.get_argument("proDes", "") )
inputDes = misaka.html( self.get_argument("inputDes", "") )
outputDes = misaka.html( self.get_argument("outputDes", "") )
sapInput = self.get_argument("sapInput", "")
sapOutput = self.get_argument("sapOutput", "")
author = self.get_argument("author", "")
recommend = misaka.html( self.get_argument("recommend", "") )
testInput = self.request.files["inputfile"][0]["body"].replace("\r\n", "\n")
testOutput = self.request.files["outputfile"][0]["body"].request("\r\n", "\n")
print testInput
if timeLimit != "" and stars != "" \
and title != "" and proDes != "" \
and inputDes != "" and outputDes != "" \
and sapInput != "" and sapOutput != "" \
and author != "" \
and testInput != None and testOutput != None:
print "Adding Problem:", \
"\ntimeLimit:\n", timeLimit, \
"\nstarts:\n", stars, \
"\ntitle:\n", title, \
"\nproDes:\n", proDes, \
"\ninputDes:\n", inputDes, \
"\noutputDes:\n", outputDes, \
"\nsapInput:\n", sapInput, \
"\nsapOutput:\n", sapOutput, \
"\nauthor:\n", author, \
"\nrecommend:\n", recommend, "\n"
proID = self.application.problemCnt + 1001
self.application.problemCnt += 1
self.application.problemSet.addProblemItem(proID, title, stars, proDes,\
inputDes, outputDes, sapInput, sapOutput,\
recommend, author, timeLimit)
dirName = "./judgefile/%s" % proID
if os.path.exists(dirName) == False:
os.makedirs(dirName)
finput = open("%s/%s.in" % (dirName, proID), "w")
foutput = open("%s/%s.out" % (dirName, proID), "w")
finput.write(str(testInput))
foutput.write(str(testOutput))
print testOutput
finput.close()
foutput.close()
self.render('addProblem.html', addOK=True)
return
self.render('addProblem.html', addOK=False)
示例5: save
def save(self, *args, **kwargs):
if not self.pk:
self.created_at = timezone.now()
if self.excerpt:
self.excerpt_html = misaka.html(self.excerpt)
self.content_html = misaka.html(self.content)
super(Post, self).save(*args, **kwargs)
示例6: test_misaka
def test_misaka(self):
import misaka
extensions = (
'no-intra-emphasis',
'fenced=code',
'autolink',
'tables',
'strikethrough',
)
misaka.html(self.text, extensions)
示例7: benchmark_misaka
def benchmark_misaka(text):
import misaka as m
# mistune has all these features
extensions = (
m.EXT_NO_INTRA_EMPHASIS | m.EXT_FENCED_CODE | m.EXT_AUTOLINK |
m.EXT_TABLES | m.EXT_STRIKETHROUGH
)
# md = m.Markdown(m.HtmlRenderer(), extensions=extensions)
# md.render(text)
m.html(text, extensions)
示例8: _parse_meta
def _parse_meta(self, header, body):
header = m.html(to_unicode(header))
titles = re.findall(r'<h1>(.*)</h1>', header)
if not titles:
logging.error('There is no title')
title = None
else:
title = titles[0]
meta = {'title': title}
items = re.findall(r'<li>(.*?)</li>', header, re.S)
for item in items:
index = item.find(':')
key = item[:index].rstrip()
value = item[index + 1:].lstrip()
meta[key] = value
desc = re.findall(r'<p>(.*?)</p>', header, re.S)
if desc:
meta['description'] = '\n\n'.join(desc)
#: keep body in meta data as source text
meta['source_text'] = body
_toc = m.Markdown(m.HtmlTocRenderer(), 0)
meta['toc'] = _toc.render(body)
return meta
示例9: getRevealMarkdown
def getRevealMarkdown(self):
# Remove non-ASCII characters from markdown, these appear when reading from the wiki
# (http://stackoverflow.com/questions/8689795/python-remove-non-ascii-characters-but-leave-periods-and-spaces)
self.markdown = filter(lambda x: x in string.printable, self.markdown)
# Convert the markdown to HTML using misaka which is a python wrapper utilizing the same
# parser as GitHub
# (https://gist.github.com/fyears/5097469)
html = misaka.html(self.markdown,
extensions = misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_FENCED_CODE |
misaka.EXT_AUTOLINK |
misaka.EXT_TABLES,
render_flags = misaka.HTML_USE_XHTML | misaka.HTML_HARD_WRAP)
# Convert the Remark.js style blocks to spans
html = re.sub(r'<p>\.(.*?)\[</p>', self._startSpan, html)
html = re.sub(r'<p>\]</p>', '</span>', html)
# Create the html output suitable for Reveal.js
output = ''
output += ' '*10 + '<section id="' + self.name() + '">\n'
output += html
output += ' '*10 + '</section>\n'
return output
示例10: note
def note(self, name=None, title=None, raw=None, tags=None):
cherrypy.response.headers['Content-Type'] = 'text/html'
vals = {}
if cherrypy.request.method == 'GET':
if name is not None:
vals['title'] = name
try:
vals['raw'] = self.load_note(name)
except IOError:
pass
elif cherrypy.request.method == 'POST':
if name is not None and name != title:
self.rename_note(name, title, raw, tags)
else:
self.save_note(title, raw, tags)
vals['title'] = title
vals['raw'] = raw
if 'raw' in vals:
vals['body'] = misaka.html(vals['raw'], self.markdown_extensions)
if 'title' in vals:
vals['tags'] = self.get_tags(vals['title'])
return bytes(self.template_env.get_template('note.html')
.render(vals), 'utf-8')
示例11: markdownToHtml
def markdownToHtml(markdownStr):
"""
Converts Markdown to HTML. Supports GitHub's fenced code blocks,
auto linking and typographic features by SmartyPants.
"""
return misaka.html(markdownStr, misakaExt, misakaRender)
示例12: contentView
def contentView(name):
import datetime
pageList = pagelist()
updateList = commitList()
if os.path.splitext(name)[1] != '.ico':
try:
fullpath = os.path.join(path, name+'.md')
f = codecs.open(
fullpath,
'r',
encoding='utf-8')
pageTitle = f.readline()
pageTitle = pageTitle.replace('#', '')
text = f.read()
rndr = BleepRenderer(flags=misaka_flags)
md = misaka.Markdown(rndr, extensions=misaka_ext)
content = md.render(text)
toc = misaka.html(text, misaka_ext, misaka.HTML_TOC_TREE)
st_time = os.lstat(fullpath).st_mtime
date_time = datetime.datetime.fromtimestamp(st_time)
updateTime = date_time.strftime('%Y/%m/%d %H:%M')
return render_template('content.html', **locals())
except:
# TODO: page not found message in flash
return redirect(url_for('newView', pageName=name))
else:
return 0
示例13: form_valid
def form_valid(self, form):
rsvps = form.cleaned_data.get('rsvps')
event = self.get_context_data().get('event')
selected_rsvps = event.rsvps.all()
if rsvps == 'yes':
selected_rsvps = event.rsvps.yes()
elif rsvps == 'no':
selected_rsvps = event.rsvps.no()
elif rsvps == 'maybe':
selected_rsvps = event.rsvps.maybe()
elif rsvps == 'possible':
selected_rsvps = event.rsvps.possible()
to_emails = ['{0.name} <{0.email}>'.format(rsvp.user) for
rsvp in selected_rsvps]
host_email = event.host.email if form.cleaned_data.get(
'include_email_address') else None
email = generate_email(
'events/email/message_from_host',
self.request,
{
'subject': form.cleaned_data.get('subject'),
'body': form.cleaned_data.get('body'),
'body_html': misaka.html(form.cleaned_data.get('body')),
'host_email': host_email,
'event': event,
'domain': Site.objects.get_current().domain
},
to=to_emails
)
email.send(fail_silently=True)
return super(EmailRSVPs, self).form_valid(form)
示例14: render
def render(filename, template, edit=False):
filename = filename.replace('.', '') # remove periods
filename = filename.replace(' ', '-')
filename = filename.replace('/', '-')
filepath = os.path.join(NOTES_PATH, '%s.md' % (filename, ))
if not os.path.exists(filepath):
if edit:
note = ''
else:
bottle.redirect('/edit/%s' % (filename, ))
else:
with codecs.open(filepath, 'r', 'utf8') as file_obj:
note = file_obj.read()
def replacement(match):
match_str = match.groups()[0]
replace_match = match_str.replace(' ', '-')
replace_match = match_str.replace('/', '-')
replace_match = replace_match.replace('.', '')
return "<a href='/notes/%s'>%s</a>" % (replace_match, match_str)
if not edit:
note = re.sub(
r'\[\[([A-Z \/\[email protected]]+)\]\]',
replacement,
m.html(note)
)
return pystache.render(loader.load_name(template), {
'title': ' '.join(x.capitalize() for x in filename.split('-')),
'filename': filename,
'content': note
})
示例15: resume
def resume():
logger.info('(' + get_addr(request) + ')')
db.counter.update_one({'counter': 'resume'}, {'$inc': {'value': 1}})
with codecs.open(app.static_folder + '/files/md/resume.md', 'r', encoding='utf8') as f:
text = f.read()
res = m.html(text)
return render_template('blank.html', html=res, title='Resume')