mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-25 06:24:33 +01:00
render static pages with unsafe markdown
This commit is contained in:
parent
455583fb2e
commit
c86e449f42
4 changed files with 30 additions and 20 deletions
|
@ -79,6 +79,15 @@ pre {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-family: $font_family_monospace;
|
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 {
|
a, a:active, a:visited {
|
||||||
|
@ -305,23 +314,11 @@ img[alt=large] {
|
||||||
max-width: $image_large_size !important;
|
max-width: $image_large_size !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.communication__body__text > table {
|
table {
|
||||||
@extend .table;
|
@extend .table;
|
||||||
}
|
}
|
||||||
|
|
||||||
.communication__body__text pre {
|
|
||||||
border: 1px solid $meta_border_color;
|
|
||||||
max-width: 100%;
|
|
||||||
|
|
||||||
code {
|
code {
|
||||||
overflow-y: scroll;
|
|
||||||
border: 0;
|
|
||||||
background: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.communication__body__text code {
|
|
||||||
background-color: $meta_color;
|
background-color: $meta_color;
|
||||||
border: 1px solid $meta_border_color;
|
border: 1px solid $meta_border_color;
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.PageController do
|
||||||
|
|
||||||
alias Philomena.StaticPages.StaticPage
|
alias Philomena.StaticPages.StaticPage
|
||||||
alias Philomena.StaticPages
|
alias Philomena.StaticPages
|
||||||
|
alias PhilomenaWeb.MarkdownRenderer
|
||||||
|
|
||||||
plug :load_and_authorize_resource, model: StaticPage, id_field: "slug"
|
plug :load_and_authorize_resource, model: StaticPage, id_field: "slug"
|
||||||
|
|
||||||
|
@ -11,7 +12,8 @@ defmodule PhilomenaWeb.PageController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(conn, _params) do
|
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
|
end
|
||||||
|
|
||||||
def new(conn, _params) do
|
def new(conn, _params) do
|
||||||
|
|
|
@ -15,6 +15,13 @@ defmodule PhilomenaWeb.MarkdownRenderer do
|
||||||
Markdown.to_html(text, representations)
|
Markdown.to_html(text, representations)
|
||||||
end
|
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
|
defp find_images(text) do
|
||||||
Regex.scan(~r/>>(\d+)([tsp])?/, text, capture: :all_but_first)
|
Regex.scan(~r/>>(\d+)([tsp])?/, text, capture: :all_but_first)
|
||||||
|> Enum.map(fn matches ->
|
|> Enum.map(fn matches ->
|
||||||
|
|
|
@ -3,9 +3,13 @@ p
|
||||||
' Last updated
|
' Last updated
|
||||||
=> pretty_time(@static_page.updated_at)
|
=> pretty_time(@static_page.updated_at)
|
||||||
|
|
||||||
== @static_page.body
|
p
|
||||||
|
=> link to: Routes.page_history_path(@conn, :index, @static_page) do
|
||||||
p = link "Revision history", to: Routes.page_history_path(@conn, :index, @static_page)
|
i.fa.fa-history>
|
||||||
|
' Revision history
|
||||||
= if can?(@conn, :edit, Philomena.StaticPages.StaticPage) do
|
= if can?(@conn, :edit, Philomena.StaticPages.StaticPage) do
|
||||||
p = link "Edit", to: Routes.page_path(@conn, :edit, @static_page)
|
=< link to: Routes.page_path(@conn, :edit, @static_page) do
|
||||||
|
i.fa.fa-edit>
|
||||||
|
' Edit
|
||||||
|
|
||||||
|
== @rendered
|
||||||
|
|
Loading…
Reference in a new issue