Skip to content

Commit

Permalink
fix(gui): convert JATS paragraph markup to HTML
Browse files Browse the repository at this point in the history
in abstracts.
  • Loading branch information
strogonoff committed Jul 14, 2022
1 parent d4e33c5 commit 3c43550
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 9 additions & 3 deletions main/templates/relaton/formatted_string.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{% if val.format == "text/html" %}
{{ val.content|default:"N/A"|safe }}
{% load relaton %}

{% if val.content %}
{% if val.format == "text/html" %}
{{ val.content|safe }}
{% else %}
{{ val|to_html|safe }}
{% endif %}
{% else %}
{{ val.content|default:"N/A" }}
N/A
{% endif %}
20 changes: 19 additions & 1 deletion main/templatetags/relaton.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
from typing import Any, Set, Tuple, Callable, List, Optional
from typing import Dict, Any, Set, Tuple, Callable, List, Optional
from urllib.parse import quote_plus
import dataclasses
import json

from django.urls import reverse
from django import template

from relaton.models.strings import GenericStringValue
from relaton.serializers.bibxml.abstracts import get_paragraphs

from common.util import as_list


register = template.Library()


@register.filter
def to_html(value: Dict[str, str]):
"""Converts a dictionary representation of Relaton’s
:class:`~relaton.models.strings.GenericStringValue`
to HTML with paragraph markup.
"""
if isinstance(value, dict) and 'content' in value and 'format' in value:
try:
gsv = GenericStringValue(**value)
except Exception:
return value['content']
else:
return '<p>%s' % '<p>'.join(get_paragraphs(gsv))


@register.filter
def bibitem_link(value: Any):
"""The value can either be a BibliographicItem
Expand Down

0 comments on commit 3c43550

Please sign in to comment.