Skip to content

Handling newlines in the front and back of template arguments #111

@lihaohong6

Description

@lihaohong6

Running the following code snippet yields something unexpected

p = wikitextparser.parse("{{A|a=\n\nx\n\n|b=xxx}}")
print(p)
t = p.templates[0]
t.set_arg("a", t.get_arg("a").value)
print(p)

Since the second to last line sets an argument to itself, I was expecting that p stays the same in both print statements. However, 4 lines instead of 2 are padded to "x" both before and after it. I'm wondering if this is the expected behavior or a bug.

The workaround is quite simple since we just have to do t.get_arg("a").value.strip() to get rid of the extra lines, but I'm wondering if this can be fixed. Thank you!

One concern is that a fix might also break the behavior of previously written programs that rely on the fact that wikitextparser doubles newlines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions