Skip to content

Commit

Permalink
Fix table in markdown and use dsfr table style (#432)
Browse files Browse the repository at this point in the history
* feat: handle dsfr table in markdown

* fix: qa
  • Loading branch information
nicolaskempf57 committed Jun 20, 2024
1 parent d8cf2f2 commit 0249046
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
## 4.0.1 (2024-04-26)

- Update footer
- Fix markdown tables and use DSFR ones [#432](https://github.com/datagouv/udata-front/pull/432)

## 4.0.0 (2024-04-23)

Expand Down
2 changes: 2 additions & 0 deletions udata_front/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# included for retro-compatibility reasons (some plugins may import from here instead of udata)
from udata.frontend import template_hook # noqa
from udata.i18n import I18nBlueprint
from .markdown import init_app as init_markdown

nav = Navigation()
oauth = OAuth()
Expand Down Expand Up @@ -43,6 +44,7 @@ def init_app(app):

nav.init_app(app)
theme.init_app(app)
init_markdown(app)

from . import helpers, error_handlers, menu_helpers, resource_helpers # noqa

Expand Down
22 changes: 22 additions & 0 deletions udata_front/frontend/markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from udata.frontend.markdown import mistune, UDataMarkdown


class Renderer(mistune.Renderer):
def table(self, header, body):
return (
'<div class=\"fr-table\">\n<table>\n<thead>\n%s</thead>\n'
'<tbody>\n%s</tbody>\n</table>\n</div>\n'
) % (header, body)


class UDataFrontMarkdown(UDataMarkdown):
"""Consistent with Flask's extensions signature."""

def __init__(self, app):
app.jinja_env.filters['markdown'] = self.__call__
renderer = Renderer(escape=False, hard_wrap=True)
self.markdown = mistune.Markdown(renderer=renderer)


def init_app(app):
app.extensions['markdown'] = UDataFrontMarkdown(app)
3 changes: 3 additions & 0 deletions udata_front/theme/gouvfr/assets/less/components/markdown.less
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ Content on the site can be styled with Markdown. Ready made styles are provided
tr:nth-child(odd) {
background-color: @grey-125;
}
}

.fr-table tbody:only-child {
& > :first-child {
&:extend(.fr-table thead);
}
Expand Down

0 comments on commit 0249046

Please sign in to comment.