本文整理汇总了Python中smartypants.smartypants函数的典型用法代码示例。如果您正苦于以下问题:Python smartypants函数的具体用法?Python smartypants怎么用?Python smartypants使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smartypants函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: parse_transcript
def parse_transcript(path):
"""
Parse a Premiere .tsv file, calculate total seconds and write to JSON for use in the app.
"""
data = {
'subtitles': []
}
filename, ext = path.split('/')[-1].split('.')
with codecs.open(path, 'rb', encoding='utf16') as f:
transcript = f.read().encode('utf-8')
tab_reader = csv.reader(BytesIO(transcript), delimiter='\t')
headers = tab_reader.next()
for row in tab_reader:
# Premiere exports kind of suck
if row[0] == '':
words = smartypants(row[1].strip())
time_str = row[2]
else:
words = smartypants(row[0].strip())
time_str = row[1]
hours, minutes, seconds, frame = [int(x) for x in time_str.split(';')]
decimal = (float(frame) / 24)
total_seconds = (hours * 3600) + (minutes * 60) + (seconds + decimal)
segment = {
'time': total_seconds,
'transcript': words,
}
data['subtitles'].append(segment)
with open('www/data/%s.json' % filename, 'w') as wf:
wf.write(json.dumps(data))
开发者ID:dailycal-projects,项目名称:public-trust,代码行数:35,代码来源:data.py
示例2: publish_index_pages
def publish_index_pages(self):
file_posts = self.get_all_file_posts_by_date()
posts = [ Post(f, self.s) for f in self.get_all_file_posts_by_date()]
for post in posts:
post.content = smartypants(self.md_to_html(post.content))
post.title = smartypants(post.title)
first_post = 0
last_post = first_post + self.s.POSTS_PER_PAGE
page_number = 0
dest_fname = self.s.INDEX_PAGE
dest_dir = self.s.WWW_DIR
prev_page_url = None
next_page_url = None
while first_post < len(posts):
p = posts[first_post:last_post]
if page_number == 0:
local_fname = dest_fname
else:
local_fname = "%s-%d%s" % (os.path.splitext(dest_fname)[0], page_number, self.s.HTML_EXT )
# Pagination
if len(posts) <= last_post:
# No next page
next_page_url = None
else:
next_page_url = "%s-%d%s" % (os.path.splitext(self.s.INDEX_PAGE)[0], page_number + 1, self.s.HTML_EXT)
if first_post - self.s.POSTS_PER_PAGE < 0:
prev_page_url = None
else:
if page_number == 1:
prev_page_url = self.s.INDEX_PAGE
else:
prev_page_url = "%s-%d.html" % (os.path.splitext(self.s.INDEX_PAGE)[0], page_number - 1)
self.write_posts_to_file(
posts=p,
fname=local_fname,
dir=dest_dir,
template=self.s.INDEX_TEMPLATE,
prev_page_url=prev_page_url,
next_page_url=next_page_url,
)
logging.info("Wrote posts %d-%d to %s." % (first_post, last_post, local_fname))
first_post = last_post
last_post = first_post + self.s.POSTS_PER_PAGE
page_number = page_number + 1
开发者ID:robertozoia,项目名称:ristretto,代码行数:59,代码来源:updater.py
示例3: prepare_post
def prepare_post(self, post):
post.title = smartypants(post.title)
post.content = smartypants(markdown.markdown(post.content,
extensions=self.s.MD_EXTENSIONS,
extension_configs=self.s.MD_EXTENSION_CONFIGS,
output_format=self.s.MD_OUTPUT_FORMAT
))
开发者ID:robertozoia,项目名称:ristretto,代码行数:8,代码来源:updater.py
示例4: __init__
def __init__(self, **kwargs):
self.date = kwargs['date']
self.source_file = kwargs['source_file']
self.summary = smartypants.smartypants(kwargs['summary'])
self.title = smartypants.smartypants(kwargs['title'])
self.route = kwargs['route']
self.url = kwargs['url']
# Having the posts enables a blog post to find its relationships.
self._posts = kwargs['posts']
开发者ID:handroll,项目名称:handroll,代码行数:9,代码来源:blog.py
示例5: smartquotes
def smartquotes(self, text: str) -> str:
"""If enabled, apply 'smart quotes' to the text; replaces quotes and dashes by nicer looking symbols"""
if self.supports_smartquotes and self.do_smartquotes:
if hasattr(smartypants.Attr, "u"):
return smartypants.smartypants(text, smartypants.Attr.q | smartypants.Attr.B |
smartypants.Attr.D | smartypants.Attr.e | smartypants.Attr.u)
else:
# older smartypants lack attribute 'u' for avoiding html entity creation
txt = smartypants.smartypants(text, smartypants.Attr.q | smartypants.Attr.B |
smartypants.Attr.D | smartypants.Attr.e)
import html.parser
return html.parser.unescape(txt) # type: ignore
return text
开发者ID:irmen,项目名称:Tale,代码行数:13,代码来源:iobase.py
示例6: make_item_content_encoded
def make_item_content_encoded(self, text1, text2, url, comment_name):
"""
Called from item_content_encoded() in children.
text1 and text2 are chunks of HTML text (or empty strings).
url is the URL of the item (no domain needed, eg '/diary/1666/10/31/').
comment_name is one of 'comment' or 'annotation'.
"""
return '%s %s <p><strong><a href="%s#%ss">Read the %ss</a></strong></p>' % (
force_unicode(smartypants.smartypants(text1)),
force_unicode(smartypants.smartypants(text2)),
add_domain(Site.objects.get_current().domain, url),
comment_name,
comment_name
)
开发者ID:srinchiera,项目名称:pepysdiary,代码行数:14,代码来源:views.py
示例7: render_gist
def render_gist(request, id, raw):
"""Render a raw gist and store it"""
gist = {
'id': raw['id'],
'html_url': raw['html_url'],
'public': raw['public'],
'description': raw['description'],
'created_at': iso8601.parse_date(raw['created_at']),
'updated_at': iso8601.parse_date(raw['updated_at']),
'fetched_at': rdb.now(),
'author_id': raw['user']['id'],
'author_login': raw['user']['login'],
'files': [],
}
for gistfile in raw['files'].values():
format = RENDERABLE.get(gistfile['language'], None)
if format is None:
continue
output = None
if format is FORMAT_MD:
payload = {
'mode': 'gfm',
'text': gistfile['content'],
}
req_render = requests.post('https://api.github.com/markdown',
params=GITHUB_AUTH_PARAMS,
data=unicode(json.dumps(payload)))
if req_render.status_code != 200:
logger.warn('Render {} file {} failed: {}'.format(id, gistfile['filename'], req_render.status_code))
continue
else:
output = smartypants.smartypants(req_render.text)
if format is FORMAT_RST:
rendered = render_rst(gistfile['content'], writer_name='html')['fragment']
output = smartypants.smartypants(rendered)
if output is not None:
gistfile['rendered'] = output
gist['files'].append(gistfile)
rdb.table('gists').insert(gist, upsert=True).run(request.rdbconn)
return gist
开发者ID:OWLOOKIT,项目名称:gistio,代码行数:48,代码来源:views.py
示例8: prettify_text
def prettify_text(self, text):
"""
Make text more nicerer. Run it through SmartyPants and Widont.
"""
text = self.widont(text)
text = smartypants.smartypants(text)
return text
开发者ID:olekang,项目名称:daily-paper,代码行数:7,代码来源:scraper.py
示例9: prettify_title
def prettify_title(title):
"""Sanitizes all (ALL) HTML elements in titles while prettifying the quotes
and dashes used in the titles of threads and categories.
"""
return bleach.clean(\
smartypants(title, "2"),\
tags=[], attributes={})
开发者ID:kirillyar,项目名称:pony-forum,代码行数:7,代码来源:views.py
示例10: webfix_unicode
def webfix_unicode(possible_string):
"""
This is ugly but it will create Times-approved HTML
out of terrible cut-and-paste from decision text.
"""
CHAR_MAP = [
(u'\xa7', u'§'),
(u'\u2014', u'—'),
(u'\u2013', u'–'),
(u'\x97', u'—'),
(u'\xa4', u'€'),
(u'\u201c', u'"'),
(u'\u201d', u'"'),
(u'\x96', u'–'),
]
if isinstance(possible_string, basestring):
string = possible_string
string = string.strip()
for char, replace_char in CHAR_MAP:
string = string.replace(char, replace_char)
string = string.decode('utf-8')
string = unicode(string)
string = ftfy.fix_text(string)
string = smartypants.smartypants(string)
return string
return possible_string
开发者ID:newsdev,项目名称:nyt-scotus,代码行数:28,代码来源:utils.py
示例11: convert_entities
def convert_entities(obj):
for key in obj.iterkeys():
if isinstance(obj[key], unicode):
obj[key] = smartypants(obj[key])
obj[key] = obj[key].encode('ascii', 'xmlcharrefreplace')
else:
convert_entities(obj[key])
开发者ID:nprapps,项目名称:play-quiz,代码行数:7,代码来源:static.py
示例12: _to_smart
def _to_smart(verse):
verse = verse.replace(",`",", '")
verse = verse.replace("`","'")
out = smartypants(verse)
parser = HTMLParser()
out = parser.unescape(out)
return out
开发者ID:nate9,项目名称:lampstand,代码行数:8,代码来源:dumb_to_smart_quotes.py
示例13: publish_pages
def publish_pages(self, posts=None, force_publish=False):
if force_publish:
posts = [Post(os.path.join(self.s.PAGES_DIR, f), self.s) for f in os.listdir(self.s.PAGES_DIR) if f.endswith(self.s.MD_EXT)]
for post in posts:
post.content = smartypants(self.md_to_html(post.content))
post.title = smartypants(post.title)
html_fname = "%s%s" % (post.slug, self.s.HTML_EXT)
html_dir = os.path.join(self.s.WWW_DIR, self.s.WWW_PAGES_URL)
html_full_path = os.path.join(html_dir, html_fname)
tools.mkdirp(html_dir)
# TODO: check dir owner/permission
self.write_single_post_to_file(post=post, fname=html_full_path, template=self.s.PAGES_TEMPLATE)
开发者ID:robertozoia,项目名称:ristretto,代码行数:17,代码来源:updater.py
示例14: smartypants
def smartypants(text):
"""Applies smarty pants to curl quotes.
>>> smartypants('The "Green" man')
u'The “Green” man'
"""
return _smartypants.smartypants(text)
开发者ID:chrisdrackett,项目名称:django-typogrify,代码行数:8,代码来源:typogrify_tags.py
示例15: clean_typography
def clean_typography(self, text):
return smartypants.smartypants(text).\
replace(" ", "").\
replace(" ", " ").\
replace(u'’', u'’').\
replace(u'“', u'“').\
replace(u'”', u'”').\
replace(u'\xa0 ', u' ').replace(u' \xa0', u' ')
开发者ID:groundupnews,项目名称:gu,代码行数:8,代码来源:models.py
示例16: smartypants_filter
def smartypants_filter(text):
"""
Smarty pants
"""
if text:
return smartypants(text)
else:
return ''
开发者ID:youthradio,项目名称:yr-big-read-template,代码行数:8,代码来源:blueprint.py
示例17: smartypants_wrapper
def smartypants_wrapper(text):
try:
import smartypants
except ImportError:
from typogrify.filters import TypogrifyError
raise TypogrifyError(
"Error in {% smartypants %} filter: The Python smartypants "
"library isn't installed."
)
else:
attr = smartypants.default_smartypants_attr | smartypants.Attr.w
content = smartypants.smartypants(text, attr=attr)
if isinstance(text, AMPString):
amp_data = text.amp_data
content = AMPString(content)
content.amp_data = smartypants.smartypants(amp_data, attr=attr)
return content
开发者ID:MarkusH,项目名称:blog,代码行数:17,代码来源:plugins.py
示例18: get
def get(self):
urls = self.get_query_arguments('url')
if urls and len(urls) == 1:
url = urls[0]
doc = Document(requests.get(url).text)
self.write(smartypants(doc.summary()))
self.write(STYLE)
else:
self.write("Please provide ?url=[your-url]")
开发者ID:guidoism,项目名称:prettyweb,代码行数:9,代码来源:unshitify.py
示例19: smartquotes
def smartquotes(text):
"""Applies smarty pants to curl quotes.
>>> smartquotes('The "Green" man')
u'The “Green” man'
"""
text = unicode(text)
output = smartypants.smartypants(text)
return output
开发者ID:mirisuzanne,项目名称:miriamsuzanne,代码行数:9,代码来源:typogrify.py
示例20: about
def about():
context = make_context()
f = codecs.open("posts/intro.md", mode="r", encoding="utf-8")
contents = f.read()
html = markdown.markdown(smartypants(contents))
context['markdown'] = Markup(html)
return render_template('post.html', **context)
开发者ID:TylerFisher,项目名称:euphonos2,代码行数:9,代码来源:app.py
注:本文中的smartypants.smartypants函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论