Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor help #771

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion rdmo/core/static/core/css/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ table {
}
}

details {
margin-bottom: 10px;
}

summary {
color: $link-color;
display: list-item;
cursor: pointer;
margin-bottom: 5px;
}

metadata {
Expand Down Expand Up @@ -477,3 +482,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;
}
11 changes: 11 additions & 0 deletions rdmo/core/static/core/js/utils.js
Original file line number Diff line number Diff line change
@@ -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();
}
3 changes: 3 additions & 0 deletions rdmo/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
{% endblock %}

{% block js %}
{% compress js %}
<script type="text/javascript" src="{% static 'core/js/utils.js' %}" ></script>
{% endcompress %}
{% endblock %}

{% block head %}{% endblock %}
Expand Down
19 changes: 15 additions & 4 deletions rdmo/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,26 @@ def is_truthy(value):


def markdown2html(markdown_string):
# adoption of the normal markdown function which also converts
# `[<string>]{<title>}` 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


Expand Down