Hola a todos.
Aquí les propongo una función que formatea un texto en párrafos, opcionalmente se puede indicar "html5" para que agregue los tags <p></p>.
Por favor si alguien tiene una mejor idea por favor no dude en compartirla.
Código:
'' Paragraph validation, double space NO, Space at the beginning and/or at the end NO, line breaks at the beginning and/or at the end NO etc.
Public Function Paragraph(strInput As String, Optional strMod As String) As String
Dim strOut As String
Dim strTmp As String
Dim int As Integer
Dim stxLines As New String[] ' List of lines as they come in txt
Dim str As String
Dim strCap As String
Dim strParagraph As String
Dim stxParagraph As New String[]
'
strTmp = Replace(strInput, "\n ", "\n")
strTmp = Replace(strInput, "\n\n", "\n")
strTmp = Replace(strInput, "\t\n", "\n")
strTmp = Replace(strInput, "\n\t", "\n")
' Work by paragraph
strParagraph = ""
For int = 0 To stxLines.Max
If stxLines[int] <> "" Then
str = String.Trim(stxLines[int])
strCap = String.Left(str)
Select int
Case 0
stxParagraph.Add(str)
Case Else
If String.UCase(strCap) = strCap Then
stxParagraph.Add(str)
Else
stxParagraph[stxParagraph.Max] = stxParagraph[stxParagraph.Max] & " " & str
Endif
End Select
Endif
Next
Select String.LCase(strMod)
Case "html", "html5"
For int = 0 To stxParagraph.Max
' Proceed to validate the characters, in this case for XHTML 1.0
strParagraph = XmlValidate(stxParagraph[int], "utf8")
strParagraph = ReTager(strParagraph)
If InStr(strParagraph, "<h") > 0 Then
stxParagraph[int] = "\n" & strParagraph & "\n"
Else
stxParagraph[int] = "<p>" & strParagraph & "</p>"
Endif
Next
End Select
strOut = stxParagraph.Join("\n")
Return strOut
End
Saludos.