def latest_post(): '''Return the most recent blog post. Returns None if there are no blog posts. :rtype: ckanext.sweden.blog.model.post.Post or None ''' try: from ckanext.sweden.blog.model.post import Post post = Session.query(Post).\ filter(Post.visible == True).\ order_by('created desc').\ first() except NoResultFound: return None if post is None: return None post.content_markdown = markdown( unicode(truncate(post.content, length=320, indicator='...', whole_word=True))) post.post_author = (model.User.get(post.user_id) or Session.query(model.User).filter_by( id=post.user_id).first()) return post
def markdown_extract(text): if (text is None) or (text == ''): return '' html = fromstring(markdown(text)) plain = html.xpath("string()") return unicode( truncate(plain, length=190, indicator='...', whole_word=True))
def markdown(text, **kwargs): """Format the text with MarkDown formatting This function uses the `Python MarkDown library <http://www.freewisdom.org/projects/python-markdown/>`_ which is included with WebHelpers. """ return _markdown.markdown(text, **kwargs)
def markdown_extract(text, extract_length=190): if (text is None) or (text.strip() == ''): return '' plain = re.sub(r'<.*?>', '', markdown(text)) return unicode( truncate(plain, length=extract_length, indicator='...', whole_word=True))
def markdown_extract(text, extract_length=190): """ return the plain text representation of markdown encoded text. That is the texted without any html tags. If extract_length is 0 then it will not be truncated.""" if (text is None) or (text.strip() == ""): return "" plain = re.sub(r"<.*?>", "", markdown(text)) if not extract_length or len(plain) < extract_length: return plain return literal(unicode(truncate(plain, length=extract_length, indicator="...", whole_word=True)))
def markdown_wrap(text, extract_length=190): ''' return the plain text representation of markdown encoded text. That is the texted without any html tags. If extract_length is 0 then it will not be truncated.''' if (text is None) or (text.strip() == ''): return '' plain = RE_MD_HTML_TAGS.sub('', markdown(text)) if not extract_length or len(plain) < extract_length: return literal(plain) return literal(unicode(wrap_paragraphs(plain, width=extract_length)))
def annotate(self): c.prefix = server_api + 'annotation' c.uri = 'make one up' # TODO: create text in the backend ... text = request.params.get('text', '') import webhelpers.markdown as md if text: c.content = md.markdown(text) else: c.content = '' out = render('annotate.html') # out is a webhelpers.html.builder.literal # we want to work with raw html ... out = anno_middleware.modify_html(unicode(out)) return out
def read(self, title): try: from ckanext.sweden.blog.model.post import Post c.post = model.Session.query(Post).\ filter(Post.url == title).\ filter(Post.visible == True).\ one() except NoResultFound: abort(404) c.content_markdown = markdown(c.post.content) c.post_author = (model.User.get(c.post.user_id) or model.Session.query(model.User).filter_by( id=c.post.user_id).first()) return toolkit.render('blog/post.html')
def markdown(text, **kwargs): """Format the text to HTML with MarkDown formatting. This function uses the `Python MarkDown library <http://www.freewisdom.org/projects/python-markdown/>`_ which is included with WebHelpers. It does not include extensions due to circular import issues. If you need the footnotes or RSS extensions, use the full Markdown package instead. IMPORTANT: If your source text is untrusted and may contain malicious HTML markup, pass ``safe_mode="escape"`` to escape it, ``safe_mode="replace"`` to replace it with a scolding message, or ``safe_mode="remove"`` to strip it. There is at least one other Markdown package for Python. python-markdown2 (http://code.google.com/p/python-markdown2/), which claims to be faster and to handle edge cases better. WebHelpers is sticking to the original Python Markdown for now for backward compatibility and because nobody has complained about the speed. """ return literal(_markdown.markdown(text, **kwargs))
def markdown_extract(text, extract_length=190): if (text is None) or (text.strip() == ''): return '' plain = re.sub(r'<.*?>', '', markdown(text)) return literal(unicode(truncate(plain, length=extract_length, indicator='...', whole_word=True)))
def markdown(self): text = request.POST['data'] if text is None: abort(400) c.content = markdown(text) return render('/util/response.html')
from ckanext.blog.authorize import blog_admin log = getLogger(__name__) def latest_post(): try: from ckanext.blog.model.post import Post post = Session.query(Post).\ filter(Post.visible == True).\ order_by('created desc').\ first() except NoResultFound, e: return None post.content_markdown = markdown(unicode(truncate(post.content, length=320, indicator='...', whole_word=True))) post.post_author = model.User.get(post.user_id) or Session.query(model.User).filter_by(id=post.user_id).first() return post class BlogPlugin(p.SingletonPlugin): """This extension adds blogging functionality to ckan This extension implements four interfaces - ``IConfigurer`` allows to modify the configuration - ``IConfigurable`` get the configuration - ``IAuthFunctions`` to add custom authorization - ``IRoutes`` to add custom routes """ p.implements(p.IConfigurer, inherit=True) p.implements(p.IConfigurable, inherit=True)
def markdown_extract(text): if (text is None) or (text == ''): return '' html = fromstring(markdown(text)) plain = html.xpath("string()") return unicode(truncate(plain, length=190, indicator='...', whole_word=True))
def markdown_extract(text, extract_length=190): if (text is None) or (text.strip() == ""): return "" plain = re.sub(r"<.*?>", "", markdown(text)) return literal(unicode(truncate(plain, length=extract_length, indicator="...", whole_word=True)))
def markdown_extract(text, extract_length=190): if (text is None) or (text == ""): return "" html = fromstring(markdown(text)) plain = html.xpath("string()") return unicode(truncate(plain, length=extract_length, indicator="...", whole_word=True))
log = getLogger(__name__) def latest_post(): try: from ckanext.blog.model.post import Post post = Session.query(Post).\ filter(Post.visible == True).\ order_by('created desc').\ first() except NoResultFound, e: return None post.content_markdown = markdown( unicode( truncate(post.content, length=320, indicator='...', whole_word=True))) post.post_author = model.User.get(post.user_id) or Session.query( model.User).filter_by(id=post.user_id).first() return post class BlogPlugin(p.SingletonPlugin): """This extension adds blogging functionality to ckan This extension implements four interfaces - ``IConfigurer`` allows to modify the configuration - ``IConfigurable`` get the configuration - ``IAuthFunctions`` to add custom authorization