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

Demote headings appearing in markdown #166

Merged
merged 1 commit into from
Mar 13, 2024
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
6 changes: 3 additions & 3 deletions home/templatetags/markdown.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.utils.safestring import SafeText, mark_safe
from markdown import markdown as markdown_func

register = template.Library()


@register.filter
@stringfilter
def markdown(value):
return mark_safe(markdown_func(value))
def markdown(value, heading_offset=0) -> SafeText:
return mark_safe(markdown_func(value, extensions=['mdx_headdown'], extension_configs={'mdx_headdown': {'offset': heading_offset}}))
19 changes: 16 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ whitenoise = "^6.6.0"
ministryofjustice-data-platform-catalogue = "^0.19.2"
markdown = "^3.5.2"
python-dotenv = "^1.0.1"
markdown-headdown = "^0.1.3"

[tool.poetry.group.dev.dependencies]
black = "^24.2.0"
Expand Down
6 changes: 3 additions & 3 deletions templates/details_data_product.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
Description
</h2>
<div class="govuk-body">
{{result.description|markdown}}
{{result.description|markdown:3}}
</div>
<dl class="govuk-summary-list govuk-summary-list--no-border">
<div class="govuk-summary-list__row">
Expand Down Expand Up @@ -93,9 +93,9 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
<th scope="row" class="govuk-table__header">{{table.name}}</th>
<td class="govuk-table__cell">
{% if table.description|length > 200 %}
{{ table.description|slice:":200"|add:"..."|markdown }}
{{ table.description|slice:":200"|add:"..."|markdown:3 }}
{% else %}
{{ table.description|markdown }}
{{ table.description|markdown:3 }}
{% endif %}
</td>
<td class="govuk-table__cell"> <a href="{% url 'home:details' result_type=table_type id=table.urn %}" class="govuk-link">Schema details</a></td>
Expand Down
2 changes: 1 addition & 1 deletion templates/details_dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 class="govuk-heading-s govuk-!-margin-top-3">
Description
</h2>
<p class="govuk-body">
{{table.description|markdown}}
{{table.description|markdown:3}}
</p>
<dl class="govuk-summary-list govuk-summary-list--no-border">
<div class="govuk-summary-list__row">
Expand Down
2 changes: 1 addition & 1 deletion templates/glossary.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h2 class="govuk-heading-l" id="{{ parent_term }}">{{ parent_term.name }}</h2>
{% for member in parent_term.members %}
<div data-term="{{member.name|upper}}" class="term">
<h3 class="govuk-heading-m" id="{{ member.name }}">{{ member.name }}</h3>
<p class="govuk-body">{{ member.description|markdown }}</p>
<p class="govuk-body">{{ member.description|markdown:3 }}</p>
</div>
{%endfor%}
<br>
Expand Down
4 changes: 2 additions & 2 deletions templates/partial/search_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ <h3 class="govuk-heading-m govuk-!-margin-bottom-2">
{% if result.description %}
<div class="govuk-body-m">
{% if result.description|length > 200 %}
{{ result.description|slice:":200"|add:"..."|markdown }}
{{ result.description|slice:":200"|add:"..."|markdown:3 }}
{% else %}
{{ result.description|markdown }}
{{ result.description|markdown:3 }}
{% endif %}
</div>
{% endif %}
Expand Down
Loading