镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Multiline comments #449

Closed
Closed

Description

@curtis1757

Currently this will not work:

        doc = document()
        doc.add(comment('A comment is here'))
        doc.add(comment("""
---------------------------------------------------------------------------------------------------------------------
A multi line
comment block is here
---------------------------------------------------------------------------------------------------------------------
"""))

It creates:

# A comment is here
#
---------------------------------------------------------------------------------------------------------------------
A multi line
comment block is here
---------------------------------------------------------------------------------------------------------------------

Would like it to make:

# A comment is here
# ---------------------------------------------------------------------------------------------------------------------
# A multi line
# comment block is here
# ---------------------------------------------------------------------------------------------------------------------

In api.py if def comment() is changed to:

def comment(string: str) -> Comment:
    """Create a comment item."""

    lines = string.splitlines()
    if len(lines) > 1:
        return Comment(Trivia(comment_ws="  ", comment='\n# '.join(lines)[1:]))
    else:
        return Comment(Trivia(comment_ws="  ", comment="# " + string))

It will the create comments as shown above.

Possibly include that in master?

Thanks,
Curits

Activity

  1. added a commit that references this issue on Jun 13, 2026
    b7ab6bc
  2. added a commit that references this issue on Jun 13, 2026
    5b2b1ff
  3. added a commit that references this issue on Jul 26, 2026
  4. added a commit that references this issue on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions