-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use wagtail-markdown instead of custom code (#116)
- Loading branch information
Showing
36 changed files
with
159 additions
and
1,187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,3 @@ def extendMarkdown(self, md): | |
"InternalLinkPattern", | ||
200, | ||
) | ||
|
||
|
||
def makeExtension(): | ||
return MinuteExtension() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,4 @@ | ||
# vim:sw=4 ts=4 et: | ||
# Copyright (c) 2015 Torchbox Ltd. | ||
# [email protected] 2015-09-14 | ||
# | ||
# Permission is granted to anyone to use this software for any purpose, | ||
# including commercial applications, and to alter it and redistribute it | ||
# freely. This software is provided 'as-is', without any express or implied | ||
# warranty. | ||
# | ||
|
||
import html2text | ||
from django.db.models import TextField | ||
from wagtail_localize.segments import ( | ||
OverridableSegmentValue, | ||
StringSegmentValue, | ||
|
@@ -18,19 +7,13 @@ | |
from wagtail_localize.segments.extract import quote_path_component | ||
from wagtail_localize.segments.ingest import organise_template_segments | ||
from wagtail_localize.strings import extract_strings, restore_strings | ||
from wagtailmarkdown.fields import MarkdownField | ||
from wagtailmarkdown.utils import render_markdown | ||
|
||
from .utils import render_markdown | ||
from .widgets import MarkdownTextarea | ||
|
||
|
||
class MarkdownField(TextField): | ||
def formfield(self, **kwargs): | ||
defaults = {"widget": MarkdownTextarea} | ||
defaults.update(kwargs) | ||
return super(MarkdownField, self).formfield(**defaults) | ||
|
||
class CustomMarkdownField(MarkdownField): | ||
def get_translatable_segments(self, value): | ||
template, strings = extract_strings(render_markdown(value, with_abbreveations=False)[0]) | ||
template, strings = extract_strings(render_markdown(value)) | ||
|
||
# Find all unique href values | ||
hrefs = set() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import markdown | ||
from django.utils.encoding import smart_str | ||
from django.utils.safestring import mark_safe | ||
from wagtailmarkdown.utils import _get_markdown_kwargs, _sanitise_markdown_html | ||
|
||
from myhpi.core.markdown.extensions import MinuteExtension | ||
|
||
|
||
def render_markdown(text, context=None, with_abbreveations=True): | ||
""" | ||
Turn markdown into HTML. | ||
""" | ||
if context is None or not isinstance(context, dict): | ||
context = {} | ||
markdown_html, toc = _transform_markdown_into_html(text, with_abbreveations=with_abbreveations) | ||
sanitised_markdown_html = _sanitise_markdown_html(markdown_html) | ||
return mark_safe(sanitised_markdown_html), mark_safe(toc) | ||
|
||
|
||
def _transform_markdown_into_html(text, with_abbreveations): | ||
from myhpi.core.models import AbbreviationExplanation | ||
|
||
markdown_kwargs = _get_markdown_kwargs() | ||
markdown_kwargs["extensions"].append( | ||
MinuteExtension() | ||
) # should be in settings.py, but module lookup doesn't work | ||
md = markdown.Markdown(**markdown_kwargs) | ||
abbreveations = "\n" + ( | ||
"\n".join( | ||
[ | ||
f"*[{abbr.abbreviation}]: {abbr.explanation}" | ||
for abbr in AbbreviationExplanation.objects.all() | ||
] | ||
) | ||
) | ||
text = smart_str(text) + abbreveations if with_abbreveations else smart_str(text) | ||
return md.convert(text), md.toc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from myhpi.settings import * | ||
|
||
DEBUG = True | ||
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" | ||
WAGTAIL_APPEND_SLASH = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.