closed #24: Replace postmarkup by django-bbmarkup

This commit is contained in:
slav0nic 2010-01-04 14:17:36 +02:00
parent 97d4cfcf50
commit 55cb1458ef
8 changed files with 31 additions and 1565 deletions

View file

@ -1,27 +0,0 @@
import re
from djangobb_forum.markups import postmarkup
RE_FIRST_LF = re.compile('^\s*\r?\n')
markup = postmarkup.create(exclude=['link', 'url', 'code'], use_pygments=False)
class LinkTagNoAnnotate(postmarkup.LinkTag):
def annotate_link(self, domain):
return ''
class CodeTagNoBreak(postmarkup.CodeTag):
def render_open(self, parser, node_index):
contents = self._escape(self.get_contents(parser))
contents = RE_FIRST_LF.sub('', contents)
self.skip_contents(parser)
return '<pre><code>%s</code></pre>' % contents
def _escape(self, s):
return postmarkup.PostMarkup.standard_replace_no_break(s.rstrip('\n'))
markup.tag_factory.add_tag(LinkTagNoAnnotate, 'url')
markup.tag_factory.add_tag(CodeTagNoBreak, 'code')

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@ from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.hashcompat import sha_constructor
from djangobb_forum.markups import mypostmarkup
from djangobb_forum.markups import bbmarkup
from djangobb_forum.fields import AutoOneToOneField, ExtendedImageField, JSONField
from djangobb_forum.util import urlize, smiles
from djangobb_forum import settings as forum_settings
@ -187,8 +187,8 @@ class Post(models.Model):
def save(self, *args, **kwargs):
if self.markup == 'bbcode':
self.body_html = mypostmarkup.markup(self.body, auto_urls=False)
elif self.markup == 'markdown':
self.body_html = bbmarkup.bbcode(self.body)
elif self.markup == 'markdown' and MARKDOWN_AVAILABLE:
self.body_html = unicode(Markdown(self.body, safe_mode='escape'))
#self.body_html = markdown(self.body, 'safe')
else:
@ -347,17 +347,16 @@ class PrivateMessage(models.Model):
def save(self, *args, **kwargs):
if self.markup == 'bbcode':
self.body_html = mypostmarkup.markup(self.body, auto_urls=False)
self.body_html = bbmarkup.bbcode(self.body)
elif self.markup == 'markdown':
self.body_html = unicode(Markdown(self.body, safe_mode='escape'))
#self.body_html = markdown(self.body, 'safe')
else:
raise Exception('Invalid markup property: %s' % self.markup)
self.body_text = strip_tags(self.body_html)
#self.body_text = strip_tags(self.body_html)
self.body_html = urlize(self.body_html)
if forum_settings.SMILES_SUPPORT:
self.body_html = smiles(self.body_html)
new = self.id is None
super(PrivateMessage, self).save(*args, **kwargs)
@models.permalink

View file

@ -2,13 +2,3 @@
The root of forum tests.
"""
import unittest
from djangobb_forum.tests.postmarkup import PostmarkupTestCase
def suite():
cases = (PostmarkupTestCase,
)
tests = unittest.TestSuite(
unittest.TestLoader().loadTestsFromTestCase(x)\
for x in cases)
return tests

View file

@ -1,26 +0,0 @@
import unittest
from djangobb_forum.markups import mypostmarkup
class PostmarkupTestCase(unittest.TestCase):
def setUp(self):
self.markup = mypostmarkup.markup
def testLinkTag(self):
link = 'http://ya.ru/'
self.assertEqual('<a href="%s">%s</a>' % (link, link),
self.markup('[url]%s[/url]' % link))
def testPlainTest(self):
text = 'just a text'
self.assertEqual(text, self.markup(text))
def testNewLines(self):
text = 'just a\n text'
self.assertEqual('just a<br/> text', self.markup(text))
def testCodeTag(self):
text = 'foo [code]foo\nbar[/code] bar'
self.assertEqual('foo <pre><code>foo\nbar</code></pre>bar', self.markup(text))

View file

@ -21,6 +21,7 @@ from djangobb_forum import settings as forum_settings
#compile smiles regexp
_SMILES = [(re.compile(smile_re), path) for smile_re, path in forum_settings.SMILES]
def render_to(template):
"""
Decorator for Django views that sends returned dict to render_to_response function.
@ -72,9 +73,11 @@ def render_to(template):
return wrapper
return renderer
def absolute_url(path):
return 'http://%s%s' % (forum_settings.HOST, path)
def paged(paged_list_name, per_page):
"""
Parse page from GET data and pass it to view. Split the
@ -209,7 +212,7 @@ class ExcludeTagsHTMLParser(HTMLParser):
self.html.append('&%s;' % name)
def handle_charref(self, name):
self.html.append('&%s;' % name)
self.html.append('&#%s;' % name)
def __html_attrs(self, attrs):
_attrs = ''
@ -261,7 +264,7 @@ def paginate(items, request, per_page, total_count=None):
try:
paged_list_name = paginator.page(page_number).object_list
except (InvalidPage, EmptyPage):
raise Http404
raise Http404
return pages, paginator, paged_list_name
def set_language(request, language):

View file

@ -1,5 +1,6 @@
import math
from datetime import datetime, timedelta
from markdown import Markdown
from django.shortcuts import get_object_or_404
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseForbidden
@ -12,6 +13,7 @@ from django.core.cache import cache
from django.utils import translation
from django.db.models import Q, F, Sum
from django.utils.encoding import smart_str
from django.views.decorators.http import require_POST
from djangobb_forum.util import render_to, paged, build_form, paginate, set_language
from djangobb_forum.models import Category, Forum, Topic, Post, Profile, Reputation,\
@ -20,7 +22,7 @@ from djangobb_forum.forms import AddPostForm, EditPostForm, UserSearchForm,\
PostSearchForm, ReputationForm, MailToForm, EssentialsProfileForm,\
PersonalProfileForm, MessagingProfileForm, PersonalityProfileForm,\
DisplayProfileForm, PrivacyProfileForm, ReportForm, UploadAvatarForm, CreatePMForm
from djangobb_forum.markups import mypostmarkup
from djangobb_forum.markups import bbmarkup
from djangobb_forum.templatetags import forum_extras
from djangobb_forum import settings as forum_settings
from djangobb_forum.util import urlize, smiles
@ -786,11 +788,23 @@ def show_attachment(request, hash):
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(attachment.name)
return response
#TODO: check markup
@login_required
#@require_POST
@render_to('forum/post_preview.html')
def post_preview(request):
'''Preview for markitup'''
data = mypostmarkup.markup(request.POST.get('data', ''), auto_urls=False)
markup = request.user.forum_profile.markup
data = request.POST.get('data', '')
if markup == 'bbcode':
data = bbmarkup.bbcode(data)
elif markup == 'markdown' and MARKDOWN_AVAILABLE:
data = unicode(Markdown(data, safe_mode='escape'))
else:
raise Exception('Invalid markup property: %s' % markup)
data = urlize(data)
data = smiles(data)
if forum_settings.SMILES_SUPPORT:
data = smiles(data)
return {'data': data}

View file

@ -19,11 +19,10 @@ mySettings = {
{name:'Picture', key:'P', replaceWith:'[img][![Url]!][/img]'},
{name:'Link', key:'L', openWith:'[url=[![Url]!]]', closeWith:'[/url]', placeHolder:'Your text to link here...'},
{separator:'---------------' },
{name:'Size', key:'S', openWith:'[size=[![Text size]!]]', closeWith:'[/size]',
{name:'Size', key:'S', openWith:'', closeWith:'',
dropMenu :[
{name:'Big', openWith:'[size=200]', closeWith:'[/size]' },
{name:'Normal', openWith:'[size=100]', closeWith:'[/size]' },
{name:'Small', openWith:'[size=50]', closeWith:'[/size]' }
{name:'Big', openWith:'[big]', closeWith:'[/big]' },
{name:'Small', openWith:'[small]', closeWith:'[/small]' }
]},
{separator:'---------------' },
{name:'Bulleted list', openWith:'[list]\n', closeWith:'\n[/list]'},