如何注释重构文本中的字符串?

发布于 2024-10-14 03:55:01 字数 75 浏览 2 评论 0原文

HTML的注释是,如何用重组文本制作这个注释块?换句话说,如何注释掉重组文本中的某些行?

The comment of HTML is <!-- .. -->, how can I make this comment block with restructured text? In order words, how can I comment out some of the lines in restructured text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

醉梦枕江山 2024-10-21 03:55:01

来自参考

任意缩进的文本可以跟随
显式标记开始并将
作为评论元素处理。

..
   _This: is a comment!

..
   [and] this!

..
   this:: too!

..
   |even| this:: !

也可以将注释放在与双点相同的行上:

.. Avoid this type of comment

但这被认为是不好的做法,因为如果注释与正确的标记结构匹配,则可能会导致意想不到的后果,正如 @CecilCurry 在 下面的评论

From the reference:

Arbitrary indented text may follow the
explicit markup start and will be
processed as a comment element.

..
   _This: is a comment!

..
   [and] this!

..
   this:: too!

..
   |even| this:: !

It is also possible to put the comment on the same line as the double dots:

.. Avoid this type of comment

This is however considered bad practice since it may lead to unintended consequences if the comment matches a proper markup construct, as pointed out by @CecilCurry in the comment below.

甜警司 2024-10-21 03:55:01

对于注释,请添加 2 个句点 ..,后跟换行符,然后缩进您的注释。

例子:

..
  comment goes here

For comments, add 2 periods .. followed by a newline and then your comment indented.

Example:

..
  comment goes here
枯叶蝶 2024-10-21 03:55:01

请原谅这个重复的答案,因为我正在努力帮助像我这样的 RST 新手。我的回答显示了评论的上下文。

我天真地尝试使用上面的答案在我的 RST 文档中标记一行,不要这样做:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    .. Hi everyone this line will never be seen
    Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Sphinx(或其他 RST 格式化程序)不会抱怨,但“大家好”将出现在输出中。相反,在评论之前和之后放置一个空行,如下所示:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    .. 
        comment Hi everyone this line will never be seen

    Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

但这样做的缺点是该段落结束然后重新开始,因此段落之间会有空格。

我没有在 RST 中找到任何可以使某些文本完全消失的 C /* */ 或 HTML 注释语法的等效项。

Please forgive this duplicative answer cos I'm trying to help RST newbies like me. My answer shows the CONTEXT of a comment.

I naively tried marking a line in my RST document using the answer above, DO NOT DO THIS:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    .. Hi everyone this line will never be seen
    Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Sphinx (or other RST formatter) will not complain, but "hi everyone" will appear in the output. Instead place a blank line before and after your comment like this:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    .. 
        comment Hi everyone this line will never be seen

    Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

But the downside of this is that the paragraph is ended then restarted, so you will have whitespace between.

I have not found any equivalent in RST for the C /* */ or HTML <!-- --> comment syntax that can make some text vanish totally.

喜你已久 2024-10-21 03:55:01

我遇到了这个线程,寻找一种更明确的方式在重构文本中放置注释。就我个人而言,我当然也不喜欢单行..这是一条评论。为了保持评论可搜索和可识别,我建议考虑使用

.. only:: comment

    This is a comment

记录( http://www.sphinx-doc.org/en/master/usage/restructedtext/directives.html):“未定义的标签是错误的”,例如comment< /代码>。

或者,可以以 todo,允许语法,例如

.. comment::
    This is a comment

在没有此类扩展的情况下这样做当然会给出来自构建器的错误消息。但是有了这样的扩展,就像todo一样,就可以从文档中提取注释列表。

I came across this thread, looking for a more defined way to place comments in restructuredtext. Personally, I also of course don't like the one-liner .. this is a comment. To keep comments searchable and recognizable, I propose to consider using

.. only:: comment

    This is a comment

As documented (http://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html): "Undefined tags are false", such as comment.

Alternatively, one could write an extension in the style of todo, allowing syntax, such as

.. comment::
    This is a comment

Doing so without such extension of course gives error messages from the builder. But with such extension, just like todo, it would be possible to extract a list of comments from a document.

如果没有 2024-10-21 03:55:01

参考还提供了一个漂亮的小图表,其中显示了多个行注释很简单:

Syntax Diagram

+-------+----------------------+
| ".. " | comment              |
+-------+ block                |
        |                      |
        +----------------------+

以下是参考文献中的示例,已修改为显示多行注释:

.. This is a comment. At least one space before `This` needed. 
 This also gets commented. 1 space before `This also` works.
 As stated by others, comments on the same line as `..` 
 should not be used, to avoid confusion with proper markup constructs.
 And Yes, this entire paragraph is commented.

..    
    _so: is this! At least one space before `_so` needed.
    This also gets commented.
       Even more spaces also works.
    But I like to use a single tab.
..    
    [and] this! At least one space before `[and]` needed.
    This also gets commented.
..  
    this:: too! At least one space before `this` needed.
    this too.
..    
    |even| this:: ! At least one space before `|even|` needed.
    and this as well.
.. [this] however, is a citation.

The reference also gives a nice little diagram, which shows multi-line comments are easy:

Syntax Diagram

+-------+----------------------+
| ".. " | comment              |
+-------+ block                |
        |                      |
        +----------------------+

Here is an example from the reference that has been modified to show multi line comments:

.. This is a comment. At least one space before `This` needed. 
 This also gets commented. 1 space before `This also` works.
 As stated by others, comments on the same line as `..` 
 should not be used, to avoid confusion with proper markup constructs.
 And Yes, this entire paragraph is commented.

..    
    _so: is this! At least one space before `_so` needed.
    This also gets commented.
       Even more spaces also works.
    But I like to use a single tab.
..    
    [and] this! At least one space before `[and]` needed.
    This also gets commented.
..  
    this:: too! At least one space before `this` needed.
    this too.
..    
    |even| this:: ! At least one space before `|even|` needed.
    and this as well.
.. [this] however, is a citation.
半葬歌 2024-10-21 03:55:01

检查: http://docutils.sourceforge.net/docs/user/rst /quickref.html#comments

任何以显式标记开始但不使用上述任何结构的语法的文本都是注释。

Check: http://docutils.sourceforge.net/docs/user/rst/quickref.html#comments

Any text which begins with an explicit markup start but doesn't use the syntax of any of the constructs above, is a comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文