fix parser
This commit is contained in:
parent
65f9d43dbe
commit
33c6754592
2 changed files with 25 additions and 6 deletions
|
@ -117,11 +117,10 @@ defmodule AutoLinker.Builder do
|
||||||
|
|
||||||
url = mention_prefix <> name
|
url = mention_prefix <> name
|
||||||
|
|
||||||
[]
|
[href: url]
|
||||||
|> build_attrs(url, opts, :rel)
|
|> build_attrs(url, opts, :rel)
|
||||||
|> build_attrs(url, opts, :target)
|
|> build_attrs(url, opts, :target)
|
||||||
|> build_attrs(url, opts, :class)
|
|> build_attrs(url, opts, :class)
|
||||||
|> build_attrs(url, opts, :scheme)
|
|
||||||
|> format_mention(name, opts)
|
|> format_mention(name, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -378,23 +378,43 @@ defmodule AutoLinker.Parser do
|
||||||
def link_hashtag(nil, buffer, _, _user_acc), do: buffer
|
def link_hashtag(nil, buffer, _, _user_acc), do: buffer
|
||||||
|
|
||||||
def link_hashtag(hashtag, buffer, %{hashtag_handler: hashtag_handler} = opts, user_acc) do
|
def link_hashtag(hashtag, buffer, %{hashtag_handler: hashtag_handler} = opts, user_acc) do
|
||||||
hashtag_handler.(hashtag, buffer, opts, user_acc)
|
hashtag
|
||||||
|
|> hashtag_handler.(buffer, opts, user_acc)
|
||||||
|
|> maybe_update_buffer(hashtag, buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_hashtag(hashtag, buffer, opts, _user_acc) do
|
def link_hashtag(hashtag, buffer, opts, _user_acc) do
|
||||||
Builder.create_hashtag_link(hashtag, buffer, opts)
|
hashtag
|
||||||
|
|> Builder.create_hashtag_link(buffer, opts)
|
||||||
|
|> maybe_update_buffer(hashtag, buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_mention(nil, buffer, _, user_acc), do: {buffer, user_acc}
|
def link_mention(nil, buffer, _, user_acc), do: {buffer, user_acc}
|
||||||
|
|
||||||
def link_mention(mention, buffer, %{mention_handler: mention_handler} = opts, user_acc) do
|
def link_mention(mention, buffer, %{mention_handler: mention_handler} = opts, user_acc) do
|
||||||
mention_handler.(mention, buffer, opts, user_acc)
|
mention
|
||||||
|
|> mention_handler.(buffer, opts, user_acc)
|
||||||
|
|> maybe_update_buffer(mention, buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_mention(mention, buffer, opts, _user_acc) do
|
def link_mention(mention, buffer, opts, _user_acc) do
|
||||||
Builder.create_mention_link(mention, buffer, opts)
|
mention
|
||||||
|
|> Builder.create_mention_link(buffer, opts)
|
||||||
|
|> maybe_update_buffer(mention, buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp maybe_update_buffer(out, match, buffer) when is_binary(out) do
|
||||||
|
maybe_update_buffer({out, nil}, match, buffer)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_update_buffer({out, user_acc}, match, buffer)
|
||||||
|
when match != buffer and out != buffer do
|
||||||
|
out = String.replace(buffer, match, out)
|
||||||
|
{out, user_acc}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_update_buffer(out, _match, _buffer), do: out
|
||||||
|
|
||||||
def link_phone(nil, buffer, _), do: buffer
|
def link_phone(nil, buffer, _), do: buffer
|
||||||
|
|
||||||
def link_phone(list, buffer, opts) do
|
def link_phone(list, buffer, opts) do
|
||||||
|
|
Reference in a new issue