@@ -44,11 +44,37 @@ defmodule Wik.Markdown do
4444 end
4545
4646 defp transform_node ( { "a" , [ { "href" , href } ] , children , meta } , base_path , _embedded_pages ) do
47+ max_length = 50
48+
49+ simple_link? =
50+ case children do
51+ [ text ] when is_binary ( text ) and text == href -> true
52+ _ -> false
53+ end
54+
55+ truncated_text =
56+ if simple_link? and String . length ( href ) > max_length do
57+ String . slice ( href , 0 , max_length ) <> "..."
58+ else
59+ href
60+ end
61+
62+ final_children = if simple_link? , do: [ truncated_text ] , else: children
63+
4764 if Utils.Href . external? ( href ) do
48- { "a" , [ { "href" , href } ] , children , meta }
65+ if simple_link? do
66+ { :replace , { "a" , [ { "href" , href } ] , final_children , meta } }
67+ else
68+ { "a" , [ { "href" , href } ] , children , meta }
69+ end
4970 else
5071 slug = Utils . slugify ( href )
51- { "a" , [ { "href" , Path . join ( base_path , slug ) } ] , children , meta }
72+
73+ if simple_link? do
74+ { :replace , { "a" , [ { "href" , Path . join ( base_path , slug ) } ] , final_children , meta } }
75+ else
76+ { "a" , [ { "href" , Path . join ( base_path , slug ) } ] , children , meta }
77+ end
5278 end
5379 end
5480
0 commit comments