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 @@ -804,7 +804,8 @@ impl<'a> CommentRewrite<'a> {
804
804
let should_wrap_comment = self . fmt . config . wrap_comments ( )
805
805
&& !is_markdown_header_doc_comment
806
806
&& unicode_str_width ( line) > self . fmt . shape . width
807
- && !has_url ( line) ;
807
+ && !has_url ( line)
808
+ && !is_table_item ( line) ;
808
809
809
810
if should_wrap_comment {
810
811
match rewrite_string ( line, & self . fmt , self . max_width ) {
@@ -939,6 +940,18 @@ fn has_url(s: &str) -> bool {
939
940
|| REFERENCE_LINK_URL . is_match ( s)
940
941
}
941
942
943
+ /// Returns true if the given string may be part of a Markdown talble.
944
+ fn is_table_item ( mut s : & str ) -> bool {
945
+ // This function may return false positive, but should get its job done in most cases (i.e.
946
+ // markdown tables with two column delimiters).
947
+ s = s. trim_start ( ) ;
948
+ return s. starts_with ( '|' )
949
+ && match s. rfind ( '|' ) {
950
+ Some ( 0 ) | None => false ,
951
+ _ => true ,
952
+ } ;
953
+ }
954
+
942
955
/// Given the span, rewrite the missing comment inside it if available.
943
956
/// Note that the given span must only include comments (or leading/trailing whitespaces).
944
957
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