-
Notifications
You must be signed in to change notification settings - Fork 156
Multiline examples don't display as markdown code #180
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
Comments
@Kreloc ah, interesting. Thank you for reporting it! |
I might as well add something to the mix here. I often have multiple commands in an example:
Followed by a blank line and then an explanation. I'd love for the PowerShell commands to be treated as a code block. |
@jdhitsolutions sorry for the super late reply, slipped out of my attention :( If you still care, this is a duplicate requirement of #294 you can read the long conversation there for more details. |
So this is an issue because the PowerShell help system considers the second line a remark instead of code regardless of if it's prefixed with |
It seems like this issue probably isn't being looked at anymore or isn't going to be resolved, right? I guess just making everything be on one line |
@midacts anything not closed will be looked at but more common issues are prioritised. |
This particular issue as i understand it only applies one inital help import into markdown. So a copy/paste from help to markdown would also allow you to work around the issue. |
I created a big of regex magic to fix this issue, it can help somebody hopefully. New-MarkdownHelp -Module MyModuleToDocument -OutputFolder $OutputDir -Force
$OutputDir | Get-ChildItem -File | ForEach-Object {
# fix formatting in multiline examples
$content = Get-Content $_.FullName -Raw
$newContent = $content -replace '(## EXAMPLE [^`]*)(```\r\n)([^`]*)(```\r\n)(\r\n)([^#]*)(\r\n\r\n)+([^#]+)(#)', '$1$2$3$6$5$4$7$8$9'
if ($newContent -ne $content) {
Set-Content -Path $_.FullName -Value $newContent -Force
}
} |
Would you care to try to include such heuristic in platypus when we generate the examples code from Get-Help object? |
@vors, TL;DR: I gave it a try and realized that there is no way to come up with the heuristics that works for all scenarios. Unfortunately, it seems that there is no way to distinguish between these two scenarios:
and
As it was said before, the problem is that I came up with a couple of regexes:
Feel free to test the above e.g. on http://regexstorm.net/tester using the below test data: test data
Generated markdown:
Original comment-based help template based on https://technet.microsoft.com/en-us/library/hh847834.aspx :
I can open a PR for the above, but I'm a bit worried about introducing a breaking change here. Another option is to add this as an optional feature, but then probably just letting people use the above regexes (or different ones) is easier, safer and more reasonable. The heuristics can be improved by checking if the first paragraph of remarks looks more like code or more like text, but it feels like creating a lot of complexity just to create a workaround for a bug. I assume that there is no way to have the |
First, wow, TIL about this nice trick from you test dataFoo
That's awesome, going to use from now on. I think for the future versions of powershell, we can definitely fix it. The code is some state machine, if you feel like opening at issue in the PowerShell repo and maybe even trying to solve it - that would be amazing. |
To be more precise, the bug is here: We are cutting off the |
@Greg-Smulko nice job, I just tested this fix in Powershell 7. Is my conclusion correct in that this will only work for adjacent lines, like shown below.
|
@bravo-kernel , yes, you're correct. Everything up to the first double new line is treated as code, and then the rest is a description. The reasoning behind this is that a multi-paragraph description is quite common, and otherwise, it wouldn't be possible to figure out where the code ends and description begins (without some heuristics or relying on a prompt If you want to take a look at supported examples, please take a look at the tests added as part of the PR in the PowerShell repo. |
@Greg-Smulko thank you kindly for confirming, always better to be 100% sure beforehand. For other users that might be interested in this topic... the Pester documentation website required supporting more complex code examples (that contain double-newlines in the code itself). After trying various solutions, the one that won is It basically allows you to use common markdown code fences in your Get-Help examples. For more information see:
Vendor AgnosticWe added support for vendor agnostic output so our module can now also be used by users who want to render code fenced get-help but do not want to use Docusaurus to serve their pages. |
Marking as closed as it is no longer an issue due to the excellent work done by @Greg-Smulko based on @vors comments. |
Steps to reproduce
Have a function with multiple lines in an .EXAMPLE section
Expected behavior
------------------------- EXAMPLE 1 -------------------------
Actual behavior
------------------------- EXAMPLE 1 -------------------------
$verbs
v0.5.0
The text was updated successfully, but these errors were encountered: