diff --git a/rdmo/core/static/core/css/base.scss b/rdmo/core/static/core/css/base.scss index 5d372c3206..af36f32d2f 100644 --- a/rdmo/core/static/core/css/base.scss +++ b/rdmo/core/static/core/css/base.scss @@ -477,3 +477,13 @@ li.has-warning > a.control-label > i { text-decoration: underline; text-decoration-style: dotted; } + +.more, +.show-less { + display: none; +} +.show-more, +.show-less { + color: $link-color; + cursor: pointer; +} diff --git a/rdmo/core/static/core/js/utils.js b/rdmo/core/static/core/js/utils.js new file mode 100644 index 0000000000..8c34a73526 --- /dev/null +++ b/rdmo/core/static/core/js/utils.js @@ -0,0 +1,11 @@ +function showMore(element) { + $(element).siblings('.more').show(); + $(element).siblings('.show-less').show(); + $(element).hide(); +} + +function showLess(element) { + $(element).siblings('.more').hide(); + $(element).siblings('.show-more').show(); + $(element).hide(); +} diff --git a/rdmo/core/templates/core/base.html b/rdmo/core/templates/core/base.html index fbe8dcec9a..d9508e1be9 100644 --- a/rdmo/core/templates/core/base.html +++ b/rdmo/core/templates/core/base.html @@ -20,6 +20,9 @@ {% endblock %} {% block js %} + {% compress js %} + + {% endcompress %} {% endblock %} {% block head %}{% endblock %} diff --git a/rdmo/core/utils.py b/rdmo/core/utils.py index 22d9d42b31..acfaf51fdd 100644 --- a/rdmo/core/utils.py +++ b/rdmo/core/utils.py @@ -384,15 +384,26 @@ def is_truthy(value): def markdown2html(markdown_string): - # adoption of the normal markdown function which also converts - # `[]{}` to <span title="<title>"><string></span> to - # allow for underlined tooltips - html = markdown(force_str(markdown_string)) + # adoption of the normal markdown function + html = markdown(force_str(markdown_string)).strip() + + # convert `[<string>]{<title>}` to <span title="<title>"><string></span> to allow for underlined tooltips html = re.sub( r'\[(.*?)\]\{(.*?)\}', r'<span data-toggle="tooltip" data-placement="bottom" data-html="true" title="\2">\1</span>', html ) + + # convert everything after `{more}` to <span class="more"><string></span> to be shown/hidden on user input + show_string = _('show more') + hide_string = _('show less') + html = re.sub( + r'(\{more\})(.*?)</p>$', + f'<span class="show-more" onclick="showMore(this)">... ({show_string})</span>' + r'<span class="more">\2</span>' + f'<span class="show-less" onclick="showLess(this)"> ({hide_string})</span></p>', + html + ) return html