33rescue LoadError ; end
44
55module KramdownEnhancer
6+ GITHUB_LINK_REGEX = /\b (GP-\d +|GC-[0-9a-f]{7})\b /
7+ BLOCKQUOTE_TYPES = {
8+ note : "notice--info" ,
9+ tip : "notice--success" ,
10+ important : "notice--primary" ,
11+ warning : "notice--warning" ,
12+ caution : "notice--danger" ,
13+ }
14+
615 class << self
716 def webp
817 @webp ||= { }
@@ -25,16 +34,6 @@ def baseurl=(input)
2534 ""
2635 end
2736 end
28-
29- def blockquote_types
30- @blockquote_types ||= {
31- :note => "notice--info" ,
32- :tip => "notice--success" ,
33- :important => "notice--primary" ,
34- :warning => "notice--warning" ,
35- :caution => "notice--danger" ,
36- }
37- end
3837 end
3938
4039 class WebpFile < Jekyll ::StaticFile
@@ -81,7 +80,7 @@ def convert_blockquote(el, indent)
8180 return super unless first &.type == :text
8281
8382 text = first . value . downcase
84- KramdownEnhancer . blockquote_types . each do |type , class_name |
83+ KramdownEnhancer :: BLOCKQUOTE_TYPES . each do |type , class_name |
8584 prefix = "[!#{ type } ]"
8685 prefix_with_newline = "#{ prefix } \n "
8786
@@ -128,6 +127,29 @@ def convert_html_element(el, indent)
128127 super ( el , indent )
129128 end
130129
130+ def convert_text ( el , indent )
131+ return super ( el , indent ) unless !el . options [ :github_link ] && KramdownEnhancer ::GITHUB_LINK_REGEX . match? ( el . value )
132+ list = el . value . split ( KramdownEnhancer ::GITHUB_LINK_REGEX )
133+ el . type = :html_element
134+ el . value = "span"
135+ el . children = list . reject ( &:empty? ) . map do |item |
136+ if KramdownEnhancer ::GITHUB_LINK_REGEX . match ( item )
137+ href =
138+ if item . start_with? ( "GP-" )
139+ "https://github.com/HMCL-dev/HMCL/pull/#{ item [ 3 ..] } "
140+ else
141+ "https://github.com/HMCL-dev/HMCL/commit/#{ item [ 3 ..] } "
142+ end
143+ link = Kramdown ::Element . new ( :a , nil , { "href" : href , "target" : "_blank" } )
144+ link . children = [ Kramdown ::Element . new ( :text , item , nil , :github_link => true ) ]
145+ link
146+ else
147+ Kramdown ::Element . new ( :text , item , nil , :github_link => true )
148+ end
149+ end
150+ convert_html_element ( el , indent )
151+ end
152+
131153 private
132154
133155 def relative_url ( input )
0 commit comments