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

ConvertTo-Yaml multi-line scalar output #95

Closed
Skeb1ns opened this issue Jan 31, 2023 · 2 comments
Closed

ConvertTo-Yaml multi-line scalar output #95

Skeb1ns opened this issue Jan 31, 2023 · 2 comments

Comments

@Skeb1ns
Copy link

Skeb1ns commented Jan 31, 2023

When converting hash tables where a node contains multiple lines the ConvertTo-Yaml cmdlet currently puts everything on the same row and escapes the special characters like the example below:

install: "Start-Transcript -Path "C:\Windows\Logs\Software\Audacity.Audacity-winget-install.log"

It would be nice if the cmdlet automatically interpreted the value as multi-line scalar like this:

install: |
Start-Transcript -Path "C:\Windows\Logs\Software\Audacity.Audacity-winget-install.log

I'm using this module to write yaml files containing code blocks and putting everything on the same row hurts readability. (it is still functional though).

@gabriel-samfira
Copy link
Member

Hi @Skeb1ns !

In theory, adding a newline to any string will give you the desired result.

PS /tmp> $c = @{"install"='Start-Transcript -Path "C:\Windows\Logs\Software\Audacity.Audacity-winget-install.log"'} 
PS /tmp> ConvertTo-yaml $c
install: Start-Transcript -Path "C:\Windows\Logs\Software\Audacity.Audacity-winget-install.log"

PS /tmp> $c.install += "`n"                                                                                        
PS /tmp> ConvertTo-yaml $c 
install: |
  Start-Transcript -Path "C:\Windows\Logs\Software\Audacity.Audacity-winget-install.log"

@Skeb1ns
Copy link
Author

Skeb1ns commented Feb 13, 2023

Awesome! I also did not removed the hidden spaces in my here-string. Removing those also properly translated the block to a multi-line scalar block.

@Skeb1ns Skeb1ns closed this as completed Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants