fix issue with displaying content
This commit is contained in:
		| @@ -1,3 +1,6 @@ | |||||||
|  | # v0.1.14 | ||||||
|  | - Fix issue with item content not able to be displayed sometimes | ||||||
|  |  | ||||||
| # v0.1.13 | # v0.1.13 | ||||||
| - Update dependencies | - Update dependencies | ||||||
| - Fix debounces | - Fix debounces | ||||||
|   | |||||||
| @@ -134,25 +134,30 @@ defmodule MemexWeb.CoreComponents do | |||||||
|  |  | ||||||
|   def pipeline_content(assigns) |   def pipeline_content(assigns) | ||||||
|  |  | ||||||
|   defp display_backlinks(record) do |   defp display_links(record) do | ||||||
|     record |     record | ||||||
|     |> get_text() |     |> get_content() | ||||||
|     |> replace_links(record) |     |> replace_hyperlinks(record) | ||||||
|     |> replace_triple_backlinks(record) |     |> replace_triple_links(record) | ||||||
|     |> replace_double_backlinks(record) |     |> replace_double_links(record) | ||||||
|     |> replace_single_backlinks(record) |     |> replace_single_links(record) | ||||||
|     |> HTML.raw() |     |> HTML.raw() | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   defp get_text(%{content: content}), do: content |   defp get_content(%{content: content}), do: content |> get_text() | ||||||
|   defp get_text(%{description: description}), do: description |   defp get_content(%{description: description}), do: description |> get_text() | ||||||
|  |   defp get_content(_fallthrough), do: nil |> get_text() | ||||||
|  |  | ||||||
|  |   defp get_text(string) when is_binary(string), do: string | ||||||
|   defp get_text(_fallthrough), do: "" |   defp get_text(_fallthrough), do: "" | ||||||
|  |  | ||||||
|  |   # replaces hyperlinks like https://bubbletea.dev | ||||||
|  |   # | ||||||
|   # link regex from |   # link regex from | ||||||
|   # https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url |   # https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url | ||||||
|   # and modified with additional schemes from |   # and modified with additional schemes from | ||||||
|   # https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml |   # https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml | ||||||
|   defp replace_links(content, _record) do |   defp replace_hyperlinks(content, _record) do | ||||||
|     Regex.replace( |     Regex.replace( | ||||||
|       ~r<((file|git|https?|ipfs|ipns|irc|jabber|magnet|mailto|mumble|tel|udp|xmpp):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))>, |       ~r<((file|git|https?|ipfs|ipns|irc|jabber|magnet|mailto|mumble|tel|udp|xmpp):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))>, | ||||||
|       content, |       content, | ||||||
| @@ -173,7 +178,8 @@ defmodule MemexWeb.CoreComponents do | |||||||
|     ) |     ) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   defp replace_triple_backlinks(content, _record) do |   # replaces triple links like [[[slug-title]]] | ||||||
|  |   defp replace_triple_links(content, _record) do | ||||||
|     Regex.replace( |     Regex.replace( | ||||||
|       ~r/(^|[^\[])\[\[\[([\p{L}\p{N}\-]+)\]\]\]($|[^\]])/, |       ~r/(^|[^\[])\[\[\[([\p{L}\p{N}\-]+)\]\]\]($|[^\]])/, | ||||||
|       content, |       content, | ||||||
| @@ -192,7 +198,8 @@ defmodule MemexWeb.CoreComponents do | |||||||
|     ) |     ) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   defp replace_double_backlinks(content, record) do |   # replaces double links like [[slug-title]] | ||||||
|  |   defp replace_double_links(content, record) do | ||||||
|     Regex.replace( |     Regex.replace( | ||||||
|       ~r/(^|[^\[])\[\[([\p{L}\p{N}\-]+)\]\]($|[^\]])/, |       ~r/(^|[^\[])\[\[([\p{L}\p{N}\-]+)\]\]($|[^\]])/, | ||||||
|       content, |       content, | ||||||
| @@ -218,7 +225,8 @@ defmodule MemexWeb.CoreComponents do | |||||||
|     ) |     ) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   defp replace_single_backlinks(content, record) do |   # replaces single links like [slug-title] | ||||||
|  |   defp replace_single_links(content, record) do | ||||||
|     Regex.replace( |     Regex.replace( | ||||||
|       ~r/(^|[^\[])\[([\p{L}\p{N}\-]+)\]($|[^\]])/, |       ~r/(^|[^\[])\[([\p{L}\p{N}\-]+)\]($|[^\]])/, | ||||||
|       content, |       content, | ||||||
|   | |||||||
| @@ -4,4 +4,4 @@ | |||||||
|   phx-update="ignore" |   phx-update="ignore" | ||||||
|   readonly |   readonly | ||||||
|   phx-no-format |   phx-no-format | ||||||
| ><p class="inline"><%= display_backlinks(@context) %></p></div> | ><p class="inline"><%= display_links(@context) %></p></div> | ||||||
|   | |||||||
| @@ -4,4 +4,4 @@ | |||||||
|   phx-update="ignore" |   phx-update="ignore" | ||||||
|   readonly |   readonly | ||||||
|   phx-no-format |   phx-no-format | ||||||
| ><p class="inline"><%= display_backlinks(@note) %></p></div> | ><p class="inline"><%= display_links(@note) %></p></div> | ||||||
|   | |||||||
| @@ -4,4 +4,4 @@ | |||||||
|   phx-update="ignore" |   phx-update="ignore" | ||||||
|   readonly |   readonly | ||||||
|   phx-no-format |   phx-no-format | ||||||
| ><p class="inline"><%= display_backlinks(@pipeline) %></p></div> | ><p class="inline"><%= display_links(@pipeline) %></p></div> | ||||||
|   | |||||||
| @@ -4,4 +4,4 @@ | |||||||
|   phx-update="ignore" |   phx-update="ignore" | ||||||
|   readonly |   readonly | ||||||
|   phx-no-format |   phx-no-format | ||||||
| ><p class="inline"><%= display_backlinks(@step) %></p></div> | ><p class="inline"><%= display_links(@step) %></p></div> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user