mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +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;
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ->
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue