diff --git a/poetry.lock b/poetry.lock index 6a935b6..1f4e9ff 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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"}, diff --git a/pyproject.toml b/pyproject.toml index ecee974..a48d32e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/sdbs_pile/pile/models.py b/sdbs_pile/pile/models.py index 78d1ffd..5acabef 100644 --- a/sdbs_pile/pile/models.py +++ b/sdbs_pile/pile/models.py @@ -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: diff --git a/sdbs_pile/pile/static/main.css b/sdbs_pile/pile/static/main.css index 81e928f..02b74aa 100755 --- a/sdbs_pile/pile/static/main.css +++ b/sdbs_pile/pile/static/main.css @@ -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; diff --git a/sdbs_pile/pile/templates/front_doc_detail.html b/sdbs_pile/pile/templates/front_doc_detail.html index 58eacfd..73def11 100644 --- a/sdbs_pile/pile/templates/front_doc_detail.html +++ b/sdbs_pile/pile/templates/front_doc_detail.html @@ -32,7 +32,7 @@ {% if document.url %}Description{% else %}Content{% endif %}: -

{{ document.description }}

+

{{ document.html_description | safe }}

{% endif %} @@ -59,6 +59,6 @@ The /-\ pile: {{ document.title }} - + {% endblock %} \ No newline at end of file diff --git a/sdbs_pile/pile/templates/front_intro.html b/sdbs_pile/pile/templates/front_intro.html index df167c6..108c6a5 100644 --- a/sdbs_pile/pile/templates/front_intro.html +++ b/sdbs_pile/pile/templates/front_intro.html @@ -22,7 +22,7 @@ {% endif %}
- {{ random_document.description }} + {{ random_document.html_description | safe }}
@@ -40,7 +40,7 @@ {{ document.title }}
- {{ document.description }} + {{ document.html_description | safe }}
diff --git a/sdbs_pile/pile/templates/label.html b/sdbs_pile/pile/templates/label.html index fe57edd..5ede2d0 100644 --- a/sdbs_pile/pile/templates/label.html +++ b/sdbs_pile/pile/templates/label.html @@ -118,7 +118,7 @@
(Published: {{ document.published }})
{% endif %} -

{{ document.description }}

+

{{ document.html_description | safe }}