diff --git a/demo/demodesk/config/settings.py b/demo/demodesk/config/settings.py index 14c54876..7985edc2 100644 --- a/demo/demodesk/config/settings.py +++ b/demo/demodesk/config/settings.py @@ -37,7 +37,6 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.humanize', - 'markdown_deux', 'bootstrap4form', 'helpdesk' ] diff --git a/docs/install.rst b/docs/install.rst index 67e90b9f..66df1905 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -57,7 +57,6 @@ errors with trying to create User settings. 'django.contrib.sites', # Required for determining domain url for use in emails 'django.contrib.admin', # Required for helpdesk admin/maintenance 'django.contrib.humanize', # Required for elapsed time formatting - 'markdown_deux', # Required for Knowledgebase item formatting 'bootstrap4form', # Required for nicer formatting of forms with the default templates 'helpdesk', # This is us! ) @@ -114,21 +113,17 @@ errors with trying to create User settings. Ideally, accessing http://MEDIA_URL/helpdesk/attachments/ will give you a 403 access denied error. -7. If it's not already installed, install ``markdown_deux`` and ensure it's in your ``INSTALLED_APPS``:: - - pip install django-markdown-deux - -8. If you already have a view handling your logins, then great! If not, add the following to ``settings.py`` to get your Django installation to use the login view included in ``django-helpdesk``:: +7. If you already have a view handling your logins, then great! If not, add the following to ``settings.py`` to get your Django installation to use the login view included in ``django-helpdesk``:: LOGIN_URL = '/helpdesk/login/' Alter the URL to suit your installation path. -9. Load initial e-mail templates, otherwise you will not be able to send e-mail:: +8. Load initial e-mail templates, otherwise you will not be able to send e-mail:: python manage.py loaddata emailtemplate.json -10. If you intend on using local mail directories for processing email into tickets, be sure to create the mail directory before adding it to the queue in the Django administrator interface. The default mail directory is ``/var/lib/mail/helpdesk/``. Ensure that the directory has appropriate permissions so that your Django/web server instance may read and write files from this directory. +9. If you intend on using local mail directories for processing email into tickets, be sure to create the mail directory before adding it to the queue in the Django administrator interface. The default mail directory is ``/var/lib/mail/helpdesk/``. Ensure that the directory has appropriate permissions so that your Django/web server instance may read and write files from this directory. Note that by default, any mail files placed in your local directory will be permanently deleted after being successfully processed. It is strongly recommended that you take further steps to save emails if you wish to retain backups. diff --git a/helpdesk/models.py b/helpdesk/models.py index 9096f75d..78a02e61 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -19,11 +19,37 @@ from io import StringIO import re import datetime +from django.utils.safestring import mark_safe +from markdown import markdown +from markdown.extensions import Extension + + import uuid from .templated_email import send_templated_mail +class EscapeHtml(Extension): + def extendMarkdown(self, md, md_globals): + del md.preprocessors['html_block'] + del md.inlinePatterns['html'] + + +def get_markdown(text): + if not text: + return "" + + return mark_safe( + markdown( + text, + extensions=[ + EscapeHtml(), 'markdown.extensions.nl2br', + 'markdown.extensions.fenced_code' + ] + ) + ) + + class Queue(models.Model): """ A queue is a collection of tickets into what would generally be business @@ -717,6 +743,9 @@ class Ticket(models.Model): queue = '-'.join(parts[0:-1]) return queue, parts[-1] + def get_markdown(self): + return get_markdown(self.description) + class FollowUpManager(models.Manager): @@ -768,8 +797,10 @@ class FollowUp(models.Model): _('Public'), blank=True, default=False, - help_text=_('Public tickets are viewable by the submitter and all ' - 'staff, but non-public tickets can only be seen by staff.'), + help_text=_( + 'Public tickets are viewable by the submitter and all ' + 'staff, but non-public tickets can only be seen by staff.' + ), ) user = models.ForeignKey( @@ -821,6 +852,9 @@ class FollowUp(models.Model): t.save() super(FollowUp, self).save(*args, **kwargs) + def get_markdown(self): + return get_markdown(self.comment) + class TicketChange(models.Model): """ @@ -1161,6 +1195,9 @@ class KBItem(models.Model): from django.urls import reverse return reverse('helpdesk:kb_item', args=(self.id,)) + def get_markdown(self): + return get_markdown(self.answer) + class SavedSearch(models.Model): """ diff --git a/helpdesk/static/helpdesk/helpdesk-extend.css b/helpdesk/static/helpdesk/helpdesk-extend.css index ad62b9b4..85e14baa 100644 --- a/helpdesk/static/helpdesk/helpdesk-extend.css +++ b/helpdesk/static/helpdesk/helpdesk-extend.css @@ -77,3 +77,9 @@ Add your custom styles here } #helpdesk-body {padding-top: 100px;} img.brand {padding-right: 30px;} + +pre { + background: #eee; + padding: 1em; + border: 1pt solid white; +} diff --git a/helpdesk/templates/helpdesk/kb_item.html b/helpdesk/templates/helpdesk/kb_item.html index cfefaa1d..bdd8457b 100644 --- a/helpdesk/templates/helpdesk/kb_item.html +++ b/helpdesk/templates/helpdesk/kb_item.html @@ -1,4 +1,4 @@ -{% extends "helpdesk/public_base.html" %}{% load i18n %}{% load markdown_deux_tags %} +{% extends "helpdesk/public_base.html" %}{% load i18n %} {% block helpdesk_breadcrumb %}
{{ item.answer|markdown }}
+{{ item.get_markdown }}