File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ defmodule Slugger do
3737 @ spec slugify ( text :: any , separator :: char ) :: String . t
3838 def slugify ( text , separator \\ @ separator_char ) do
3939 text
40+ |> handle_possessives
4041 |> replace_special_chars
4142 |> remove_unwanted_chars ( separator , ~r/ ([^A-Za-z0-9가-힣])+/ )
4243 end
@@ -62,6 +63,7 @@ defmodule Slugger do
6263 @ spec slugify_downcase ( text :: any , separator :: char ) :: String . t
6364 def slugify_downcase ( text , separator \\ @ separator_char ) do
6465 text
66+ |> handle_possessives
6567 |> replace_special_chars
6668 |> String . downcase
6769 |> remove_unwanted_chars ( separator , ~r/ ([^a-z0-9가-힣])+/ )
@@ -160,4 +162,10 @@ defmodule Slugger do
160162 |> Enum . take ( range )
161163 |> Enum . any? ( & ( & 1 == separator ) )
162164 end
165+
166+ # Handle "Sheep's Milk" so it will be "sheeps-milk" instead of "sheep-s-milk"
167+ defp handle_possessives ( text ) do
168+ String . replace ( text , ~r/ ['’]s/ u , "s" )
169+ end
170+
163171end
Original file line number Diff line number Diff line change @@ -39,7 +39,11 @@ defmodule SluggerTest do
3939 assert Slugger . slugify ( "baü" ) == "baue"
4040 assert Slugger . slugify ( "büaü" ) == "bueaue"
4141 end
42-
42+
43+ test "removing space between possessives" do
44+ assert Slugger . slugify ( "Sheep's Milk" ) == "Sheeps-Milk"
45+ end
46+
4347 #--- slugify_downcase()
4448
4549 test "string to lower" do
@@ -63,6 +67,10 @@ defmodule SluggerTest do
6367 assert Slugger . slugify_downcase ( " A B C " , ?_ ) == "a_b_c"
6468 end
6569
70+ test "removing space between possessives lowercase" do
71+ assert Slugger . slugify_downcase ( "Sheep's Milk" ) == "sheeps-milk"
72+ end
73+
6674 #--- Naughty strings
6775
6876 test "naughty strings" do
You can’t perform that action at this time.
0 commit comments