diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -1,6 +1,8 @@ +from django.core.urlresolvers import reverse import markdown from markdown.inlinepatterns import Pattern from markdown.util import etree +import boards __author__ = 'neko259' @@ -28,7 +30,8 @@ class ReflinkPattern(Pattern): def handleMatch(self, m): ref_element = etree.Element('a') post_id = m.group(4) - ref_element.set('href', '#' + str(post_id)) + ref_element.set('href', reverse(boards.views.jump_to_post, + kwargs={'post_id': post_id})) ref_element.text = m.group(2) return ref_element diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -24,6 +24,7 @@ urlpatterns = patterns('', url(r'^settings$', views.settings, name='settings'), url(r'^tags$', views.all_tags, name='tags'), url(r'^captcha/', include('captcha.urls')), + url(r'^jump/(?P\w+)', views.jump_to_post, name='jumper'), # RSS feeds url(r'^rss/$', AllThreadsFeed()), diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -206,6 +206,17 @@ def all_tags(request): return render(request, 'boards/tags.html', context) +def jump_to_post(request, post_id): + post = get_object_or_404(Post, id=post_id) + + if boards.models.NO_PARENT == post.parent: + return redirect(thread, post_id=post.id) + else: + parent_thread = get_object_or_404(Post, id=post.parent) + return redirect(reverse(thread, kwargs={'post_id': parent_thread.id}) + + '#' + str(post.id)) + + def _get_theme(request): return request.session.get('theme', neboard.settings.DEFAULT_THEME)