Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Taking RTF multiline input and converting to html

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
Hi all - I'm trying to change a powershell script that took a single line console input and used it to set something that accepts HTML so that it has a richtextbox for input that accepts multiline text (this much works ok) but preferably that has a way to convert it to HTML. So far I've said
Code:
$text = $text -replace "`r`n", "<br>"
which successfully turns the newlines into linebreaks - but it would be nice to keep all the formatting of what is pasted in rather than making it all plain black etc.
Also I noticed that when copying in my email signature, it would turn something like
Code:
Email: thisis@myemail.com
where the email address was coloured red and a hyperlink to the email
into
Code:
Email: thisis@myemail.com <mailto:thisis@myemail.com>
where the email and the hyperlink code are red
Obviously if this was going to me a correct conversion to html it would be
Code:
Email: <mailto:thisis@myemail.com>thisis@myemail.com</a>
and code for font colour too
I'm sure there must be a simple way to do this as people must want to take HTML code from people based on richtextbox input?
Using this form currently
Code:
function Read-MultiLineInputDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
{
<#
	.EXAMPLE
	$inputText = Read-MultiLineInputDialog -Message "If you have a really long message you can break it apart`nover two lines with the powershell newline character:" -WindowTitle "Window Title" -DefaultText "Default text for the input box."
	
	Shows how to break the second parameter (Message) up onto two lines using the powershell newline character (`n).
	If you break the message up into more than two lines the extra lines will be hidden behind or show ontop of the TextBox.
	
	.NOTES
	Name: Show-MultiLineInputDialog
	Author: Daniel Schroeder (originally based on the code shown at [URL unfurl="true"]http://technet.microsoft.com/en-us/library/ff730941.aspx)[/URL]
	Version: 1.0
#>
	Add-Type -AssemblyName System.Drawing
	Add-Type -AssemblyName System.Windows.Forms
	
	# Create the Label.
	$label = New-Object System.Windows.Forms.Label
	$label.Location = New-Object System.Drawing.Size(10,10) 
	$label.Size = New-Object System.Drawing.Size(280,20)
	$label.AutoSize = $true
	$label.Text = $Message
	
	# Create the RichTextBox used to capture the user's text.
	$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
	$richTextBox1.Anchor = 15
	$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 10
	$System_Drawing_Point.Y = 40
	$richTextBox1.Location = $System_Drawing_Point
	$richTextBox1.Name = "richTextBox1"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 200
	$System_Drawing_Size.Width = 575
	$richTextBox1.Size = $System_Drawing_Size
	$richTextBox1.TabIndex = 2
	$richTextBox1.Text = ""
	$richTextBox1.font = "Arial"

	# Create the OK button.
	$okButton = New-Object System.Windows.Forms.Button
	$okButton.Location = New-Object System.Drawing.Size(415,250)
	$okButton.Size = New-Object System.Drawing.Size(75,25)
	$okButton.Text = "OK"
	$okButton.Add_Click({ $form.Tag = $richTextBox1.Text; $form.Close() })
	
	# Create the Cancel button.
	$cancelButton = New-Object System.Windows.Forms.Button
	$cancelButton.Location = New-Object System.Drawing.Size(510,250)
	$cancelButton.Size = New-Object System.Drawing.Size(75,25)
	$cancelButton.Text = "Cancel"
	$cancelButton.Add_Click({ $form.Tag = $null; $form.Close() })
	
	# Create the form.
	$form = New-Object System.Windows.Forms.Form 
	$form.Text = $WindowTitle
	$form.Size = New-Object System.Drawing.Size(610,320)
	$form.FormBorderStyle = 'FixedSingle'
	$form.StartPosition = "CenterScreen"
	$form.AutoSizeMode = 'GrowAndShrink'
	$form.Topmost = $True
	$form.AcceptButton = $okButton
	$form.CancelButton = $cancelButton
	$form.ShowInTaskbar = $true
	
	# Add all of the controls to the form.
	$form.Controls.Add($label)
	$form.Controls.Add($richTextBox1)
	$form.Controls.Add($okButton)
	$form.Controls.Add($cancelButton)
	
	# Initialize and show the form.
	$form.Add_Shown({$form.Activate()})
	$form.ShowDialog() > $null	# Trash the text of the button that was clicked.
	
	# Return the text that the user entered.
	return $form.Tag
}

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Attached is the difference between pasting html markup copied to the clipboard from the left nav of this website into word vs into my ps script's form rtf textbox.
As you can see the RTF textbox doesn't handle it correctly. Once it does it is being passed to the "set-mailboxautoreplyconfiguration" cmdlet for exchange which accepts HTML not RTF so I think it would need converting? Eitherway for now I'm using a multiline textbox instead and losing all the formatting :/

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
 http://files.engineering.com/getfile.aspx?folder=46986897-42ae-47e9-9a30-54d463963013&file=pasting_rtf.png
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top