Browse Source

pruebas

master
Your Name 1 year ago
parent
commit
3e662be78f
2 changed files with 42 additions and 1 deletions
  1. +23
    -0
      docker-compose.yml
  2. +19
    -1
      lib/linkify/parser.ex

+ 23
- 0
docker-compose.yml

@ -0,0 +1,23 @@
version: '2'
services:
auto_linker:
image: elixir
restart: always
hostname: auto_linker
container_name: auto_linker
entrypoint:
- /bin/sleep
- infinity
volumes:
- ./:/auto_linker
networks:
mynet:
ipv4_address: 172.144.0.101
networks:
mynet:
driver: bridge
ipam:
config:
- subnet: 172.144.0.0/24

+ 19
- 1
lib/linkify/parser.ex

@ -7,6 +7,9 @@ defmodule Linkify.Parser do
@invalid_url ~r/(\.\.+)|(^(\d+\.){1,2}\d+$)/
@match_youtube ~r{http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?‌​[\w\?‌​=]*)?}u
@match_url ~r{^(?:\W*)?(?<url>(?:https?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:\/?#[\]@!\$&'\(\)\*\+,;=.]+$)}u
@match_hostname ~r{^\W*(?<scheme>https?:\/\/)?(?:[^@\n]+\\w@)?(?<host>[^:#~\/\n?]+)}u
@ -54,7 +57,7 @@ defmodule Linkify.Parser do
~s{Check out <a href="http://google.com">google.com</a>}
"""
@types [:url, :email, :hashtag, :mention, :extra]
@types [:youtube, :url, :email, :hashtag, :mention, :extra]
def parse(input, opts \\ %{})
def parse(input, opts) when is_binary(input), do: {input, %{}} |> parse(opts) |> elem(0)
@ -65,9 +68,11 @@ defmodule Linkify.Parser do
Enum.reduce(opts, input, fn
{type, true}, input when type in @types ->
IO.puts inspect type
do_parse(input, opts, {"", "", :parsing}, type)
_, input ->
IO.puts inspect input
input
end)
end
@ -171,6 +176,19 @@ defmodule Linkify.Parser do
defp do_parse({<<ch::8>> <> text, user_acc}, opts, {buffer, acc, state}, type),
do: do_parse({text, user_acc}, opts, {buffer <> <<ch::8>>, acc, state}, type)
def check_and_link(:youtube, buffer, opts, _user_acc) do
str = strip_parens(buffer)
if url?(str, opts) do
case @match_youtube |> Regex.run(str, capture: [:youtube]) |> hd() do
^buffer -> link_url(buffer, opts)
youtube -> String.replace(buffer, youtube, link_url(youtube, opts))
end
else
buffer
end
end
def check_and_link(:url, buffer, opts, _user_acc) do
str = strip_parens(buffer)

Loading…
Cancel
Save