diff --git a/examples/paragraphs.ps1 b/examples/paragraphs.ps1 new file mode 100644 index 00000000..e3742d33 --- /dev/null +++ b/examples/paragraphs.ps1 @@ -0,0 +1,24 @@ +Import-Module Pode -MaximumVersion 2.99.99 -Force +Import-Module ..\src\Pode.Web.psm1 -Force + +Start-PodeServer { + # add a simple endpoint + Add-PodeEndpoint -Address localhost -Port 8090 -Protocol Http + New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging + + # set the use of templates, and set a login page + Use-PodeWebTemplates -Title 'Paragraphs' -Theme Dark + + # set the home page controls (just a simple paragraph) + $card1 = New-PodeWebCard -Content @( + New-PodeWebParagraph -Value "Example paragraph`r`nover two lines" + ) + + $card2 = New-PodeWebCard -Content @( + New-PodeWebParagraph -Content @( + New-PodeWebText -Value "Example text`r`nover two lines" + ) + ) + + Add-PodeWebPage -Name 'Home' -Path '/' -HomePage -Content $card1, $card2 -Title 'Paragraphs' +} \ No newline at end of file diff --git a/src/Templates/Public/scripts/default.js b/src/Templates/Public/scripts/default.js index b2a94a68..a73112c3 100644 --- a/src/Templates/Public/scripts/default.js +++ b/src/Templates/Public/scripts/default.js @@ -1389,4 +1389,12 @@ function mergeObjects(obj1, obj2, excludeProps) { } return obj1; +} + +function encodeNewlines(text) { + if (!text) { + return ''; + } + + return text.replace(/\r?\n/g, "
"); } \ No newline at end of file diff --git a/src/Templates/Public/scripts/templates.js b/src/Templates/Public/scripts/templates.js index a49bbafe..a26ee2ba 100644 --- a/src/Templates/Public/scripts/templates.js +++ b/src/Templates/Public/scripts/templates.js @@ -1809,7 +1809,7 @@ class PodeText extends PodeTextualElement { class='pode-text' pode-object='${this.getType()}' pode-id='${this.uuid}'> - ${data.Value} + ${encodeNewlines(data.Value)} `; switch (data.Style.toLowerCase()) { @@ -3603,7 +3603,7 @@ class PodeParagraph extends PodeTextualElement { pode-object="${this.getType()}" pode-id="${this.uuid}"> - ${data.Value ? data.Value : ''} + ${data.Value ? encodeNewlines(data.Value) : ''}

`; }