This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: spam / garbage report
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti
Priority: normal Keywords:

Created on 2012-07-05 17:55 by andisthermal555, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg164688 - (view) Author: andisthermal (andisthermal555) Date: 2012-07-05 17:55
<p>This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:</p>

<pre><code>$ cd your_repo_root/repo_name
$ git fetch origin
$ git checkout gh-pages
</code></pre>

<p>If you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.</p>

<h3>Designer Templates</h3>
msg164726 - (view) Author: andisthermal (andisthermal555) Date: 2012-07-06 15:03
#!/usr/bin/env python

"""A small wrapper file for parsing AsciiDoc files at Github."""

__author__ = "Devin Weaver" 
__copyright__ = "Copyright (C) 2009 Devin Weaver" 
__license__ = "Public Domain" 
__version__ = "0.1" 

"""
github_asciidoc.py
------------------

This is a wrapper file for parsing AsciiDoc files at github. It wraps the
current AsciiDoc API.

AsciiDoc specifications suggest using the file extension of `.txt` however this
causes conflict because there is no way to determine if a text file is an
AsciiDoc or not without pre-processing the file. This gives us two simple
options:

1. **Parse all text files**. We could have all files ending in `.txt` or
   ``README.txt`` be parsed through AsciiDoc. It will print pretty text fine
   even if it isn't formatted as such. However this could be *not what the user
   expects*.
2. **Pick a unique extension**. We could pick a unique extension (i.e.
   `.asciidoc`) to prevent clashing. Although not directly suggested by the
   author of AsciiDoc there is no standard or practice to the contrary.

Option two is recommended by myself.

Requirements
~~~~~~~~~~~~

The AsciiDoc API comes in two parts. The first is the system installation of
AsciiDoc which has a simple install_. The second part is the API script. You
can either copy this to the current directory or the application's lib folder.
There is more information on the `API page`_

The `re` package is imported here for the purpose to accomplish E-Mail address
cloaking. AsciiDoc does not offer it's own cloaking algorithm like docutils
does. So I made a simple one here to do the same. **If the expense of regex's
is too high it can be easily commented out.**

.. tip::
    AsciiDoc by default runs in *safe mode* which means it will not include
    external files that are **not** in the same directory as the `infile`.
    However since we use a StringIO through the API it should be based on the
    current working directory.

.. _install: http://www.methods.co.nz/asciidoc/userguide.html
.. _API page: http://www.methods.co.nz/asciidoc/asciidocapi.html
"""

try:
    import locale
    locale.setlocale(locale.LC_ALL, '')
except:
    pass

import sys
import cStringIO # faster then StringIO
from asciidocapi import AsciiDocAPI
from asciidocapi import AsciiDocError
import re # only needed to simulate cloak_email_addresses

def main():
    """
    Parses the given AsciiDoc file or the redirected string input and returns
    the HTML body.

    Usage: asciidoc2html < README.rst
           asciidoc2html README.rst
    """
    try:
        text = open(sys.argv[1], 'r').read()
    except IOError: # given filename could not be found
        return ''
    except IndexError: # no filename given
        text = sys.stdin.read()

    infile = cStringIO.StringIO(text)
    outfile = cStringIO.StringIO()
    asciidoc = AsciiDocAPI()
    asciidoc.options('-s')

    try:
        asciidoc.execute(infile, outfile, 'xhtml11')
    except AsciiDocError, strerror:
        str = "%s" % (strerror)
        str = str.replace("&", "&amp;") # Must be done first
        str = str.replace("<", "%lt;")
        str = str.replace(">", "%gt;")
        outfile.write ("<blockquote><strong>AsciiDoc ERROR: %s</strong></blockquote>" % (str))

    """
    Cloak email addresses

    AsciiDoc API does not have a `cloak_email_addresses` option. We can do the
    same with a set of regex but that can be expensive. Keep section commented
    to disable. So ``abc@mail.example.com`` becomes:

    -----------
    <a class="reference" href="mailto:abc&#37;&#52;&#48;mail&#46;example&#46;org">
    abc<span>&#64;</span>mail<span>&#46;</span>example<span>&#46;</span>org</a>
    -----------
    """
    def mangleEmail(matches):
        email1 = "%s&#37;&#52;&#48;%s" % (matches.group(1), matches.group(2))
        email1 = email1.replace(".", "&#46;")
        email2 = "%s<span>&#64;</span>%s" % (matches.group(1), matches.group(2))
        email2 = email2.replace(".", "<span>&#46;</span>")
        return "<a class=\"reference\" href=\"mailto:%s\">%s</a>" % (email1, email2)

    return re.sub(r'<a href="mailto:([^@]+)@([^@]+)">([^@]+)@([^@]+)</a>', mangleEmail, outfile.getvalue())
    #return outfile.getvalue()

if __name__ == '__main__':
    print main()
<div id="rainbow-message" style="display:none">
Double repositories all the way across the sky!<br/>
<a href="http://docs.python.org/devguide/triaging.html#assigned-to/">What does it mean?</a>
</div>
History
Date User Action Args
2022-04-11 14:57:32adminsetgithub: 59460
2012-07-06 17:38:55ezio.melottisetnosy: + ezio.melotti
2012-07-06 17:38:14ezio.melottisetfiles: - query.csv
2012-07-06 17:38:09ezio.melottisethgrepos: - hgrepo138
2012-07-06 17:38:05ezio.melottisethgrepos: - hgrepo139
2012-07-06 17:37:52ezio.melottisetstatus: open -> closed
assignee: collinwinter ->
type: security ->
components: - Benchmarks
versions: - 3rd party
nosy: - collinwinter, andisthermal555
-> (no value)
resolution: fixed -> not a bug
2012-07-06 15:03:49andisthermal555setstatus: closed -> open
files: + query.csv

resolution: not a bug -> fixed

assignee: collinwinter
hgrepos: + hgrepo139
nosy: + andisthermal555, collinwinter
messages: + msg164726
components: + Benchmarks, - XML
type: security
2012-07-05 18:44:58eric.araujosettitle: glose_Fb -> spam / garbage report
2012-07-05 18:44:47eric.araujosetfiles: - Fb.init.js
2012-07-05 18:44:38eric.araujosetstatus: open -> closed
-> (no value)
nosy: - andisthermal555
resolution: not a bug
type: security -> (no value)
stage: resolved
2012-07-05 17:55:05andisthermal555create