Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paragraph -NoNewLine parameter not working #75

Closed
tpcarman opened this issue Apr 15, 2018 · 3 comments
Closed

Paragraph -NoNewLine parameter not working #75

tpcarman opened this issue Apr 15, 2018 · 3 comments

Comments

@tpcarman
Copy link

When using Paragraph -NoNewLine, text is still moved to a new line

$Username = $env:USERNAME
$Date = Get-Date -Format D
Document NoNewLine {
    Paragraph "Username: "
    Paragraph $Username -NoNewLine
    Paragraph "Date: "
    Paragraph $Date -NoNewLine
} | Export-Document -Format Word -Path $env:TEMP -Verbose -PassThru | Invoke-Item
@iainbrighton
Copy link
Owner

I think I've got to the bottom of this and the solution is not easy. Plain text output is not affected, but HTML output suffers the same fate. Here's a summary:

  • In the Office Open XML document a paragraph can have multiple runs
  • When we create the Word document, we create a single run inside a paragraph, overly simplified example:
    • <p><r>My paragraph text</r></p>
  • To append text to a paragraph we would have to add a "run" to the existing paragraph
  • Each paragraph is executed in its own scope so the previous context no longer exists 😢.

A solution to this is to add another parameter set to the Paragraph function to accept a script block for each "run":

Document ParagraphRuns {
    Paragraph {
        Run "This is the first part of a paragraph"
        Run "This will append the second part of a paragraph"
    }
}

Would this proposal work? This won't break existing functionality, but would probably require dropping (or deprecating) the -NoNewLine parameter on the Paragraph function.

Note: I don't think that Run would be a good choice of function name, but would like some suggestions!

@iainbrighton
Copy link
Owner

Not that it helps, but it seems I did know about this already 😊.

image

@iainbrighton
Copy link
Owner

@tpcarman This functionality is now available in the dev branch if you want to take it for a spin. You will need to use the new Paragraph { } implementation for it to work (the old implementation will remain for compatibility and ease of use). See Example38.ps1 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants