diff --git a/assets/css/common/_base.scss b/assets/css/common/_base.scss index d10a3cfc..bae162c2 100644 --- a/assets/css/common/_base.scss +++ b/assets/css/common/_base.scss @@ -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; diff --git a/lib/philomena_web/controllers/page_controller.ex b/lib/philomena_web/controllers/page_controller.ex index 8fa86eb7..1f8490a2 100644 --- a/lib/philomena_web/controllers/page_controller.ex +++ b/lib/philomena_web/controllers/page_controller.ex @@ -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 diff --git a/lib/philomena_web/markdown_renderer.ex b/lib/philomena_web/markdown_renderer.ex index bf4259db..242a20af 100644 --- a/lib/philomena_web/markdown_renderer.ex +++ b/lib/philomena_web/markdown_renderer.ex @@ -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 -> diff --git a/lib/philomena_web/templates/page/show.html.slime b/lib/philomena_web/templates/page/show.html.slime index fd938294..fa4bc580 100644 --- a/lib/philomena_web/templates/page/show.html.slime +++ b/lib/philomena_web/templates/page/show.html.slime @@ -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