@@ -700,7 +700,11 @@ def template_for file, page = true, klass = ERB
700
700
template
701
701
end
702
702
703
- ParagraphExcerptRegexp = /[A-Z][^\. :\/ ]+\. /
703
+ # :stopdoc:
704
+ ParagraphExcerptRegexpOther = %r[\b \w [^./:]++\. ]
705
+ # use \p/\P{letter} instead of \w/\W in Unicode
706
+ ParagraphExcerptRegexpUnicode = %r[\b \p {letter}[^./:]++\. ]
707
+ # :startdoc:
704
708
705
709
# Returns an excerpt of the comment for usage in meta description tags
706
710
def excerpt ( comment )
@@ -713,11 +717,19 @@ def excerpt(comment)
713
717
714
718
# Match from a capital letter to the first period, discarding any links, so
715
719
# that we don't end up matching badges in the README
716
- first_paragraph_match = text . match ( ParagraphExcerptRegexp )
720
+ pattern = ParagraphExcerptRegexpUnicode
721
+ begin
722
+ first_paragraph_match = text . match ( pattern )
723
+ rescue Encoding ::CompatibilityError
724
+ # The doc is non-ASCII text and encoded in other than Unicode base encodings.
725
+ raise unless pattern . eaual? ( ParagraphExcerptRegexpUnicode )
726
+ pattern = ParagraphExcerptRegexpOther
727
+ retry
728
+ end
717
729
return text [ 0 ...150 ] . tr_s ( "\n " , " " ) . squeeze ( " " ) unless first_paragraph_match
718
730
719
731
extracted_text = first_paragraph_match [ 0 ]
720
- second_paragraph = first_paragraph_match . post_match . match ( ParagraphExcerptRegexp )
732
+ second_paragraph = text . match ( pattern , first_paragraph_match . end ( 0 ) )
721
733
extracted_text << " " << second_paragraph [ 0 ] if second_paragraph
722
734
723
735
extracted_text [ 0 ...150 ] . tr_s ( "\n " , " " ) . squeeze ( " " )
0 commit comments