コード例 #1
0
ファイル: views.py プロジェクト: fzzy/wadharkka
def show_document(request, id):
    """Show contents of a document"""
    ctx = copy.copy(default_ctx)
    doc = get_object_or_404(Document, id=id)
    if not (doc.visibility == 'A' or 
            (doc.visibility == 'R' and request.user.is_authenticated()) or
            (doc.visibility == 'C' and 
             (doc.owner == request.user or doc.contributors.filter(id=request.user.id).exists()))):
        raise Http404
    ctx['doc'] = doc
    ctx['doc'].content = parse_md(doc.content)
    return render_to_response('show_document.html', ctx, RequestContext(request))
コード例 #2
0
#
# 	You should have received a copy of the GNU General Public License
# 	along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import shutil

import utils


SOURCE_PATH = 'test/'
BUILD_PATH = 'build/'

if os.path.lexists(BUILD_PATH):
    shutil.rmtree(BUILD_PATH)

shutil.copytree(SOURCE_PATH, BUILD_PATH)

md_files = utils.get_files_tree(BUILD_PATH, 'md')

utils.save_html.setup(html_css='markdown.css')

for item in md_files:
    dest = item[:-2] + 'html'
    print item, '==>', dest
    with open(item, 'rb') as fp:
        model = utils.parse_md(fp)
        with open(dest, 'wb') as res_fp:
            utils.save_html(res_fp, model)
    os.remove(item)
コード例 #3
0
ファイル: views.py プロジェクト: fzzy/wadharkka
def preview_parser(request):
    """Return parsed markdown html code for markitup preview button"""
    if request.method == 'POST':
        data = request.POST.get('data', '')
        pdata = parse_md(data)
        return HttpResponse(pdata)