예제 #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
 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
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
 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
 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
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
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
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
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
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
 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
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
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
 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
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
  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
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
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
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)