Markdown support for description fields added; Tests updated
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 1m44s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 6s
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 1m44s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 6s
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import bleach
|
||||
import markdown
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
@@ -14,6 +17,18 @@ from .forms import (
|
||||
from .models import Box, BoxType, Facet, Tag, Thing, ThingFile, ThingLink
|
||||
|
||||
|
||||
def _strip_markdown(text, max_length=100):
|
||||
"""Convert Markdown to plain text and truncate."""
|
||||
if not text:
|
||||
return ''
|
||||
html = markdown.markdown(text)
|
||||
plain_text = bleach.clean(html, tags=[], strip=True)
|
||||
plain_text = ' '.join(plain_text.split())
|
||||
if len(plain_text) > max_length:
|
||||
return plain_text[:max_length].rsplit(' ', 1)[0] + '...'
|
||||
return plain_text
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
"""Home page with boxes and tags."""
|
||||
@@ -198,7 +213,7 @@ def search_api(request):
|
||||
'id': thing.id,
|
||||
'name': thing.name,
|
||||
'box': thing.box.id,
|
||||
'description': thing.description[:100] if thing.description else '',
|
||||
'description': _strip_markdown(thing.description),
|
||||
'tags': [
|
||||
{
|
||||
'name': tag.name,
|
||||
|
||||
Reference in New Issue
Block a user