Compare commits

...

1 commit

Author SHA1 Message Date
eed5d7dc76 support source:markdown in RSS feed 2022-12-05 09:56:30 -08:00
2 changed files with 30 additions and 0 deletions

View file

@ -112,4 +112,30 @@ def escape(html) do
|> html_escape() |> html_escape()
|> safe_to_string() |> safe_to_string()
end end
# Encoding newlines, e.g., per XML spec
def rss_escape(nil), do: ""
def rss_escape(data) when is_binary(data) do
data
|> rss_escape_string()
|> to_string()
end
defp rss_escape_string(""), do: ""
defp rss_escape_string(<<"&"::utf8, rest::binary>>), do: rss_escape_entity(rest)
defp rss_escape_string(<<"<"::utf8, rest::binary>>), do: ["&lt;" | rss_escape_string(rest)]
defp rss_escape_string(<<">"::utf8, rest::binary>>), do: ["&gt;" | rss_escape_string(rest)]
defp rss_escape_string(<<"\""::utf8, rest::binary>>), do: ["&quot;" | rss_escape_string(rest)]
defp rss_escape_string(<<"'"::utf8, rest::binary>>), do: ["&apos;" | rss_escape_string(rest)]
defp rss_escape_string(<<"\t"::utf8, rest::binary>>), do: ["&#9;" | rss_escape_string(rest)]
defp rss_escape_string(<<"\n"::utf8, rest::binary>>), do: ["&#10;" | rss_escape_string(rest)]
defp rss_escape_string(<<"\r\n"::utf8, rest::binary>>), do: ["&#10;" | rss_escape_string(rest)]
defp rss_escape_string(<<"\r"::utf8, rest::binary>>), do: ["&#13;" | rss_escape_string(rest)]
defp rss_escape_string(<<c::utf8, rest::binary>>), do: [c | rss_escape_string(rest)]
defp rss_escape_entity(<<"amp;"::utf8, rest::binary>>), do: ["&amp;" | rss_escape_string(rest)]
defp rss_escape_entity(<<"lt;"::utf8, rest::binary>>), do: ["&lt;" | rss_escape_string(rest)]
defp rss_escape_entity(<<"gt;"::utf8, rest::binary>>), do: ["&gt;" | rss_escape_string(rest)]
defp rss_escape_entity(<<"quot;"::utf8, rest::binary>>), do: ["&quot;" | rss_escape_string(rest)]
defp rss_escape_entity(<<"apos;"::utf8, rest::binary>>), do: ["&apos;" | rss_escape_string(rest)]
defp rss_escape_entity(rest), do: ["&amp;" | rss_escape_string(rest)]
end end

View file

@ -14,6 +14,10 @@
<description><%= escape(@data["summary"]) %></description> <description><%= escape(@data["summary"]) %></description>
<% end %> <% end %>
<%= if get_in(@data, ["source", "mediaType"]) == "text/markdown" do %>
<source:markdown><%= rss_escape(get_in(@data, ["source", "content"])) %></source:markdown>
<% end %>
<%= if @activity.local do %> <%= if @activity.local do %>
<link><%= @data["id"] %></link> <link><%= @data["id"] %></link>
<% else %> <% else %>