add markdown parsing
This commit is contained in:
parent
ce29e64299
commit
e022981027
7 changed files with 50 additions and 6 deletions
30
poetry.lock
generated
30
poetry.lock
generated
|
@ -26,6 +26,18 @@ optional = false
|
|||
python-versions = "*"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "An easy safelist-based HTML-sanitizing tool."
|
||||
name = "bleach"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
version = "3.1.4"
|
||||
|
||||
[package.dependencies]
|
||||
six = ">=1.9.0"
|
||||
webencodings = "*"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "cffi-based cairo bindings for Python"
|
||||
|
@ -234,6 +246,14 @@ parso = ">=0.5.2"
|
|||
qa = ["flake8 (3.7.9)"]
|
||||
testing = ["colorama (0.4.1)", "docopt", "pytest (>=3.9.0,<5.0.0)"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "A fast and complete Python implementation of Markdown"
|
||||
name = "markdown2"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "2.3.8"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "A Python Parser"
|
||||
|
@ -420,7 +440,7 @@ python-versions = "*"
|
|||
version = "0.5.1"
|
||||
|
||||
[metadata]
|
||||
content-hash = "56be8de37de7b07fbe5ca98c9ceea5ca22dbd2ddb2053e252bc41baf6293c373"
|
||||
content-hash = "aedaaacc2c26bf3618b35cd6ed67cbe4309526e18bb696cb37f81398e7cf9337"
|
||||
python-versions = "^3.8"
|
||||
|
||||
[metadata.files]
|
||||
|
@ -436,6 +456,10 @@ backcall = [
|
|||
{file = "backcall-0.1.0.tar.gz", hash = "sha256:38ecd85be2c1e78f77fd91700c76e14667dc21e2713b63876c0eb901196e01e4"},
|
||||
{file = "backcall-0.1.0.zip", hash = "sha256:bbbf4b1e5cd2bdb08f915895b51081c041bac22394fdfcfdfbe9f14b77c08bf2"},
|
||||
]
|
||||
bleach = [
|
||||
{file = "bleach-3.1.4-py2.py3-none-any.whl", hash = "sha256:cc8da25076a1fe56c3ac63671e2194458e0c4d9c7becfd52ca251650d517903c"},
|
||||
{file = "bleach-3.1.4.tar.gz", hash = "sha256:e78e426105ac07026ba098f04de8abe9b6e3e98b5befbf89b51a5ef0a4292b03"},
|
||||
]
|
||||
cairocffi = [
|
||||
{file = "cairocffi-1.1.0.tar.gz", hash = "sha256:f1c0c5878f74ac9ccb5d48b2601fcc75390c881ce476e79f4cfedd288b1b05db"},
|
||||
]
|
||||
|
@ -517,6 +541,10 @@ jedi = [
|
|||
{file = "jedi-0.16.0-py2.py3-none-any.whl", hash = "sha256:b4f4052551025c6b0b0b193b29a6ff7bdb74c52450631206c262aef9f7159ad2"},
|
||||
{file = "jedi-0.16.0.tar.gz", hash = "sha256:d5c871cb9360b414f981e7072c52c33258d598305280fef91c6cae34739d65d5"},
|
||||
]
|
||||
markdown2 = [
|
||||
{file = "markdown2-2.3.8-py2.py3-none-any.whl", hash = "sha256:882d3607fc023cdea0ac2cd0e1147617fcb0361cb1133d3ff095417f995ff270"},
|
||||
{file = "markdown2-2.3.8.tar.gz", hash = "sha256:7ff88e00b396c02c8e1ecd8d176cfa418fb01fe81234dcea77803e7ce4f05dbe"},
|
||||
]
|
||||
parso = [
|
||||
{file = "parso-0.6.2-py2.py3-none-any.whl", hash = "sha256:8515fc12cfca6ee3aa59138741fc5624d62340c97e401c74875769948d4f2995"},
|
||||
{file = "parso-0.6.2.tar.gz", hash = "sha256:0c5659e0c6eba20636f99a04f469798dca8da279645ce5c387315b2c23912157"},
|
||||
|
|
|
@ -10,6 +10,8 @@ django = "^3.0.4"
|
|||
django-model-utils = "^4.0.0"
|
||||
weasyprint = "^51"
|
||||
pypdf2 = "^1.26.0"
|
||||
markdown2 = "^2.3.8"
|
||||
bleach = "^3.1.4"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
ipython = "^7.13.0"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import bleach
|
||||
import markdown2
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.db import models
|
||||
|
@ -55,6 +57,14 @@ class Document(SoftDeletableModel):
|
|||
objects = DocumentManager()
|
||||
exclude_hidden = DocumentManager(include_hidden=False)
|
||||
|
||||
@property
|
||||
def html_description(self):
|
||||
return markdown2.markdown(self.description)
|
||||
|
||||
@property
|
||||
def plain_description(self):
|
||||
return bleach.clean(self.html_description, tags=[], strip=True)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
if self.is_local_pdf:
|
||||
|
|
|
@ -218,6 +218,10 @@ ul > li:before {
|
|||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.index-listing-desc p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 64em ) {
|
||||
#sidebar-head {
|
||||
display: flex;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<span class="doc-description-intro">
|
||||
{% if document.url %}Description{% else %}Content{% endif %}:
|
||||
</span>
|
||||
<p> {{ document.description }} </p>
|
||||
<p> {{ document.html_description | safe }} </p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@ -59,6 +59,6 @@
|
|||
<title>The /-\ pile: {{ document.title }}</title>
|
||||
<meta property="og:title" content="The /-\ Pile: {{ document.title }}"/>
|
||||
<meta property="og:url" content="{% url "pile:document" document.id %}"/>
|
||||
<meta property="og:description" content="{{ document.description }}"/>
|
||||
<meta property="og:description" content="{{ document.plain_description }}"/>
|
||||
<meta property="og:type" content="article"/>
|
||||
{% endblock %}
|
|
@ -22,7 +22,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
<div class="index-listing-desc">
|
||||
{{ random_document.description }}
|
||||
{{ random_document.html_description | safe }}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -40,7 +40,7 @@
|
|||
{{ document.title }}
|
||||
|
||||
<div class="index-listing-desc">
|
||||
{{ document.description }}
|
||||
{{ document.html_description | safe }}
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
<div class="label-otherinfo-date">(Published: {{ document.published }})</div>
|
||||
{% endif %}
|
||||
</h3>
|
||||
<p class="label-description">{{ document.description }}</p>
|
||||
<p class="label-description">{{ document.html_description | safe }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="label-footer">
|
||||
|
|
Loading…
Reference in a new issue