add *_md versions of all columns, textile/md glue

This commit is contained in:
Luna D 2021-09-12 21:03:59 +02:00
parent cb0ac0a9f5
commit 14db174c26
No known key found for this signature in database
GPG key ID: 81AF416F2CC36FC8
37 changed files with 320 additions and 115 deletions

View file

@ -5,6 +5,7 @@ defmodule Philomena.Badges.Badge do
schema "badges" do schema "badges" do
field :title, :string field :title, :string
field :description, :string, default: "" field :description, :string, default: ""
field :description_md, :string, default: ""
field :image, :string field :image, :string
field :disable_award, :boolean, default: false field :disable_award, :boolean, default: false
field :priority, :boolean, default: false field :priority, :boolean, default: false

View file

@ -14,6 +14,7 @@ defmodule Philomena.Channels.Channel do
field :short_name, :string field :short_name, :string
field :title, :string, default: "" field :title, :string, default: ""
field :description, :string field :description, :string
field :description_md, :string
field :tags, :string field :tags, :string
field :viewers, :integer, default: 0 field :viewers, :integer, default: 0
field :nsfw, :boolean, default: false field :nsfw, :boolean, default: false

View file

@ -11,6 +11,7 @@ defmodule Philomena.Comments.Comment do
belongs_to :deleted_by, User belongs_to :deleted_by, User
field :body, :string field :body, :string
field :body_md, :string
field :ip, EctoNetwork.INET field :ip, EctoNetwork.INET
field :fingerprint, :string field :fingerprint, :string
field :user_agent, :string, default: "" field :user_agent, :string, default: ""

View file

@ -17,6 +17,10 @@ defmodule Philomena.Commissions.Commission do
field :contact, :string field :contact, :string
field :will_create, :string field :will_create, :string
field :will_not_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 field :commission_items_count, :integer, default: 0
timestamps(inserted_at: :created_at, type: :utc_datetime) timestamps(inserted_at: :created_at, type: :utc_datetime)

View file

@ -11,8 +11,10 @@ defmodule Philomena.Commissions.Item do
field :item_type, :string field :item_type, :string
field :description, :string field :description, :string
field :description_md, :string
field :base_price, :decimal field :base_price, :decimal
field :add_ons, :string field :add_ons, :string
field :add_ons_md, :string
timestamps(inserted_at: :created_at, type: :utc_datetime) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end

View file

@ -10,6 +10,7 @@ defmodule Philomena.Conversations.Message do
belongs_to :from, User belongs_to :from, User
field :body, :string field :body, :string
field :body_md, :string
timestamps(inserted_at: :created_at, type: :utc_datetime) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end

View file

@ -17,6 +17,9 @@ defmodule Philomena.DnpEntries.DnpEntry do
field :hide_reason, :boolean, default: false field :hide_reason, :boolean, default: false
field :instructions, :string, default: "" field :instructions, :string, default: ""
field :feedback, :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) timestamps(inserted_at: :created_at, type: :utc_datetime)
end end

View file

@ -12,6 +12,7 @@ defmodule Philomena.Filters.Filter do
field :name, :string field :name, :string
field :description, :string, default: "" field :description, :string, default: ""
field :description_md, :string, default: ""
field :system, :boolean field :system, :boolean
field :public, :boolean field :public, :boolean
field :hidden_complex_str, :string field :hidden_complex_str, :string

View file

@ -17,6 +17,7 @@ defmodule Philomena.Galleries.Gallery do
field :title, :string field :title, :string
field :spoiler_warning, :string, default: "" field :spoiler_warning, :string, default: ""
field :description, :string, default: "" field :description, :string, default: ""
field :description_md, :string, default: ""
field :image_count, :integer field :image_count, :integer
field :order_position_asc, :boolean field :order_position_asc, :boolean

View file

@ -64,6 +64,7 @@ defmodule Philomena.Images.Image do
field :votes_count, :integer, default: 0 field :votes_count, :integer, default: 0
field :source_url, :string field :source_url, :string
field :description, :string, default: "" field :description, :string, default: ""
field :description_md, :string, default: ""
field :image_sha512_hash, :string field :image_sha512_hash, :string
field :image_orig_sha512_hash, :string field :image_orig_sha512_hash, :string
field :deletion_reason, :string field :deletion_reason, :string
@ -80,6 +81,7 @@ defmodule Philomena.Images.Image do
field :destroyed_content, :boolean field :destroyed_content, :boolean
field :hidden_image_key, :string field :hidden_image_key, :string
field :scratchpad, :string field :scratchpad, :string
field :scratchpad_md, :string
field :hides_count, :integer, default: 0 field :hides_count, :integer, default: 0
# todo: can probably remove these now # todo: can probably remove these now

View file

@ -12,6 +12,7 @@ defmodule Philomena.ModNotes.ModNote do
field :notable_type, :string field :notable_type, :string
field :body, :string field :body, :string
field :body_md, :string
field :notable, :any, virtual: true field :notable, :any, virtual: true

View file

@ -11,6 +11,7 @@ defmodule Philomena.Posts.Post do
belongs_to :deleted_by, User belongs_to :deleted_by, User
field :body, :string field :body, :string
field :body_md, :string
field :edit_reason, :string field :edit_reason, :string
field :ip, EctoNetwork.INET field :ip, EctoNetwork.INET
field :fingerprint, :string field :fingerprint, :string

View file

@ -13,6 +13,7 @@ defmodule Philomena.Reports.Report do
field :user_agent, :string, default: "" field :user_agent, :string, default: ""
field :referrer, :string, default: "" field :referrer, :string, default: ""
field :reason, :string field :reason, :string
field :reason_md, :string
field :state, :string, default: "open" field :state, :string, default: "open"
field :open, :boolean, default: true field :open, :boolean, default: true

View file

@ -77,6 +77,7 @@ defmodule Philomena.Tags.Tag do
field :category, :string field :category, :string
field :images_count, :integer, default: 0 field :images_count, :integer, default: 0
field :description, :string field :description, :string
field :description_md, :string
field :short_description, :string field :short_description, :string
field :namespace, :string field :namespace, :string
field :name_in_namespace, :string field :name_in_namespace, :string

View file

@ -65,6 +65,7 @@ defmodule Philomena.Users.User do
field :slug, :string field :slug, :string
field :role, :string, default: "user" field :role, :string, default: "user"
field :description, :string field :description, :string
field :description_md, :string
field :avatar, :string field :avatar, :string
# Settings # Settings
@ -115,6 +116,7 @@ defmodule Philomena.Users.User do
field :last_renamed_at, :utc_datetime field :last_renamed_at, :utc_datetime
field :deleted_at, :utc_datetime field :deleted_at, :utc_datetime
field :scratchpad, :string field :scratchpad, :string
field :scratchpad_md, :string
field :secondary_role, :string field :secondary_role, :string
field :hide_default_role, :boolean, default: false field :hide_default_role, :boolean, default: false
field :senior_staff, :boolean, default: false field :senior_staff, :boolean, default: false

View file

@ -1,7 +1,7 @@
defmodule PhilomenaWeb.Admin.DnpEntryController do defmodule PhilomenaWeb.Admin.DnpEntryController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.DnpEntries.DnpEntry alias Philomena.DnpEntries.DnpEntry
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@ -44,8 +44,8 @@ defmodule PhilomenaWeb.Admin.DnpEntryController do
bodies = bodies =
dnp_entries dnp_entries
|> Enum.map(&%{body: &1.conditions}) |> Enum.map(&%{body: &1.conditions, body_md: &1.conditions_md})
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)} dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)}

View file

@ -1,7 +1,7 @@
defmodule PhilomenaWeb.Admin.ModNoteController do defmodule PhilomenaWeb.Admin.ModNoteController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.ModNotes.ModNote alias Philomena.ModNotes.ModNote
alias Philomena.Polymorphic alias Philomena.Polymorphic
alias Philomena.ModNotes alias Philomena.ModNotes
@ -29,7 +29,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> 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]) preloaded = Polymorphic.load_polymorphic(mod_notes, notable: [notable_id: :notable_type])
mod_notes = %{mod_notes | entries: Enum.zip(bodies, preloaded)} mod_notes = %{mod_notes | entries: Enum.zip(bodies, preloaded)}

View file

@ -2,7 +2,7 @@ defmodule PhilomenaWeb.Admin.ReportController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Reports.Report alias Philomena.Reports.Report
alias Philomena.Reports.Query alias Philomena.Reports.Query
alias Philomena.Polymorphic alias Philomena.Polymorphic
@ -73,7 +73,7 @@ defmodule PhilomenaWeb.Admin.ReportController do
reportable: [reportable_id: :reportable_type] 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) render(conn, "show.html", title: "Showing Report", report: report, body: body)
end end
@ -125,7 +125,7 @@ defmodule PhilomenaWeb.Admin.ReportController do
mod_notes = mod_notes =
mod_notes mod_notes
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
|> Enum.zip(mod_notes) |> Enum.zip(mod_notes)
assign(conn, :mod_notes, mod_notes) assign(conn, :mod_notes, mod_notes)

View file

@ -1,7 +1,7 @@
defmodule PhilomenaWeb.CommentController do defmodule PhilomenaWeb.CommentController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.{Comments.Query, Comments.Comment} alias Philomena.{Comments.Query, Comments.Comment}
import Ecto.Query import Ecto.Query
@ -39,7 +39,7 @@ defmodule PhilomenaWeb.CommentController do
preload(Comment, [:deleted_by, image: [tags: :aliases], user: [awards: :badge]]) 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)} comments = %{comments | entries: Enum.zip(rendered, comments.entries)}

View file

@ -3,7 +3,7 @@ defmodule PhilomenaWeb.ConversationController do
alias PhilomenaWeb.NotificationCountPlug alias PhilomenaWeb.NotificationCountPlug
alias Philomena.{Conversations, Conversations.Conversation, Conversations.Message} alias Philomena.{Conversations, Conversations.Conversation, Conversations.Message}
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@ -72,7 +72,7 @@ defmodule PhilomenaWeb.ConversationController do
rendered = rendered =
messages.entries messages.entries
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
messages = %{messages | entries: Enum.zip(messages.entries, rendered)} messages = %{messages | entries: Enum.zip(messages.entries, rendered)}

View file

@ -2,7 +2,7 @@ defmodule PhilomenaWeb.DnpEntryController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias Philomena.DnpEntries.DnpEntry alias Philomena.DnpEntries.DnpEntry
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.DnpEntries alias Philomena.DnpEntries
alias Philomena.Tags.Tag alias Philomena.Tags.Tag
alias Philomena.ModNotes.ModNote alias Philomena.ModNotes.ModNote
@ -43,8 +43,8 @@ defmodule PhilomenaWeb.DnpEntryController do
bodies = bodies =
dnp_entries dnp_entries
|> Enum.map(&%{body: &1.conditions || "-"}) |> Enum.map(&%{body_md: &1.conditions_md, body: &1.conditions || "-"})
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)} 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 dnp_entry = conn.assigns.dnp_entry
[conditions, reason, instructions] = [conditions, reason, instructions] =
TextileRenderer.render_collection( TextRenderer.render_collection(
[ [
%{body: dnp_entry.conditions || "-"}, %{body_md: dnp_entry.conditions_md, body: dnp_entry.conditions || "-"},
%{body: dnp_entry.reason || "-"}, %{body_md: dnp_entry.reason_md, body: dnp_entry.reason || "-"},
%{body: dnp_entry.instructions || "-"} %{body_md: dnp_entry.instructions_md, body: dnp_entry.instructions || "-"}
], ],
conn conn
) )
@ -164,7 +164,7 @@ defmodule PhilomenaWeb.DnpEntryController do
mod_notes = mod_notes =
mod_notes mod_notes
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
|> Enum.zip(mod_notes) |> Enum.zip(mod_notes)
assign(conn, :mod_notes, mod_notes) assign(conn, :mod_notes, mod_notes)

View file

@ -2,7 +2,7 @@ defmodule PhilomenaWeb.Image.CommentController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.CommentLoader alias PhilomenaWeb.CommentLoader
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.{Images.Image, Comments.Comment} alias Philomena.{Images.Image, Comments.Comment}
alias Philomena.UserStatistics alias Philomena.UserStatistics
alias Philomena.Comments alias Philomena.Comments
@ -48,7 +48,7 @@ defmodule PhilomenaWeb.Image.CommentController do
def index(conn, _params) do def index(conn, _params) do
comments = CommentLoader.load_comments(conn, conn.assigns.image) 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)} comments = %{comments | entries: Enum.zip(comments.entries, rendered)}
@ -56,7 +56,7 @@ defmodule PhilomenaWeb.Image.CommentController do
end end
def show(conn, _params) do 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", render(conn, "show.html",
layout: false, layout: false,

View file

@ -1,7 +1,7 @@
defmodule PhilomenaWeb.Image.DescriptionController do defmodule PhilomenaWeb.Image.DescriptionController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Images.Image alias Philomena.Images.Image
alias Philomena.Images alias Philomena.Images
@ -34,7 +34,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do
Images.reindex_image(image) 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 conn
|> put_view(PhilomenaWeb.ImageView) |> put_view(PhilomenaWeb.ImageView)

View file

@ -4,7 +4,7 @@ defmodule PhilomenaWeb.ImageController do
alias PhilomenaWeb.ImageLoader alias PhilomenaWeb.ImageLoader
alias PhilomenaWeb.CommentLoader alias PhilomenaWeb.CommentLoader
alias PhilomenaWeb.NotificationCountPlug alias PhilomenaWeb.NotificationCountPlug
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.{ alias Philomena.{
Images, Images,
@ -63,13 +63,13 @@ defmodule PhilomenaWeb.ImageController do
comments = CommentLoader.load_comments(conn, image) 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)} comments = %{comments | entries: Enum.zip(comments.entries, rendered)}
description = description =
%{body: image.description} %{body: image.description, body_md: image.description_md}
|> TextileRenderer.render_one(conn) |> TextRenderer.render_one(conn)
interactions = Interactions.user_interactions([image], conn.assigns.current_user) interactions = Interactions.user_interactions([image], conn.assigns.current_user)

View file

@ -1,7 +1,7 @@
defmodule PhilomenaWeb.Post.PreviewController do defmodule PhilomenaWeb.Post.PreviewController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Posts.Post alias Philomena.Posts.Post
alias Philomena.Repo alias Philomena.Repo
@ -10,8 +10,8 @@ defmodule PhilomenaWeb.Post.PreviewController do
body = to_string(params["body"]) body = to_string(params["body"])
anonymous = params["anonymous"] == true anonymous = params["anonymous"] == true
post = %Post{user: user, body: body, anonymous: anonymous} post = %Post{user: user, body_md: body, anonymous: anonymous}
rendered = TextileRenderer.render_one(post, conn) rendered = TextRenderer.render_one(post, conn)
render(conn, "create.html", layout: false, post: post, body: rendered) render(conn, "create.html", layout: false, post: post, body: rendered)
end end

View file

@ -1,7 +1,7 @@
defmodule PhilomenaWeb.PostController do defmodule PhilomenaWeb.PostController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.{Posts.Query, Posts.Post} alias Philomena.{Posts.Query, Posts.Post}
import Ecto.Query import Ecto.Query
@ -36,7 +36,7 @@ defmodule PhilomenaWeb.PostController do
preload(Post, [:deleted_by, topic: :forum, user: [awards: :badge]]) 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)} posts = %{posts | entries: Enum.zip(rendered, posts.entries)}

View file

@ -3,7 +3,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do
alias Philomena.Commissions.Commission alias Philomena.Commissions.Commission
alias Philomena.Commissions alias Philomena.Commissions
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Users.User alias Philomena.Users.User
plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :delete] plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :delete]
@ -36,21 +36,21 @@ defmodule PhilomenaWeb.Profile.CommissionController do
item_descriptions = item_descriptions =
items items
|> Enum.map(&%{body: &1.description}) |> Enum.map(&%{body: &1.description, body_md: &1.description_md})
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
item_add_ons = item_add_ons =
items items
|> Enum.map(&%{body: &1.add_ons}) |> Enum.map(&%{body: &1.add_ons, body_md: &1.add_ons_md})
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
[information, contact, will_create, will_not_create] = [information, contact, will_create, will_not_create] =
TextileRenderer.render_collection( TextRenderer.render_collection(
[ [
%{body: commission.information || ""}, %{body_md: commission.information_md, body: commission.information || ""},
%{body: commission.contact || ""}, %{body_md: commission.contact_md, body: commission.contact || ""},
%{body: commission.will_create || ""}, %{body_md: commission.will_create_md, body: commission.will_create || ""},
%{body: commission.will_not_create || ""} %{body_md: commission.will_not_create_md, body: commission.will_not_create || ""}
], ],
conn conn
) )

View file

@ -3,7 +3,7 @@ defmodule PhilomenaWeb.Profile.DetailController do
alias Philomena.UserNameChanges.UserNameChange alias Philomena.UserNameChanges.UserNameChange
alias Philomena.ModNotes.ModNote alias Philomena.ModNotes.ModNote
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Polymorphic alias Philomena.Polymorphic
alias Philomena.Users.User alias Philomena.Users.User
alias Philomena.Repo alias Philomena.Repo
@ -30,7 +30,7 @@ defmodule PhilomenaWeb.Profile.DetailController do
mod_notes = mod_notes =
mod_notes mod_notes
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
|> Enum.zip(mod_notes) |> Enum.zip(mod_notes)
name_changes = name_changes =

View file

@ -3,7 +3,7 @@ defmodule PhilomenaWeb.ProfileController do
alias PhilomenaWeb.ImageLoader alias PhilomenaWeb.ImageLoader
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.UserStatistics.UserStatistic alias Philomena.UserStatistics.UserStatistic
alias Philomena.Users.User alias Philomena.Users.User
alias Philomena.Bans alias Philomena.Bans
@ -131,12 +131,12 @@ defmodule PhilomenaWeb.ProfileController do
recent_comments = recent_comments =
recent_comments recent_comments
|> Enum.filter(&Canada.Can.can?(current_user, :show, &1.image)) |> Enum.filter(&Canada.Can.can?(current_user, :show, &1.image))
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
|> Enum.zip(recent_comments) |> 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) 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(nil, _field_name), do: nil
defp map_fetch(map, field_name), do: Map.get(map, field_name) defp map_fetch(map, field_name), do: Map.get(map, field_name)
defp commission_info(%{information: info}, conn) when info not in [nil, ""], defp commission_info(%{information: info, information_md: info_md}, conn) when info not in [nil, ""],
do: TextileRenderer.render_one(%{body: info}, conn) do: TextRenderer.render_one(%{body: info, body_md: info_md}, conn)
defp commission_info(_commission, _conn), do: "" defp commission_info(_commission, _conn), do: ""
@ -282,7 +282,7 @@ defmodule PhilomenaWeb.ProfileController do
mod_notes = mod_notes =
mod_notes mod_notes
|> TextileRenderer.render_collection(conn) |> TextRenderer.render_collection(conn)
|> Enum.zip(mod_notes) |> Enum.zip(mod_notes)
assign(conn, :mod_notes, mod_notes) assign(conn, :mod_notes, mod_notes)

View file

@ -5,7 +5,7 @@ defmodule PhilomenaWeb.TagController do
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.{Tags, Tags.Tag} alias Philomena.{Tags, Tags.Tag}
alias Philomena.{Images, Images.Image} alias Philomena.{Images, Images.Image}
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Interactions alias Philomena.Interactions
import Ecto.Query import Ecto.Query
@ -61,11 +61,11 @@ defmodule PhilomenaWeb.TagController do
interactions = Interactions.user_interactions(images, user) 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 = dnp_bodies =
TextileRenderer.render_collection( TextRenderer.render_collection(
Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), Enum.map(tag.dnp_entries, &%{body_md: &1.conditions_md, body: &1.conditions || ""}),
conn conn
) )

View file

@ -5,7 +5,7 @@ defmodule PhilomenaWeb.TopicController do
alias Philomena.{Forums.Forum, Topics.Topic, Posts.Post, Polls.Poll, PollOptions.PollOption} alias Philomena.{Forums.Forum, Topics.Topic, Posts.Post, Polls.Poll, PollOptions.PollOption}
alias Philomena.{Forums, Topics, Polls, Posts} alias Philomena.{Forums, Topics, Polls, Posts}
alias Philomena.PollVotes alias Philomena.PollVotes
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@ -60,7 +60,7 @@ defmodule PhilomenaWeb.TopicController do
|> preload([:deleted_by, :topic, topic: :forum, user: [awards: :badge]]) |> preload([:deleted_by, :topic, topic: :forum, user: [awards: :badge]])
|> Repo.all() |> Repo.all()
rendered = TextileRenderer.render_collection(posts, conn) rendered = TextRenderer.render_collection(posts, conn)
posts = Enum.zip(posts, rendered) posts = Enum.zip(posts, rendered)

View file

@ -2,7 +2,7 @@ defmodule PhilomenaWeb.ImageLoader do
alias PhilomenaWeb.ImageSorter alias PhilomenaWeb.ImageSorter
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.Images.{Image, Query} alias Philomena.Images.{Image, Query}
alias PhilomenaWeb.TextileRenderer alias PhilomenaWeb.TextRenderer
alias Philomena.Tags.Tag alias Philomena.Tags.Tag
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@ -132,14 +132,14 @@ defmodule PhilomenaWeb.ImageLoader do
defp render_bodies([tag], conn) do defp render_bodies([tag], conn) do
dnp_bodies = dnp_bodies =
TextileRenderer.render_collection( TextRenderer.render_collection(
Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), Enum.map(tag.dnp_entries, &%{body_md: &1.conditions_md, body: &1.conditions || ""}),
conn conn
) )
dnp_entries = Enum.zip(dnp_bodies, tag.dnp_entries) 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}] [{tag, description, dnp_entries}]
end end

View file

@ -0,0 +1,7 @@
defmodule PhilomenaWeb.MarkdownRenderer do
alias Philomena.Markdown
def render(text, _conn) do
Markdown.to_html(text)
end
end

View file

@ -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

View file

@ -9,44 +9,32 @@ defmodule PhilomenaWeb.TextileRenderer do
# Kill bogus compile time dependency on ImageView # Kill bogus compile time dependency on ImageView
@image_view Module.concat(["PhilomenaWeb.ImageView"]) @image_view Module.concat(["PhilomenaWeb.ImageView"])
def render_one(post, conn) do def render(text, conn) do
hd(render_collection([post], conn)) opts = %{image_transform: &Camo.Image.image_url/1}
end parsed = Parser.parse(opts, text)
def render_collection(posts, conn) do images =
# opts = %{image_transform: &Camo.Image.image_url/1} parsed
# parsed = Enum.map(posts, &Parser.parse(opts, &1.body)) |> Enum.flat_map(fn
{:text, text} ->
[text]
Enum.map(posts, &Philomena.Markdown.to_html(&1.body)) _ ->
[]
end)
|> find_images
# images = parsed
# parsed |> Enum.map(fn
# |> Enum.flat_map(fn tree -> {:text, text} ->
# tree text
# |> Enum.flat_map(fn |> replacement_entities()
# {:text, text} -> |> replacement_images(conn, images)
# [text]
# _ -> {_k, markup} ->
# [] markup
# end) end)
# end) |> Enum.join()
# |> 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)
end end
defp replacement_entities(t) do defp replacement_entities(t) do

View file

@ -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

View file

@ -2,8 +2,8 @@
-- PostgreSQL database dump -- PostgreSQL database dump
-- --
-- Dumped from database version 13.2 -- Dumped from database version 13.4
-- Dumped by pg_dump version 13.2 -- Dumped by pg_dump version 13.4
SET statement_timeout = 0; SET statement_timeout = 0;
SET lock_timeout = 0; SET lock_timeout = 0;
@ -165,7 +165,8 @@ CREATE TABLE public.badges (
created_at timestamp without time zone 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,
disable_award boolean DEFAULT false 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, total_viewer_minutes integer DEFAULT 0 NOT NULL,
banner_image character varying, banner_image character varying,
remote_stream_id integer, 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, edited_at timestamp without time zone,
deletion_reason character varying DEFAULT ''::character varying NOT NULL, deletion_reason character varying DEFAULT ''::character varying NOT NULL,
destroyed_content boolean DEFAULT false, 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, add_ons character varying,
example_image_id integer, example_image_id integer,
created_at timestamp without time zone 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,
description_md character varying,
add_ons_md character varying
); );
@ -347,7 +352,11 @@ CREATE TABLE public.commissions (
will_not_create character varying, will_not_create character varying,
commission_items_count integer DEFAULT 0 NOT NULL, commission_items_count integer DEFAULT 0 NOT NULL,
created_at timestamp without time zone 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, instructions character varying NOT NULL,
feedback character varying NOT NULL, feedback character varying NOT NULL,
created_at timestamp without time zone 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, user_count integer DEFAULT 0 NOT NULL,
created_at timestamp without time zone 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,
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_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
watcher_count integer DEFAULT 0 NOT NULL, watcher_count integer DEFAULT 0 NOT NULL,
image_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, hidden_image_key character varying,
scratchpad character varying, scratchpad character varying,
hides_count integer DEFAULT 0 NOT NULL, 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, created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL,
from_id integer 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, body text NOT NULL,
deleted boolean DEFAULT false NOT NULL, deleted boolean DEFAULT false NOT NULL,
created_at timestamp without time zone 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, edited_at timestamp without time zone,
deletion_reason character varying DEFAULT ''::character varying NOT NULL, deletion_reason character varying DEFAULT ''::character varying NOT NULL,
destroyed_content boolean DEFAULT false 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, user_id integer,
admin_id integer, admin_id integer,
reportable_id integer NOT NULL, 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, created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL,
category character varying, 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, last_renamed_at timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL,
forced_filter_id bigint, forced_filter_id bigint,
confirmed_at timestamp(0) without time zone, 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 (20210121200815);
INSERT INTO public."schema_migrations" (version) VALUES (20210301012137); INSERT INTO public."schema_migrations" (version) VALUES (20210301012137);
INSERT INTO public."schema_migrations" (version) VALUES (20210427022351); INSERT INTO public."schema_migrations" (version) VALUES (20210427022351);
INSERT INTO public."schema_migrations" (version) VALUES (20210912171343);