File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -806,7 +806,8 @@ impl<'a> CommentRewrite<'a> {
806
806
let should_wrap_comment = self . fmt . config . wrap_comments ( )
807
807
&& !is_markdown_header_doc_comment
808
808
&& unicode_str_width ( line) > self . fmt . shape . width
809
- && !has_url ( line) ;
809
+ && !has_url ( line)
810
+ && !is_table_item ( line) ;
810
811
811
812
if should_wrap_comment {
812
813
match rewrite_string ( line, & self . fmt , self . max_width ) {
@@ -941,6 +942,18 @@ fn has_url(s: &str) -> bool {
941
942
|| REFERENCE_LINK_URL . is_match ( s)
942
943
}
943
944
945
+ /// Returns true if the given string may be part of a Markdown talble.
946
+ fn is_table_item ( mut s : & str ) -> bool {
947
+ // This function may return false positive, but should get its job done in most cases (i.e.
948
+ // markdown tables with two column delimiters).
949
+ s = s. trim_start ( ) ;
950
+ return s. starts_with ( '|' )
951
+ && match s. rfind ( '|' ) {
952
+ Some ( 0 ) | None => false ,
953
+ _ => true ,
954
+ } ;
955
+ }
956
+
944
957
/// Given the span, rewrite the missing comment inside it if available.
945
958
/// Note that the given span must only include comments (or leading/trailing whitespaces).
946
959
pub ( crate ) fn rewrite_missing_comment (
Original file line number Diff line number Diff line change
1
+ // rustfmt-wrap_comments: true
2
+
3
+ /// Table that is > 80 symbols:
4
+ ///
5
+ /// | table | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
6
+ /// |-------|-----------------------------------------------------------------------------|
7
+ /// | val | x |
8
+ pub struct Item ;
9
+
10
+ /// Table that is > 80 symbols:
11
+ ///
12
+ /// | table | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
13
+ /// |-------|-----------------------------------------------------------------------------
14
+ /// | val | x
15
+ pub struct Item ;
You can’t perform that action at this time.
0 commit comments