首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在文档中将长表行分成多行

在文档中将长表行分成多行
EN

Stack Overflow用户
提问于 2019-03-24 14:35:59
回答 2查看 1K关注 0票数 5

我想记录一下我的箱子,并在文档中包括一个表格:

代码语言:javascript
复制
//! Demonstrating MarkDown tables.
//!
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president  | I can't think of any more "funny" things | oopsie |
//!

使用cargo doc呈现此结果如下:

这就是我想要的。但是,您可能已经注意到,只有一个源代码行非常长。事实上,超过100个字符的长度。就像许多锈蚀项目一样,我想把我所有的线条保持在100个字符以下。所以我设法打破了界限。

所有这些版本:

代码语言:javascript
复制
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president  
//! I can't think of any more "funny" things | oopsie |

//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president  |
//! I can't think of any more "funny" things | oopsie |

//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president 
//! | I can't think of any more "funny" things | oopsie |

//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president  |
//! | I can't think of any more "funny" things | oopsie |

//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president  \
//! I can't think of any more "funny" things | oopsie |

在以下方面的成果:

文档中有哪些选项可以在不违反行长限制的情况下包括长表行?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-30 15:37:36

HTML

正如Francis已经回答的那样,如果您想保持短行,就必须使用HTML。rustdoc利用拉下标记,并且不支持您想要的东西。

包括外部文件

夜间&医生

跟踪问题: rfc 1990 -向rustc添加外部doc属性。在nightly工具链的情况下,您可以启用external_doc特性,并在#[doc(include = "../some/path")]中包含外部Markdown文件。

需要注意的是,无论在哪个模块中使用#[doc(include = "...")],路径都是相对于板条根的总是 (lib.rsmain.rs,.)。

示例:

代码语言:javascript
复制
.
|____Cargo.toml
|____Cargo.lock
|____doc
| |____foo-bar-bar.md
|____src
| |____main-hallo.md
| |____foo
| | |____mod.rs
| | |____bar.rs
| |____main.rs

src/main.rs

代码语言:javascript
复制
#![feature(external_doc)]

pub mod foo;

#[doc(include = "main-hallo.md")]
pub fn hallo() {}

fn main() {}

src/foo/bar.rs

代码语言:javascript
复制
#[doc(include = "../doc/foo-bar-bar.md")]
pub struct Bar;

您可以在src/文件夹中保存单独的Markdown文档,也可以将其保存在单独的文件夹中,如doc/等。但是路径总是相对于板条根。

夜间及rdoc

还有rdoc编译器插件(需要nightly),它基本上可以做同样的事情。如何启用和使用它将在项目README.md中描述。

稳定

为了稳定,我会做以下几件事:

  • 在单独的标记文件中的文档,
  • 自定义build.rs,它将扫描.md文件并将其输出为.rs文件(内容相同,只需在行前面加上/////!)、
    • 把它们放到std::env::var("OUT_DIR")文件夹中,

  • 将它们包含在源代码中,
    • 通过include!(concat!(env!("OUT_DIR"), "/main-hallo-md.rs"));

夜间沙沙

comment_width选项(默认为80) & wrap_comments选项(默认为false)。这可以帮助您将注释保持到一定的宽度。但是我用长标记表行试了一下,它把它包装成->坏了的表。别用它。

票数 1
EN

Stack Overflow用户

发布于 2019-03-24 15:23:15

使用HTML标记。

代码语言:javascript
复制
//! Demonstrating HTML tables.
//!
//! <table>
//!     <thead>
//!         <tr>
//!             <th>Foo</th>
//!             <th>Bar</th>
//!             <th>Baz</th>
//!             <th>Quux</th>
//!         </tr>
//!     </thead>
//!     <tbody>
//!         <tr>
//!             <td>Hail the turbofish <code>::&lt;></code></td>
//!             <td>Ferris for president </td>
//!             <td>
//!                 I can't think of any
//!                 more "funny" things
//!             </td>
//!             <td>oopsie</td>
//!         </tr>
//!     </tbody>
//! </table>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55324887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档