コード例 #1
0
ファイル: views.py プロジェクト: artemzi/pepysdiary
 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)
コード例 #2
0
ファイル: views.py プロジェクト: 31H0B1eV/pepysdiary
 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
     )
コード例 #3
0
 def sidenoteLinkToMarkdown(match):
   group = match.groupdict()
   return ("[%s](javascript:Sidenote.openColumnLoud\('#%s','#%s','%s'\))" %
     (group["linktext"],
      escapeQuotes(source),
      escapeQuotes(group["identifier"]),
      escapeQuotes(smartypants.smartyPants(group["linktext"]))))
コード例 #4
0
  def keywordToSidenoteLink(match):
    keyword = match.group()
    begin = end = ""
    if re.match("\W", keyword[0]):
      begin = keyword[0]
      keyword = keyword[1:]
    if re.match("\W", keyword[-1]):
      end = keyword[-1]
      keyword = keyword[:-1]
    pageId = keywordIndex[keyword.lower()]

    if pageId == source:
      return "%s%s%s" % (begin, keyword, end)

    if keyword in observedKeywords:
      loudness = "Quiet"
    else:
      loudness = "Loud"
    observedKeywords.add(keyword)

    return ("%s[%s](javascript:Sidenote.openColumn%s\('#%s','#%s','%s'\))%s" %
      (begin,
       keyword,
       loudness,
       escapeQuotes(source),
       escapeQuotes(pageId),
       escapeQuotes(smartypants.smartyPants(keyword)),
       end))
コード例 #5
0
ファイル: SmartyPants.py プロジェクト: zw/Anki-Plugins
def formatQA(html, type, cid, mid, fact, tags, cm):
    logger.debug(u"before smartypants, html is:\n" + html)
    if NO_SMARTYPANTS_TAG not in tags:
        html = smartypants.smartyPants(html, attr="2")

    logger.debug(u"after smartypants, html is:\n" + html)
    return html
コード例 #6
0
ファイル: basenodehandler.py プロジェクト: wolfoo2931/rst2pdf
 def apply_smartypants(self, text, smarty, node):
     # Try to be clever about when to use smartypants
     if node.__class__ in (docutils.nodes.paragraph,
                           docutils.nodes.block_quote,
                           docutils.nodes.title):
         return smartyPants(text, smarty)
     return text
コード例 #7
0
def formatQA(html, type, cid, mid, fact, tags, cm):
    logger.debug(u"before smartypants, html is:\n" + html)
    if NO_SMARTYPANTS_TAG not in tags:
        html = smartypants.smartyPants(html, attr="2")

    logger.debug(u"after smartypants, html is:\n" + html)
    return html
コード例 #8
0
ファイル: scraper.py プロジェクト: henare/daily-paper
 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
コード例 #9
0
def read_and_parse_entries():
    files = sorted(
        [join(DIRS['source'], f) for f in os.listdir(DIRS['source'])],
        reverse=True)
    entries = []
    for file in files:
        match = META_REGEX.findall(file)
        if len(match):
            meta = match[0]
            with open(file, 'r') as open_file:
                msg = email.message_from_file(open_file)
                date = datetime(*[int(d) for d in meta[0:3]])
                entries.append({
                    'slug':
                    slugify(meta[3]),
                    'title':
                    meta[3].replace('.', ' '),
                    'tags':
                    msg['Tags'].split(),
                    'date': {
                        'iso8601': date.isoformat(),
                        'rfc3339': rfc3339(date),
                        'display': date.strftime('%Y-%m-%d'),
                    },
                    'content_html':
                    smartyPants(_markdown(msg.get_payload())),
                })
    return entries
コード例 #10
0
def typogrify(content):
    """The super typography filter

    Applies the following filters: widont, smartypants, caps, amp, initial_quotes"""

    return number_suffix(
        initial_quotes(caps(smartypants.smartyPants(widont(amp(content)),
                                                    "2"))))
コード例 #11
0
def typographie(text):
  text = html_parser.unescape(text)
  text = force_unicode(text)
  text = smartyPants(text)
  text = ellipsis(text)
  text = spaces(text)
  text = widont(text)
  return mark_safe(text)
コード例 #12
0
def smartypants(text):
    """Applies smarty pants to curl quotes.

    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """

    return _smartypants.smartyPants(text)
コード例 #13
0
ファイル: text_parsing.py プロジェクト: syncopated/97bottles
def unsmartypants(value):
  """
  Normalizes a string which has been processed by smartypants.py.
  """
  try:
    import smartypants
    return smartypants.smartyPants(value, '-1')
  except ImportError:
    return value
コード例 #14
0
ファイル: typogrify.py プロジェクト: thegreyspot/susysite
def smartquotes(text):
    """Applies smarty pants to curl quotes.

    >>> smartquotes('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    text = unicode(text)
    output = smartypants.smartyPants(text)
    return output
コード例 #15
0
ファイル: my-rst2html.py プロジェクト: shaggytwodope/dotfiles
def main():

  with open(sys.argv[1]) as f:
    source = f.read()

  doc_parts = publish_parts(
      source,
      settings_overrides={'output_encoding': 'utf8',
                          'initial_header_level': 2,
                          },
      writer_name="html")

  RE = smartypants.tags_to_skip_regex 
  pattern = RE.pattern.replace('|code', '|code|tt')
  pattern = pattern.replace('|script', '|script|style')
  RE = re.compile(pattern, RE.flags)
  smartypants.tags_to_skip_regex = RE
  print smartyPants(doc_parts['fragment']).encode('utf-8')
コード例 #16
0
ファイル: typogrify.py プロジェクト: karanlyons/bestthing
def smartypants(text):
	"""Applies smarty pants to curl quotes.
	
	>>> smartypants('The "Green" man')
	u'The &#8220;Green&#8221; man'
	"""
	text = force_unicode(text)
	output = _smartypants.smartyPants(re.sub(ur'“|”', '"', re.sub(ur'‘|’', "'", text)))
	return output
コード例 #17
0
def smartypants_filter(text):
    """Applies smarty pants to curl quotes.
    
    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    text = force_unicode(text)
    output = smartypants.smartyPants(text)
    return mark_safe(output)
コード例 #18
0
def _smartypants(text):
    """Applies SmartyPants transformations to a block of text."""
    text = force_unicode(text)
    try:
        import smartypants
    except ImportError:
        return text
    else:
        return smartypants.smartyPants(text)
コード例 #19
0
ファイル: typogrify.py プロジェクト: JustJenFelice/oddsite
def smartquotes(text):
    """Applies smarty pants to curl quotes.

    >>> smartquotes('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    text = unicode(text)
    output = smartypants.smartyPants(text)
    return output
コード例 #20
0
def smartypants_filter(text):
    """Applies smarty pants to curl quotes.
    
    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    text = force_unicode(text)
    output = smartypants.smartyPants(text)
    return mark_safe(output)
コード例 #21
0
 def save(self, force_insert=False, force_update=False):
     """
     Use Markdown to convert the ``copy`` field from plain-text to
     HTMl.  Smartypants is also used to bring in curly quotes.
     """
     from markdown import markdown
     from smartypants import smartyPants
     self.copy_html = smartyPants(
         markdown(self.copy, ['abbr', 'headerid(level=2)']))
     super(Entry, self).save(force_insert=False, force_update=False)
コード例 #22
0
ファイル: models.py プロジェクト: AbdAllah-Ahmed/flother
 def save(self, force_insert=False, force_update=False):
     """
     Use Markdown to convert the ``copy`` field from plain-text to
     HTMl.  Smartypants is also used to bring in curly quotes.
     """
     from markdown import markdown
     from smartypants import smartyPants
     self.copy_html = smartyPants(markdown(self.copy, ['abbr',
         'headerid(level=2)']))
     super(Entry, self).save(force_insert=False, force_update=False)
コード例 #23
0
ファイル: rst_parser.py プロジェクト: VCTLabs/bruce
 def curlify(text):
     """Replace quotes in `text` with curly equivalents."""
     if config.options.smartypants == 'off':
         return text
     # Replace any ampersands with an entity so we don't harm the text.
     text = text.replace('&', '&#38;')
     # Use smartypants to curl the quotes, creating HTML entities
     text = smartypants.smartyPants(text, config.options.smartypants)
     # Replace the entities with real Unicode characters.
     text = re.sub('&#(\d+);', lambda m: unichr(int(m.group(1))), text)
     return text
コード例 #24
0
ファイル: typography.py プロジェクト: sebix/acrylamid
def typogrify(content):
    """The super typography filter

    Applies the following filters: widont, smartypants, caps, amp, initial_quotes"""

    return number_suffix(
           initial_quotes(
           caps(
           smartypants.smartyPants(
           widont(
           amp(content)), mode))))
コード例 #25
0
ファイル: core_utils.py プロジェクト: taylanpince/taylanpince
def smartypants(value):
    """
    Filters the value through SmartyPants for converting plain 
    ASCII punctuation characters into typographically correct versions
    """
    try:
        from smartypants import smartyPants
        
        return smartyPants(value)
    except ImportError:
        return value
コード例 #26
0
ファイル: rst_parser.py プロジェクト: imbilltucker/bruce
 def curlify(text):
     """Replace quotes in `text` with curly equivalents."""
     if config.options.smartypants == 'off':
         return text
     # Replace any ampersands with an entity so we don't harm the text.
     text = text.replace('&', '&#38;')
     # Use smartypants to curl the quotes, creating HTML entities
     text = smartypants.smartyPants(text, config.options.smartypants)
     # Replace the entities with real Unicode characters.
     text = re.sub('&#(\d+);', lambda m: unichr(int(m.group(1))), text)
     return text
コード例 #27
0
def smartypants(text):
    """Applies smarty pants to curl quotes.

    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """

    t = _smartypants.smartyPants(text)
    # replace "curly" quotes with russian-style quotes (&laquo; and &raquo;)
    t = t.replace('&#8220;', '&#171;')
    t = t.replace('&#8221;', '&#187;')
    return t
コード例 #28
0
ファイル: util.py プロジェクト: Lancey6/redwind
def markdown_filter(data, img_path=None):
    if data is None:
        return ''

    if img_path:
        # replace relative paths to images with absolute
        data = RELATIVE_PATH_RE.sub('[\g<1>](' + img_path + '/\g<2>)', data)

    data = convert_legacy_people_to_at_names(data)
    result = markdown(data, extensions=['codehilite', 'fenced_code'])
    result = smartyPants(result)
    return result
コード例 #29
0
ファイル: typogrify.py プロジェクト: braveulysses/backwater
def smartypants(text):
    """Applies smarty pants to curl quotes.
    
    >>> smartypants('The "Green" man')
    'The &#8220;Green&#8221; man'
    """
    try:
        import smartypants
    except ImportError:
        return text
    else:
        return smartypants.smartyPants(text)
コード例 #30
0
    def smartypants(text):
        """Applies smarty pants to curl quotes.

        >>> Typogrify.smartypants('The "Green" man')
        'The &#8220;Green&#8221; man'
        """
        try:
            import smartypants
        except ImportError:
            raise TypogrifyError, "Error in {% smartypants %} filter: The Python smartypants library isn't installed."
        else:
            output = smartypants.smartyPants(text)
            return output
コード例 #31
0
ファイル: typogrify.py プロジェクト: nikuda/cyrax
def smartypants(text):
    """Applies smarty pants to curl quotes.

    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    try:
        import smartypants
    except ImportError:
        logger.error("Error in {% smartypants %} filter: The Python smartypants library isn't installed.")
        return text
    output = smartypants.smartyPants(text)
    return jinja2.Markup(output)
コード例 #32
0
ファイル: rest.py プロジェクト: jeffschenck/zealous
def to_html(rest, smart='1'):
    """
    Converts reStructuredText to HTML fragment.
    
    By default, educates quotes, dashes and ellipses with the smartypants
    engine. You can feed in any of the options it accepts:
    http://web.chad.org/projects/smartypants.py/#options.
    """
    parts = core.publish_parts(source=rest, writer_name='html',
        settings_overrides={'initial_header_level': 3})
    html = '%s%s' % (parts['body_pre_docinfo'], parts['fragment'])
    html = smartyPants(html, smart)
    return html
コード例 #33
0
  def _CreateSeqDiv(self, seq_obj, kind):
    soup = bs4.BeautifulSoup("")
    seq = soup.new_tag("div")
    seq["class"] = kind

    seq_h = soup.new_tag("h2")
    seq_h.string = smartyPants(seq_obj["title"])
    seq.append(seq_h)

    if "description" in seq_obj:
      # XXX "html.parser" is used here because lxml adds <html></html> around
      # the element. Figure out how to achieve what we need here in a proper
      # manner.
      desc_soup = bs4.BeautifulSoup(smartyPants(seq_obj["description"]),
                                    "html.parser")
      seq_desc = soup.new_tag("div")
      seq_desc["class"] = CssClass.DESCRIPTION
      for elem in desc_soup.children:
        seq_desc.append(elem)
      seq.append(seq_desc)

    return seq
コード例 #34
0
ファイル: typogrify.py プロジェクト: tominsam/cougar
def smartypants(text):
    """Applies smarty pants to curl quotes.
    
    >>> smartypants('The "Green" man')
    'The &#8220;Green&#8221; man'
    """
    try:
        import smartypants
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError, "Error in {% smartypants %} filter: The Python smartypants library isn't installed."
        return text
    else:
        return smartypants.smartyPants(text)
コード例 #35
0
def markdown_filter(data, img_path=None):
    if data is None:
        return ''

    if img_path:
        # replace relative paths to images with absolute
        data = RELATIVE_PATH_RE.sub('[\g<1>](' + img_path + '/\g<2>)', data)

    data = convert_legacy_people_to_at_names(data)
    if data.startswith('#'):
        data = '\\' + data
    result = markdown(data, extensions=['codehilite', 'fenced_code'])
    result = smartyPants(result)
    return result
コード例 #36
0
ファイル: util.py プロジェクト: kylewm/redwind
def markdown_filter(data, img_path=None):
    if data is None:
        return ""

    if img_path:
        # replace relative paths to images with absolute
        data = RELATIVE_PATH_RE.sub("[\g<1>](" + img_path + "/\g<2>)", data)

    data = convert_legacy_people_to_at_names(data)
    if data.startswith("#"):
        data = "\\" + data
    result = markdown(data, extensions=["codehilite", "fenced_code"])
    result = smartyPants(result)
    return result
コード例 #37
0
ファイル: typography.py プロジェクト: strogo/socrates
def smartypants(text):
    """Applies smarty pants to curl quotes.
    
    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    text = force_unicode(text)
    try:
        import smartypants
    except ImportError:
        raise Exception, "Error in {% smartypants %} filter: The Python smartypants library isn't installed."
    else:
        output = smartypants.smartyPants(text)
        return mark_safe(output)
コード例 #38
0
ファイル: filters.py プロジェクト: rayleyva/typogrify
def smartypants(text):
    """Applies smarty pants to curl quotes.

    >>> smartypants('The "Green" man')
    'The &#8220;Green&#8221; man'
    """
    try:
        import smartypants
    except ImportError:
        raise TypogrifyError(
            "Error in {% smartypants %} filter: The Python smartypants library isn't installed."
        )
    else:
        output = smartypants.smartyPants(text)
        return output
コード例 #39
0
ファイル: util.py プロジェクト: thedod/redwind
def markdown_filter(data, img_path=None, url_processor=url_to_link,
                    person_processor=person_to_microcard):
    if data is None:
        return ''

    if img_path:
        # replace relative paths to images with absolute
        data = RELATIVE_PATH_RE.sub('[\g<1>](' + img_path + '/\g<2>)', data)

    data = convert_legacy_people_to_at_names(data)
    result = markdown(data, extensions=['codehilite', 'fenced_code'])
    if url_processor or person_processor:
        result = autolink(result, url_processor, person_processor)
    result = smartyPants(result)
    return result
コード例 #40
0
def unsmartypants(value):
  """
  Normalizes a string which has been processed by smartypants.py.
    
    {% entry.body|smartypants|unsmartypants %}
  
  """
  try:
    import smartypants
  except ImportError:
    if settings.DEBUG:
      raise template.TemplateSyntaxError, "Error in {% smartypants %} filter: The Python SmartyPants library isn't installed."
      return value
    else:
      return smartypants.smartyPants(value, '-1')
コード例 #41
0
def smartypants(text):
    """Applies smarty pants to curl quotes.
    
    >>> smartypants('The "Green" man')
    u'The &#8220;Green&#8221; man'
    """
    text = force_unicode(text)
    try:
        import smartypants
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError, "Error in {% smartypants %} filter: The Python smartypants library isn't installed."
        return text
    else:
        output = smartypants.smartyPants(text)
        return mark_safe(output)
コード例 #42
0
def smartypants(value):
    """
    Applies SmartyPants to a piece of text, applying typographic
    niceties.

    Requires the Python SmartyPants library to be installed; see
    http://web.chad.org/projects/smartypants.py/

    """
    try:
        from smartypants import smartyPants
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError("Error in smartypants filter: the Python smartypants module is not installed or could not be imported")
        return value
    else:
        return mark_safe(smartyPants(value))
コード例 #43
0
 def generate_chapter(self, chapter):
     """Return a rendered 'chapter' given a chapter element from the
     manifest. This uses the extension of the input file to determine the
     processing (if any) to be done. First external processors defined in
     the configuration file are checked; otherwise, the internal Markdown
     processor is used for .md/.txt files. XHTML files are used as-is.
     
     """
     html = False
     filename, file_ext = os.path.splitext(chapter['file'])
     file_ext = file_ext.lower()
     stylesheet = self.styles + '/' + chapter.get(
         'stylesheet', self.manifest.get('stylesheet', 'default.css'))
     processors = self.config.get('processors', {})
     if processors.has_key(file_ext):
         command = processors[file_ext].format(chapter['file'])
         try:
             html = subprocess.check_output(command.split())
         except:
             print "Error running '{}'".format(chapter['file'])
             sys.exit(1)
         # TODO handle partial or full HTML output here
     elif file_ext == '.md' or file_ext == '.txt' or file_ext == '.markdown':
         try:
             file_obj = open(self.source_dir + '/' + chapter['file'])
             text = file_obj.read()
         except IOError as err:
             print err
             sys.exit(1)
         try:
             html = smartyPants(markdown(text))
         except MarkdownException as err:
             print "Error processing {} - {}".format(chapter['file'], err)
             sys.exit(1)
     elif file_ext == '.xhtml':
         file_obj = open(self.source_dir + '/' + chapter['file'])
         return file_obj.read()
     if html is False:
         raise BinderError(BinderError.WEIRD_FILE,
                           'Unknown file type: ' + chapter['file'])
     return self.templatize(
         'chapter.xhtml', {
             'content': html,
             'stylesheet': stylesheet,
             'title': chapter.get('title')
         })
コード例 #44
0
def smartypants(value):
    """
    Applies SmartyPants to a piece of text, applying typographic
    niceties.
    
    Requires the Python SmartyPants library to be installed; see
    http://web.chad.org/projects/smartypants.py/
    
    """
    try:
        from smartypants import smartyPants
    except ImportError:
        if settings.DEBUG:
            raise TemplateSyntaxError("Error in smartypants filter: the Python smartypants module is not installed or could not be imported")
        return value
    else:
        return smartyPants(value)
コード例 #45
0
 def render(self, text, **kwargs):
     from smartypants import smartyPants
     return smartyPants(text, **kwargs)
コード例 #46
0
 def encode(self, text):
     text = html4css1.HTMLTranslator.encode(self, text)
     if self._in_literal <= 0:
         text = smartypants.smartyPants(text, "qde")
     return text
コード例 #47
0
def smartypants(value):
    try:
        import smartypants
        return smartypants.smartyPants(value)
    except ImportError:
        return value
コード例 #48
0
def run(content):
    return smartypants.smartyPants(content)