From 14db174c26c4db53dc284932065b398c79c316c1 Mon Sep 17 00:00:00 2001 From: Luna D Date: Sun, 12 Sep 2021 21:03:59 +0200 Subject: [PATCH] add *_md versions of all columns, textile/md glue --- lib/philomena/badges/badge.ex | 1 + lib/philomena/channels/channel.ex | 1 + lib/philomena/comments/comment.ex | 1 + lib/philomena/commissions/commission.ex | 4 + lib/philomena/commissions/item.ex | 2 + lib/philomena/conversations/message.ex | 1 + lib/philomena/dnp_entries/dnp_entry.ex | 3 + lib/philomena/filters/filter.ex | 1 + lib/philomena/galleries/gallery.ex | 1 + lib/philomena/images/image.ex | 2 + lib/philomena/mod_notes/mod_note.ex | 1 + lib/philomena/posts/post.ex | 1 + lib/philomena/reports/report.ex | 1 + lib/philomena/tags/tag.ex | 1 + lib/philomena/users/user.ex | 2 + .../controllers/admin/dnp_entry_controller.ex | 6 +- .../controllers/admin/mod_note_controller.ex | 4 +- .../controllers/admin/report_controller.ex | 6 +- .../controllers/comment_controller.ex | 4 +- .../controllers/conversation_controller.ex | 4 +- .../controllers/dnp_entry_controller.ex | 16 +- .../controllers/image/comment_controller.ex | 6 +- .../image/description_controller.ex | 4 +- .../controllers/image_controller.ex | 8 +- .../controllers/post/preview_controller.ex | 6 +- .../controllers/post_controller.ex | 4 +- .../profile/commission_controller.ex | 20 +-- .../controllers/profile/detail_controller.ex | 4 +- .../controllers/profile_controller.ex | 14 +- .../controllers/tag_controller.ex | 8 +- .../controllers/topic_controller.ex | 4 +- lib/philomena_web/image_loader.ex | 8 +- lib/philomena_web/markdown_renderer.ex | 7 + lib/philomena_web/text_renderer.ex | 18 +++ lib/philomena_web/textile_renderer.ex | 58 +++---- .../20210912171343_add_markdown_columns.exs | 145 ++++++++++++++++++ priv/repo/structure.sql | 58 +++++-- 37 files changed, 320 insertions(+), 115 deletions(-) create mode 100644 lib/philomena_web/markdown_renderer.ex create mode 100644 lib/philomena_web/text_renderer.ex create mode 100644 priv/repo/migrations/20210912171343_add_markdown_columns.exs diff --git a/lib/philomena/badges/badge.ex b/lib/philomena/badges/badge.ex index d7a232aa..88376d43 100644 --- a/lib/philomena/badges/badge.ex +++ b/lib/philomena/badges/badge.ex @@ -5,6 +5,7 @@ defmodule Philomena.Badges.Badge do schema "badges" do field :title, :string field :description, :string, default: "" + field :description_md, :string, default: "" field :image, :string field :disable_award, :boolean, default: false field :priority, :boolean, default: false diff --git a/lib/philomena/channels/channel.ex b/lib/philomena/channels/channel.ex index 1ace95a1..9c93b83c 100644 --- a/lib/philomena/channels/channel.ex +++ b/lib/philomena/channels/channel.ex @@ -14,6 +14,7 @@ defmodule Philomena.Channels.Channel do field :short_name, :string field :title, :string, default: "" field :description, :string + field :description_md, :string field :tags, :string field :viewers, :integer, default: 0 field :nsfw, :boolean, default: false diff --git a/lib/philomena/comments/comment.ex b/lib/philomena/comments/comment.ex index 180aaaaa..f7ee6f5d 100644 --- a/lib/philomena/comments/comment.ex +++ b/lib/philomena/comments/comment.ex @@ -11,6 +11,7 @@ defmodule Philomena.Comments.Comment do belongs_to :deleted_by, User field :body, :string + field :body_md, :string field :ip, EctoNetwork.INET field :fingerprint, :string field :user_agent, :string, default: "" diff --git a/lib/philomena/commissions/commission.ex b/lib/philomena/commissions/commission.ex index 18cb7b7b..c27fdbb2 100644 --- a/lib/philomena/commissions/commission.ex +++ b/lib/philomena/commissions/commission.ex @@ -17,6 +17,10 @@ defmodule Philomena.Commissions.Commission do field :contact, :string field :will_create, :string field :will_not_create, :string + field :information_md, :string + field :contact_md, :string + field :will_create_md, :string + field :will_not_create_md, :string field :commission_items_count, :integer, default: 0 timestamps(inserted_at: :created_at, type: :utc_datetime) diff --git a/lib/philomena/commissions/item.ex b/lib/philomena/commissions/item.ex index 59682f7a..f8b10c4d 100644 --- a/lib/philomena/commissions/item.ex +++ b/lib/philomena/commissions/item.ex @@ -11,8 +11,10 @@ defmodule Philomena.Commissions.Item do field :item_type, :string field :description, :string + field :description_md, :string field :base_price, :decimal field :add_ons, :string + field :add_ons_md, :string timestamps(inserted_at: :created_at, type: :utc_datetime) end diff --git a/lib/philomena/conversations/message.ex b/lib/philomena/conversations/message.ex index f1dc1129..365ad78b 100644 --- a/lib/philomena/conversations/message.ex +++ b/lib/philomena/conversations/message.ex @@ -10,6 +10,7 @@ defmodule Philomena.Conversations.Message do belongs_to :from, User field :body, :string + field :body_md, :string timestamps(inserted_at: :created_at, type: :utc_datetime) end diff --git a/lib/philomena/dnp_entries/dnp_entry.ex b/lib/philomena/dnp_entries/dnp_entry.ex index e59ab21e..14b5e90f 100644 --- a/lib/philomena/dnp_entries/dnp_entry.ex +++ b/lib/philomena/dnp_entries/dnp_entry.ex @@ -17,6 +17,9 @@ defmodule Philomena.DnpEntries.DnpEntry do field :hide_reason, :boolean, default: false field :instructions, :string, default: "" field :feedback, :string, default: "" + field :conditions_md, :string, default: "" + field :reason_md, :string, default: "" + field :instructions_md, :string, default: "" timestamps(inserted_at: :created_at, type: :utc_datetime) end diff --git a/lib/philomena/filters/filter.ex b/lib/philomena/filters/filter.ex index ea862b2b..e00dbcba 100644 --- a/lib/philomena/filters/filter.ex +++ b/lib/philomena/filters/filter.ex @@ -12,6 +12,7 @@ defmodule Philomena.Filters.Filter do field :name, :string field :description, :string, default: "" + field :description_md, :string, default: "" field :system, :boolean field :public, :boolean field :hidden_complex_str, :string diff --git a/lib/philomena/galleries/gallery.ex b/lib/philomena/galleries/gallery.ex index 9be09592..8225bf19 100644 --- a/lib/philomena/galleries/gallery.ex +++ b/lib/philomena/galleries/gallery.ex @@ -17,6 +17,7 @@ defmodule Philomena.Galleries.Gallery do field :title, :string field :spoiler_warning, :string, default: "" field :description, :string, default: "" + field :description_md, :string, default: "" field :image_count, :integer field :order_position_asc, :boolean diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index bbb7cba8..a302d70a 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -64,6 +64,7 @@ defmodule Philomena.Images.Image do field :votes_count, :integer, default: 0 field :source_url, :string field :description, :string, default: "" + field :description_md, :string, default: "" field :image_sha512_hash, :string field :image_orig_sha512_hash, :string field :deletion_reason, :string @@ -80,6 +81,7 @@ defmodule Philomena.Images.Image do field :destroyed_content, :boolean field :hidden_image_key, :string field :scratchpad, :string + field :scratchpad_md, :string field :hides_count, :integer, default: 0 # todo: can probably remove these now diff --git a/lib/philomena/mod_notes/mod_note.ex b/lib/philomena/mod_notes/mod_note.ex index 8344b7ec..acc3555b 100644 --- a/lib/philomena/mod_notes/mod_note.ex +++ b/lib/philomena/mod_notes/mod_note.ex @@ -12,6 +12,7 @@ defmodule Philomena.ModNotes.ModNote do field :notable_type, :string field :body, :string + field :body_md, :string field :notable, :any, virtual: true diff --git a/lib/philomena/posts/post.ex b/lib/philomena/posts/post.ex index b3c3c42f..1e2c2b96 100644 --- a/lib/philomena/posts/post.ex +++ b/lib/philomena/posts/post.ex @@ -11,6 +11,7 @@ defmodule Philomena.Posts.Post do belongs_to :deleted_by, User field :body, :string + field :body_md, :string field :edit_reason, :string field :ip, EctoNetwork.INET field :fingerprint, :string diff --git a/lib/philomena/reports/report.ex b/lib/philomena/reports/report.ex index 8f8de00b..5fffe5ec 100644 --- a/lib/philomena/reports/report.ex +++ b/lib/philomena/reports/report.ex @@ -13,6 +13,7 @@ defmodule Philomena.Reports.Report do field :user_agent, :string, default: "" field :referrer, :string, default: "" field :reason, :string + field :reason_md, :string field :state, :string, default: "open" field :open, :boolean, default: true diff --git a/lib/philomena/tags/tag.ex b/lib/philomena/tags/tag.ex index 2713a392..fe5e9491 100644 --- a/lib/philomena/tags/tag.ex +++ b/lib/philomena/tags/tag.ex @@ -77,6 +77,7 @@ defmodule Philomena.Tags.Tag do field :category, :string field :images_count, :integer, default: 0 field :description, :string + field :description_md, :string field :short_description, :string field :namespace, :string field :name_in_namespace, :string diff --git a/lib/philomena/users/user.ex b/lib/philomena/users/user.ex index dc41404d..df00d533 100644 --- a/lib/philomena/users/user.ex +++ b/lib/philomena/users/user.ex @@ -65,6 +65,7 @@ defmodule Philomena.Users.User do field :slug, :string field :role, :string, default: "user" field :description, :string + field :description_md, :string field :avatar, :string # Settings @@ -115,6 +116,7 @@ defmodule Philomena.Users.User do field :last_renamed_at, :utc_datetime field :deleted_at, :utc_datetime field :scratchpad, :string + field :scratchpad_md, :string field :secondary_role, :string field :hide_default_role, :boolean, default: false field :senior_staff, :boolean, default: false diff --git a/lib/philomena_web/controllers/admin/dnp_entry_controller.ex b/lib/philomena_web/controllers/admin/dnp_entry_controller.ex index 3e53d7ab..b389f49e 100644 --- a/lib/philomena_web/controllers/admin/dnp_entry_controller.ex +++ b/lib/philomena_web/controllers/admin/dnp_entry_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Admin.DnpEntryController do use PhilomenaWeb, :controller - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.DnpEntries.DnpEntry alias Philomena.Repo import Ecto.Query @@ -44,8 +44,8 @@ defmodule PhilomenaWeb.Admin.DnpEntryController do bodies = dnp_entries - |> Enum.map(&%{body: &1.conditions}) - |> TextileRenderer.render_collection(conn) + |> Enum.map(&%{body: &1.conditions, body_md: &1.conditions_md}) + |> TextRenderer.render_collection(conn) dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)} diff --git a/lib/philomena_web/controllers/admin/mod_note_controller.ex b/lib/philomena_web/controllers/admin/mod_note_controller.ex index 53d91eb1..275bd7e0 100644 --- a/lib/philomena_web/controllers/admin/mod_note_controller.ex +++ b/lib/philomena_web/controllers/admin/mod_note_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do use PhilomenaWeb, :controller - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.ModNotes.ModNote alias Philomena.Polymorphic alias Philomena.ModNotes @@ -29,7 +29,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) - bodies = TextileRenderer.render_collection(mod_notes, conn) + bodies = TextRenderer.render_collection(mod_notes, conn) preloaded = Polymorphic.load_polymorphic(mod_notes, notable: [notable_id: :notable_type]) mod_notes = %{mod_notes | entries: Enum.zip(bodies, preloaded)} diff --git a/lib/philomena_web/controllers/admin/report_controller.ex b/lib/philomena_web/controllers/admin/report_controller.ex index 40fbf191..1a40356f 100644 --- a/lib/philomena_web/controllers/admin/report_controller.ex +++ b/lib/philomena_web/controllers/admin/report_controller.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.Admin.ReportController do use PhilomenaWeb, :controller alias Philomena.Elasticsearch - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Reports.Report alias Philomena.Reports.Query alias Philomena.Polymorphic @@ -73,7 +73,7 @@ defmodule PhilomenaWeb.Admin.ReportController do reportable: [reportable_id: :reportable_type] ) - body = TextileRenderer.render_one(%{body: report.reason}, conn) + body = TextRenderer.render_one(%{body: report.reason, body_md: report.reason_md}, conn) render(conn, "show.html", title: "Showing Report", report: report, body: body) end @@ -125,7 +125,7 @@ defmodule PhilomenaWeb.Admin.ReportController do mod_notes = mod_notes - |> TextileRenderer.render_collection(conn) + |> TextRenderer.render_collection(conn) |> Enum.zip(mod_notes) assign(conn, :mod_notes, mod_notes) diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index f494fe08..4f2f4ef0 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.CommentController do use PhilomenaWeb, :controller - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Elasticsearch alias Philomena.{Comments.Query, Comments.Comment} import Ecto.Query @@ -39,7 +39,7 @@ defmodule PhilomenaWeb.CommentController do preload(Comment, [:deleted_by, image: [tags: :aliases], user: [awards: :badge]]) ) - rendered = TextileRenderer.render_collection(comments.entries, conn) + rendered = TextRenderer.render_collection(comments.entries, conn) comments = %{comments | entries: Enum.zip(rendered, comments.entries)} diff --git a/lib/philomena_web/controllers/conversation_controller.ex b/lib/philomena_web/controllers/conversation_controller.ex index 1292c441..9a843df4 100644 --- a/lib/philomena_web/controllers/conversation_controller.ex +++ b/lib/philomena_web/controllers/conversation_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.ConversationController do alias PhilomenaWeb.NotificationCountPlug alias Philomena.{Conversations, Conversations.Conversation, Conversations.Message} - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Repo import Ecto.Query @@ -72,7 +72,7 @@ defmodule PhilomenaWeb.ConversationController do rendered = messages.entries - |> TextileRenderer.render_collection(conn) + |> TextRenderer.render_collection(conn) messages = %{messages | entries: Enum.zip(messages.entries, rendered)} diff --git a/lib/philomena_web/controllers/dnp_entry_controller.ex b/lib/philomena_web/controllers/dnp_entry_controller.ex index f4dcfca5..38f7127a 100644 --- a/lib/philomena_web/controllers/dnp_entry_controller.ex +++ b/lib/philomena_web/controllers/dnp_entry_controller.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.DnpEntryController do use PhilomenaWeb, :controller alias Philomena.DnpEntries.DnpEntry - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.DnpEntries alias Philomena.Tags.Tag alias Philomena.ModNotes.ModNote @@ -43,8 +43,8 @@ defmodule PhilomenaWeb.DnpEntryController do bodies = dnp_entries - |> Enum.map(&%{body: &1.conditions || "-"}) - |> TextileRenderer.render_collection(conn) + |> Enum.map(&%{body_md: &1.conditions_md, body: &1.conditions || "-"}) + |> TextRenderer.render_collection(conn) dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)} @@ -61,11 +61,11 @@ defmodule PhilomenaWeb.DnpEntryController do dnp_entry = conn.assigns.dnp_entry [conditions, reason, instructions] = - TextileRenderer.render_collection( + TextRenderer.render_collection( [ - %{body: dnp_entry.conditions || "-"}, - %{body: dnp_entry.reason || "-"}, - %{body: dnp_entry.instructions || "-"} + %{body_md: dnp_entry.conditions_md, body: dnp_entry.conditions || "-"}, + %{body_md: dnp_entry.reason_md, body: dnp_entry.reason || "-"}, + %{body_md: dnp_entry.instructions_md, body: dnp_entry.instructions || "-"} ], conn ) @@ -164,7 +164,7 @@ defmodule PhilomenaWeb.DnpEntryController do mod_notes = mod_notes - |> TextileRenderer.render_collection(conn) + |> TextRenderer.render_collection(conn) |> Enum.zip(mod_notes) assign(conn, :mod_notes, mod_notes) diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index 3e75cc76..ebb605c3 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.Image.CommentController do use PhilomenaWeb, :controller alias PhilomenaWeb.CommentLoader - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.{Images.Image, Comments.Comment} alias Philomena.UserStatistics alias Philomena.Comments @@ -48,7 +48,7 @@ defmodule PhilomenaWeb.Image.CommentController do def index(conn, _params) do comments = CommentLoader.load_comments(conn, conn.assigns.image) - rendered = TextileRenderer.render_collection(comments.entries, conn) + rendered = TextRenderer.render_collection(comments.entries, conn) comments = %{comments | entries: Enum.zip(comments.entries, rendered)} @@ -56,7 +56,7 @@ defmodule PhilomenaWeb.Image.CommentController do end def show(conn, _params) do - rendered = TextileRenderer.render_one(conn.assigns.comment, conn) + rendered = TextRenderer.render_one(conn.assigns.comment, conn) render(conn, "show.html", layout: false, diff --git a/lib/philomena_web/controllers/image/description_controller.ex b/lib/philomena_web/controllers/image/description_controller.ex index f09f12fe..7e508567 100644 --- a/lib/philomena_web/controllers/image/description_controller.ex +++ b/lib/philomena_web/controllers/image/description_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do use PhilomenaWeb, :controller - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Images.Image alias Philomena.Images @@ -34,7 +34,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do Images.reindex_image(image) - body = TextileRenderer.render_one(%{body: image.description}, conn) + body = TextRenderer.render_one(%{body: image.description, body_md: image.description_md}, conn) conn |> put_view(PhilomenaWeb.ImageView) diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 31f94104..10c9dc47 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -4,7 +4,7 @@ defmodule PhilomenaWeb.ImageController do alias PhilomenaWeb.ImageLoader alias PhilomenaWeb.CommentLoader alias PhilomenaWeb.NotificationCountPlug - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.{ Images, @@ -63,13 +63,13 @@ defmodule PhilomenaWeb.ImageController do comments = CommentLoader.load_comments(conn, image) - rendered = TextileRenderer.render_collection(comments.entries, conn) + rendered = TextRenderer.render_collection(comments.entries, conn) comments = %{comments | entries: Enum.zip(comments.entries, rendered)} description = - %{body: image.description} - |> TextileRenderer.render_one(conn) + %{body: image.description, body_md: image.description_md} + |> TextRenderer.render_one(conn) interactions = Interactions.user_interactions([image], conn.assigns.current_user) diff --git a/lib/philomena_web/controllers/post/preview_controller.ex b/lib/philomena_web/controllers/post/preview_controller.ex index 00416436..b5a34e75 100644 --- a/lib/philomena_web/controllers/post/preview_controller.ex +++ b/lib/philomena_web/controllers/post/preview_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Post.PreviewController do use PhilomenaWeb, :controller - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Posts.Post alias Philomena.Repo @@ -10,8 +10,8 @@ defmodule PhilomenaWeb.Post.PreviewController do body = to_string(params["body"]) anonymous = params["anonymous"] == true - post = %Post{user: user, body: body, anonymous: anonymous} - rendered = TextileRenderer.render_one(post, conn) + post = %Post{user: user, body_md: body, anonymous: anonymous} + rendered = TextRenderer.render_one(post, conn) render(conn, "create.html", layout: false, post: post, body: rendered) end diff --git a/lib/philomena_web/controllers/post_controller.ex b/lib/philomena_web/controllers/post_controller.ex index 0685d1ab..e849b5ba 100644 --- a/lib/philomena_web/controllers/post_controller.ex +++ b/lib/philomena_web/controllers/post_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.PostController do use PhilomenaWeb, :controller - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Elasticsearch alias Philomena.{Posts.Query, Posts.Post} import Ecto.Query @@ -36,7 +36,7 @@ defmodule PhilomenaWeb.PostController do preload(Post, [:deleted_by, topic: :forum, user: [awards: :badge]]) ) - rendered = TextileRenderer.render_collection(posts.entries, conn) + rendered = TextRenderer.render_collection(posts.entries, conn) posts = %{posts | entries: Enum.zip(rendered, posts.entries)} diff --git a/lib/philomena_web/controllers/profile/commission_controller.ex b/lib/philomena_web/controllers/profile/commission_controller.ex index e677fc4f..0a9134d2 100644 --- a/lib/philomena_web/controllers/profile/commission_controller.ex +++ b/lib/philomena_web/controllers/profile/commission_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do alias Philomena.Commissions.Commission alias Philomena.Commissions - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Users.User plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :delete] @@ -36,21 +36,21 @@ defmodule PhilomenaWeb.Profile.CommissionController do item_descriptions = items - |> Enum.map(&%{body: &1.description}) - |> TextileRenderer.render_collection(conn) + |> Enum.map(&%{body: &1.description, body_md: &1.description_md}) + |> TextRenderer.render_collection(conn) item_add_ons = items - |> Enum.map(&%{body: &1.add_ons}) - |> TextileRenderer.render_collection(conn) + |> Enum.map(&%{body: &1.add_ons, body_md: &1.add_ons_md}) + |> TextRenderer.render_collection(conn) [information, contact, will_create, will_not_create] = - TextileRenderer.render_collection( + TextRenderer.render_collection( [ - %{body: commission.information || ""}, - %{body: commission.contact || ""}, - %{body: commission.will_create || ""}, - %{body: commission.will_not_create || ""} + %{body_md: commission.information_md, body: commission.information || ""}, + %{body_md: commission.contact_md, body: commission.contact || ""}, + %{body_md: commission.will_create_md, body: commission.will_create || ""}, + %{body_md: commission.will_not_create_md, body: commission.will_not_create || ""} ], conn ) diff --git a/lib/philomena_web/controllers/profile/detail_controller.ex b/lib/philomena_web/controllers/profile/detail_controller.ex index ced52900..17e88b0f 100644 --- a/lib/philomena_web/controllers/profile/detail_controller.ex +++ b/lib/philomena_web/controllers/profile/detail_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.Profile.DetailController do alias Philomena.UserNameChanges.UserNameChange alias Philomena.ModNotes.ModNote - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Polymorphic alias Philomena.Users.User alias Philomena.Repo @@ -30,7 +30,7 @@ defmodule PhilomenaWeb.Profile.DetailController do mod_notes = mod_notes - |> TextileRenderer.render_collection(conn) + |> TextRenderer.render_collection(conn) |> Enum.zip(mod_notes) name_changes = diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 6388d25b..b0cb6a2d 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.ProfileController do alias PhilomenaWeb.ImageLoader alias Philomena.Elasticsearch - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.UserStatistics.UserStatistic alias Philomena.Users.User alias Philomena.Bans @@ -131,12 +131,12 @@ defmodule PhilomenaWeb.ProfileController do recent_comments = recent_comments |> Enum.filter(&Canada.Can.can?(current_user, :show, &1.image)) - |> TextileRenderer.render_collection(conn) + |> TextRenderer.render_collection(conn) |> Enum.zip(recent_comments) - about_me = TextileRenderer.render_one(%{body: user.description || ""}, conn) + about_me = TextRenderer.render_one(%{body_md: user.description_md, body: user.description || ""}, conn) - scratchpad = TextileRenderer.render_one(%{body: user.scratchpad || ""}, conn) + scratchpad = TextRenderer.render_one(%{body_md: user.scratchpad_md, body: user.scratchpad || ""}, conn) commission_information = commission_info(user.commission, conn) @@ -214,8 +214,8 @@ defmodule PhilomenaWeb.ProfileController do defp map_fetch(nil, _field_name), do: nil defp map_fetch(map, field_name), do: Map.get(map, field_name) - defp commission_info(%{information: info}, conn) when info not in [nil, ""], - do: TextileRenderer.render_one(%{body: info}, conn) + defp commission_info(%{information: info, information_md: info_md}, conn) when info not in [nil, ""], + do: TextRenderer.render_one(%{body: info, body_md: info_md}, conn) defp commission_info(_commission, _conn), do: "" @@ -282,7 +282,7 @@ defmodule PhilomenaWeb.ProfileController do mod_notes = mod_notes - |> TextileRenderer.render_collection(conn) + |> TextRenderer.render_collection(conn) |> Enum.zip(mod_notes) assign(conn, :mod_notes, mod_notes) diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 7f55bcf7..ee4c6f3b 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.TagController do alias Philomena.Elasticsearch alias Philomena.{Tags, Tags.Tag} alias Philomena.{Images, Images.Image} - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Interactions import Ecto.Query @@ -61,11 +61,11 @@ defmodule PhilomenaWeb.TagController do interactions = Interactions.user_interactions(images, user) - body = TextileRenderer.render_one(%{body: tag.description || ""}, conn) + body = TextRenderer.render_one(%{body_md: tag.description_md, body: tag.description || ""}, conn) dnp_bodies = - TextileRenderer.render_collection( - Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), + TextRenderer.render_collection( + Enum.map(tag.dnp_entries, &%{body_md: &1.conditions_md, body: &1.conditions || ""}), conn ) diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index e9eeea3d..536d9336 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.TopicController do alias Philomena.{Forums.Forum, Topics.Topic, Posts.Post, Polls.Poll, PollOptions.PollOption} alias Philomena.{Forums, Topics, Polls, Posts} alias Philomena.PollVotes - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Repo import Ecto.Query @@ -60,7 +60,7 @@ defmodule PhilomenaWeb.TopicController do |> preload([:deleted_by, :topic, topic: :forum, user: [awards: :badge]]) |> Repo.all() - rendered = TextileRenderer.render_collection(posts, conn) + rendered = TextRenderer.render_collection(posts, conn) posts = Enum.zip(posts, rendered) diff --git a/lib/philomena_web/image_loader.ex b/lib/philomena_web/image_loader.ex index 57035234..914404e6 100644 --- a/lib/philomena_web/image_loader.ex +++ b/lib/philomena_web/image_loader.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.ImageLoader do alias PhilomenaWeb.ImageSorter alias Philomena.Elasticsearch alias Philomena.Images.{Image, Query} - alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.TextRenderer alias Philomena.Tags.Tag alias Philomena.Repo import Ecto.Query @@ -132,14 +132,14 @@ defmodule PhilomenaWeb.ImageLoader do defp render_bodies([tag], conn) do dnp_bodies = - TextileRenderer.render_collection( - Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), + TextRenderer.render_collection( + Enum.map(tag.dnp_entries, &%{body_md: &1.conditions_md, body: &1.conditions || ""}), conn ) dnp_entries = Enum.zip(dnp_bodies, tag.dnp_entries) - description = TextileRenderer.render_one(%{body: tag.description || ""}, conn) + description = TextRenderer.render_one(%{body_md: tag.description_md, body: tag.description || ""}, conn) [{tag, description, dnp_entries}] end diff --git a/lib/philomena_web/markdown_renderer.ex b/lib/philomena_web/markdown_renderer.ex new file mode 100644 index 00000000..72e7376a --- /dev/null +++ b/lib/philomena_web/markdown_renderer.ex @@ -0,0 +1,7 @@ +defmodule PhilomenaWeb.MarkdownRenderer do + alias Philomena.Markdown + + def render(text, _conn) do + Markdown.to_html(text) + end +end diff --git a/lib/philomena_web/text_renderer.ex b/lib/philomena_web/text_renderer.ex new file mode 100644 index 00000000..96152a50 --- /dev/null +++ b/lib/philomena_web/text_renderer.ex @@ -0,0 +1,18 @@ +defmodule PhilomenaWeb.TextRenderer do + alias PhilomenaWeb.TextileRenderer + alias PhilomenaWeb.MarkdownRenderer + + def render_one(item, conn) do + hd(render_collection([item], conn)) + end + + def render_collection(items, conn) do + Enum.map(items, fn item -> + if Map.has_key?(item, :body_md) && item.body_md != nil && item.body_md != "" do + MarkdownRenderer.render(item.body_md, conn) + else + TextileRenderer.render(item.body, conn) + end + end) + end +end diff --git a/lib/philomena_web/textile_renderer.ex b/lib/philomena_web/textile_renderer.ex index ade73e97..50870dfd 100644 --- a/lib/philomena_web/textile_renderer.ex +++ b/lib/philomena_web/textile_renderer.ex @@ -9,44 +9,32 @@ defmodule PhilomenaWeb.TextileRenderer do # Kill bogus compile time dependency on ImageView @image_view Module.concat(["PhilomenaWeb.ImageView"]) - def render_one(post, conn) do - hd(render_collection([post], conn)) - end + def render(text, conn) do + opts = %{image_transform: &Camo.Image.image_url/1} + parsed = Parser.parse(opts, text) + + images = + parsed + |> Enum.flat_map(fn + {:text, text} -> + [text] - def render_collection(posts, conn) do - # opts = %{image_transform: &Camo.Image.image_url/1} - # parsed = Enum.map(posts, &Parser.parse(opts, &1.body)) + _ -> + [] + end) + |> find_images - Enum.map(posts, &Philomena.Markdown.to_html(&1.body)) + parsed + |> Enum.map(fn + {:text, text} -> + text + |> replacement_entities() + |> replacement_images(conn, images) - # images = - # parsed - # |> Enum.flat_map(fn tree -> - # tree - # |> Enum.flat_map(fn - # {:text, text} -> - # [text] - - # _ -> - # [] - # end) - # end) - # |> find_images - - # parsed - # |> Enum.map(fn tree -> - # tree - # |> Enum.map(fn - # {:text, text} -> - # text - # |> replacement_entities() - # |> replacement_images(conn, images) - - # {_k, markup} -> - # markup - # end) - # |> Enum.join() - # end) + {_k, markup} -> + markup + end) + |> Enum.join() end defp replacement_entities(t) do diff --git a/priv/repo/migrations/20210912171343_add_markdown_columns.exs b/priv/repo/migrations/20210912171343_add_markdown_columns.exs new file mode 100644 index 00000000..21267871 --- /dev/null +++ b/priv/repo/migrations/20210912171343_add_markdown_columns.exs @@ -0,0 +1,145 @@ +defmodule Philomena.Repo.Migrations.AddMarkdownColumns do + use Ecto.Migration + + def up do + alter table("comments") do + add :body_md, :varchar, default: nil + end + + alter table("messages") do + add :body_md, :varchar, default: nil + end + + alter table("mod_notes") do + add :body_md, :varchar, default: nil + end + + alter table("posts") do + add :body_md, :varchar, default: nil + end + + alter table("badges") do + add :description_md, :varchar, default: nil + end + + alter table("channels") do + add :description_md, :varchar, default: nil + end + + alter table("commission_items") do + add :description_md, :varchar, default: nil + add :add_ons_md, :varchar, default: nil + end + + alter table("filters") do + add :description_md, :varchar, default: nil + end + + alter table("galleries") do + add :description_md, :varchar, default: nil + end + + alter table("images") do + add :description_md, :varchar, default: nil + add :scratchpad_md, :varchar, default: nil + end + + alter table("tags") do + add :description_md, :varchar, default: nil + end + + alter table("users") do + add :description_md, :varchar, default: nil + add :scratchpad_md, :varchar, default: nil + end + + alter table("dnp_entries") do + add :conditions_md, :varchar, default: nil + add :reason_md, :varchar, default: nil + add :instructions_md, :varchar, default: nil + end + + alter table("commissions") do + add :information_md, :varchar, default: nil + add :contact_md, :varchar, default: nil + add :will_create_md, :varchar, default: nil + add :will_not_create_md, :varchar, default: nil + end + + alter table("reports") do + add :reason_md, :varchar, default: nil + end + end + + def down do + alter table("comments") do + remove :body_md + end + + alter table("messages") do + remove :body_md + end + + alter table("mod_notes") do + remove :body_md + end + + alter table("posts") do + remove :body_md + end + + alter table("badges") do + remove :description_md + end + + alter table("channels") do + remove :description_md + end + + alter table("commission_items") do + remove :description_md + remove :add_ons_md + end + + alter table("filters") do + remove :description_md + end + + alter table("galleries") do + remove :description_md + end + + alter table("images") do + remove :description_md + remove :scratchpad_md + end + + alter table("tags") do + remove :description_md + remove :short_description_md + remove :mod_notes_md + end + + alter table("users") do + remove :description_md + remove :scratchpad_md + end + + alter table("dnp_entries") do + remove :conditions_md + remove :reason_md + remove :instructions_md + end + + alter table("commissions") do + remove :information_md + remove :contact_md + remove :will_create_md + remove :will_not_create_md + end + + alter table("reports") do + remove :reason_md + end + end +end diff --git a/priv/repo/structure.sql b/priv/repo/structure.sql index 3337ab7d..b53aabc2 100644 --- a/priv/repo/structure.sql +++ b/priv/repo/structure.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 13.2 --- Dumped by pg_dump version 13.2 +-- Dumped from database version 13.4 +-- Dumped by pg_dump version 13.4 SET statement_timeout = 0; SET lock_timeout = 0; @@ -165,7 +165,8 @@ CREATE TABLE public.badges ( created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, disable_award boolean DEFAULT false NOT NULL, - priority boolean DEFAULT false + priority boolean DEFAULT false, + description_md character varying ); @@ -227,7 +228,8 @@ CREATE TABLE public.channels ( total_viewer_minutes integer DEFAULT 0 NOT NULL, banner_image character varying, remote_stream_id integer, - thumbnail_url character varying DEFAULT ''::character varying + thumbnail_url character varying DEFAULT ''::character varying, + description_md character varying ); @@ -272,7 +274,8 @@ CREATE TABLE public.comments ( edited_at timestamp without time zone, deletion_reason character varying DEFAULT ''::character varying NOT NULL, destroyed_content boolean DEFAULT false, - name_at_post_time character varying + name_at_post_time character varying, + body_md character varying ); @@ -308,7 +311,9 @@ CREATE TABLE public.commission_items ( add_ons character varying, example_image_id integer, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + description_md character varying, + add_ons_md character varying ); @@ -347,7 +352,11 @@ CREATE TABLE public.commissions ( will_not_create character varying, commission_items_count integer DEFAULT 0 NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + information_md character varying, + contact_md character varying, + will_create_md character varying, + will_not_create_md character varying ); @@ -426,7 +435,10 @@ CREATE TABLE public.dnp_entries ( instructions character varying NOT NULL, feedback character varying NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + conditions_md character varying, + reason_md character varying, + instructions_md character varying ); @@ -539,7 +551,8 @@ CREATE TABLE public.filters ( user_count integer DEFAULT 0 NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - user_id integer + user_id integer, + description_md character varying ); @@ -666,7 +679,8 @@ CREATE TABLE public.galleries ( watcher_ids integer[] DEFAULT '{}'::integer[] NOT NULL, watcher_count integer DEFAULT 0 NOT NULL, image_count integer DEFAULT 0 NOT NULL, - order_position_asc boolean DEFAULT false NOT NULL + order_position_asc boolean DEFAULT false NOT NULL, + description_md character varying ); @@ -950,7 +964,9 @@ CREATE TABLE public.images ( hidden_image_key character varying, scratchpad character varying, hides_count integer DEFAULT 0 NOT NULL, - image_duration double precision + image_duration double precision, + description_md character varying, + scratchpad_md character varying ); @@ -983,7 +999,8 @@ CREATE TABLE public.messages ( created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, from_id integer NOT NULL, - conversation_id integer NOT NULL + conversation_id integer NOT NULL, + body_md character varying ); @@ -1018,7 +1035,8 @@ CREATE TABLE public.mod_notes ( body text NOT NULL, deleted boolean DEFAULT false NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + body_md character varying ); @@ -1201,7 +1219,8 @@ CREATE TABLE public.posts ( edited_at timestamp without time zone, deletion_reason character varying DEFAULT ''::character varying NOT NULL, destroyed_content boolean DEFAULT false NOT NULL, - name_at_post_time character varying + name_at_post_time character varying, + body_md character varying ); @@ -1242,7 +1261,8 @@ CREATE TABLE public.reports ( user_id integer, admin_id integer, reportable_id integer NOT NULL, - reportable_type character varying NOT NULL + reportable_type character varying NOT NULL, + reason_md character varying ); @@ -1549,7 +1569,8 @@ CREATE TABLE public.tags ( created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, category character varying, - mod_notes character varying + mod_notes character varying, + description_md character varying ); @@ -1988,7 +2009,9 @@ CREATE TABLE public.users ( last_renamed_at timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, forced_filter_id bigint, confirmed_at timestamp(0) without time zone, - senior_staff boolean DEFAULT false + senior_staff boolean DEFAULT false, + description_md character varying, + scratchpad_md character varying ); @@ -4844,3 +4867,4 @@ INSERT INTO public."schema_migrations" (version) VALUES (20201124224116); INSERT INTO public."schema_migrations" (version) VALUES (20210121200815); INSERT INTO public."schema_migrations" (version) VALUES (20210301012137); INSERT INTO public."schema_migrations" (version) VALUES (20210427022351); +INSERT INTO public."schema_migrations" (version) VALUES (20210912171343);