render static pages with unsafe markdown

This commit is contained in:
Luna D 2021-09-23 17:02:21 +02:00
parent 455583fb2e
commit c86e449f42
No known key found for this signature in database
GPG key ID: 81AF416F2CC36FC8
4 changed files with 30 additions and 20 deletions

View file

@ -79,6 +79,15 @@ pre {
padding: 10px;
font-size: 11px;
font-family: $font_family_monospace;
border: 1px solid $meta_border_color;
max-width: 100%;
code {
overflow-y: scroll;
border: 0;
background: 0;
padding: 0;
}
}
a, a:active, a:visited {
@ -305,23 +314,11 @@ img[alt=large] {
max-width: $image_large_size !important;
}
.communication__body__text > table {
table {
@extend .table;
}
.communication__body__text pre {
border: 1px solid $meta_border_color;
max-width: 100%;
code {
overflow-y: scroll;
border: 0;
background: 0;
padding: 0;
}
}
.communication__body__text code {
code {
background-color: $meta_color;
border: 1px solid $meta_border_color;
padding: 0 4px;

View file

@ -3,6 +3,7 @@ defmodule PhilomenaWeb.PageController do
alias Philomena.StaticPages.StaticPage
alias Philomena.StaticPages
alias PhilomenaWeb.MarkdownRenderer
plug :load_and_authorize_resource, model: StaticPage, id_field: "slug"
@ -11,7 +12,8 @@ defmodule PhilomenaWeb.PageController do
end
def show(conn, _params) do
render(conn, "show.html", title: conn.assigns.static_page.title)
rendered = MarkdownRenderer.render_unsafe(conn.assigns.static_page.body, conn)
render(conn, "show.html", title: conn.assigns.static_page.title, rendered: rendered)
end
def new(conn, _params) do

View file

@ -15,6 +15,13 @@ defmodule PhilomenaWeb.MarkdownRenderer do
Markdown.to_html(text, representations)
end
def render_unsafe(text, conn) do
images = find_images(text)
representations = render_representations(images, conn)
Markdown.to_html_unsafe(text, representations)
end
defp find_images(text) do
Regex.scan(~r/>>(\d+)([tsp])?/, text, capture: :all_but_first)
|> Enum.map(fn matches ->

View file

@ -3,9 +3,13 @@ p
' Last updated
=> pretty_time(@static_page.updated_at)
== @static_page.body
p
=> link to: Routes.page_history_path(@conn, :index, @static_page) do
i.fa.fa-history>
' Revision history
= if can?(@conn, :edit, Philomena.StaticPages.StaticPage) do
=< link to: Routes.page_path(@conn, :edit, @static_page) do
i.fa.fa-edit>
' Edit
p = link "Revision history", to: Routes.page_history_path(@conn, :index, @static_page)
= if can?(@conn, :edit, Philomena.StaticPages.StaticPage) do
p = link "Edit", to: Routes.page_path(@conn, :edit, @static_page)
== @rendered