Accueil > > > RTF TO XHTML (BALISES P, H3, STRONG, EM)
RTF TO XHTML (BALISES P, H3, STRONG, EM)
Information sur la source
Description
Voilà j'ai eu besoin de faire ça alors voici le code. Je ne gère que les caractères paragraphe, gras, italic et un style qui me sert de visuel pour une balise h3. Je n'avais besoinde rien d'autre dans mon projet. Pas de fichier source car cela vient d'un projet global.
Source
- ''' <summary>
- ''' Met en gras le texte sélectionné du richtextbox (chp_contenu1)
- ''' </summary>
- Private Sub BoutonGras_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonGras.Click
- Dim newFontStyle As System.Drawing.FontStyle
- Dim currentFont As System.Drawing.Font = chp_contenu1.SelectionFont
-
- If chp_contenu1.SelectionFont.Bold = True Then
- newFontStyle = FontStyle.Regular
- Else
- newFontStyle = FontStyle.Bold
- End If
- chp_contenu1.SelectionColor = Color.Black
- chp_contenu1.SelectionFont = New Font(currentFont.FontFamily, 10, newFontStyle)
- End Sub
-
- ''' <summary>
- ''' Met en italic le texte sélectionné du richtextbox (chp_contenu1)
- ''' </summary>
- Private Sub Bouton_Italic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bouton_Italic.Click
- Dim newFontStyle As System.Drawing.FontStyle
- Dim currentFont As System.Drawing.Font = chp_contenu1.SelectionFont
-
- If chp_contenu1.SelectionFont.Italic = True Then
- newFontStyle = FontStyle.Regular
- Else
- newFontStyle = FontStyle.Italic
- End If
- chp_contenu1.SelectionColor = Color.Black
- chp_contenu1.SelectionFont = New Font(currentFont.FontFamily, 10, newFontStyle)
- End Sub
-
- ''' <summary>
- ''' style rtf qui représente ma balise h3
- ''' </summary>
- Private Sub Bouton_titre3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bouton_titre3.Click
-
- Dim currentFont As System.Drawing.Font = chp_contenu1.SelectionFont
- Dim TailleH3 As Integer = 10
- Dim IndexSelection As Integer = chp_contenu1.SelectionStart
- Dim TailleSelection As Integer = chp_contenu1.SelectionLength
-
- 'copy richtextbox pour recuperer la mise en forme du caractère suivant
- Dim Gest_RichTB As New RichTextBox
- Gest_RichTB.Rtf = chp_contenu1.Rtf
- Dim charSuivant As Char
- Gest_RichTB.SelectionStart = IndexSelection + TailleSelection
- Gest_RichTB.SelectionLength = 1
- charSuivant = Gest_RichTB.SelectedText
-
-
- If chp_contenu1.SelectionFont.Size = 10 Then
- TailleH3 = 14
- chp_contenu1.SelectionColor = Color.BlueViolet
- Else
- chp_contenu1.SelectionColor = Color.Black
- End If
- chp_contenu1.SelectionFont = New Font(currentFont.FontFamily, TailleH3, FontStyle.Regular)
- 'retour à la ligne après
- If charSuivant <> Chr(10) Then chp_contenu1.SelectedText += vbCrLf
- 'Si pas premier caractère
- If IndexSelection > 0 Then
- chp_contenu1.SelectionStart = IndexSelection - 1
- chp_contenu1.SelectionLength = 1
- 'Retour à la ligne avant
- chp_contenu1.SelectedText = chp_contenu1.SelectedText.Replace(Chr(10), "") & vbCrLf
- End If
- End Sub
-
- ''' <summary>
- ''' recupere le contenu de la rictextbox (contenu1) et traduction en xhtml
- ''' </summary>
- Private Function RTF_To_XHTML() As String
- Dim Str_XHTML As String = ""
-
- Dim IsCaractereBold As Boolean = False
- Dim IsCaractereH3 As Boolean = False
- Dim IsCaractereItalic As Boolean = False
- Dim IsSuivanth3 As Boolean = False
-
-
- Dim NextPara_close As Boolean = False 'un paragraphe est il ouvert
-
- Dim TaillerichBox As Integer = chp_contenu1.Text.Length 'Nb de caractères à traiter
- Dim CharSelected As String = "" 'caratères sélectionnés
- Dim CharPrecedent As Char = "" 'caractère précédent
-
-
- chp_contenu1.DeselectAll() 'aucune sélection dans la richtextbox
-
- 'Traitement du premier caractère ******************************************************
- 'selection du caractère Premier
- chp_contenu1.SelectionStart = 0
- chp_contenu1.SelectionLength = 1
- 'Recup Premier caractère
- CharSelected = chp_contenu1.SelectedText
- 'si pas titre alors ouverture paragraphe sinon traitement
- If (chp_contenu1.SelectionColor <> Color.BlueViolet) Then
- Str_XHTML += "<p>"
- NextPara_close = True
- Else
- Str_XHTML += "<h3>"
- IsCaractereH3 = True
- End If
- If chp_contenu1.SelectionFont.Bold = True Then
- Str_XHTML += "<strong>"
- IsCaractereBold = True
- ElseIf chp_contenu1.SelectionFont.Italic = True Then
- Str_XHTML += "<em>"
- IsCaractereItalic = True
-
- End If
- CharPrecedent = CharSelected
- Str_XHTML += CharSelected
-
- 'Traitement des autres caractères
- For x As Integer = 1 To TaillerichBox + 1
- 'copy richtextbox pour suivant
- Dim Gest_RichTB As New RichTextBox
- Gest_RichTB.Rtf = chp_contenu1.Rtf
- Dim charSuivant As Char
-
- 'selection du caractère x
- chp_contenu1.SelectionStart = x
- chp_contenu1.SelectionLength = 1
- CharSelected = chp_contenu1.SelectedText
-
-
- 'caractère suivant
- Gest_RichTB.SelectionStart = x + 1
- Gest_RichTB.SelectionLength = 1
- charSuivant = Gest_RichTB.SelectedText
-
-
- If CharSelected = Chr(10) Then
- If Gest_RichTB.SelectionColor = Color.BlueViolet Then
- IsSuivanth3 = True
- End If
- If NextPara_close Then
-
- Str_XHTML += "</p>" & vbCrLf
- NextPara_close = False
- If Not IsSuivanth3 Then
- Str_XHTML += vbCrLf & "<p>"
- NextPara_close = True
- IsSuivanth3 = False
- End If
- Else
- If IsCaractereH3 Then
- Str_XHTML += "</h3>"
- IsCaractereH3 = False
- End If
- If Gest_RichTB.SelectionColor <> Color.BlueViolet Then
- Str_XHTML += vbCrLf & "<p>"
- NextPara_close = True
- End If
-
- End If
- Else
- If chp_contenu1.SelectionColor = Color.BlueViolet And Not IsCaractereH3 Then
- Str_XHTML += "<h3>" & CharSelected
- IsCaractereH3 = True
- ElseIf chp_contenu1.SelectionFont.Bold And Not IsCaractereBold Then
- Str_XHTML += "<strong>" & CharSelected
- IsCaractereBold = True
- ElseIf Not Gest_RichTB.SelectionFont.Bold And IsCaractereBold Then
- Str_XHTML += CharSelected & "</strong>"
- IsCaractereBold = False
- ElseIf chp_contenu1.SelectionFont.Italic And Not IsCaractereItalic Then
- Str_XHTML += "<em>" & CharSelected
- IsCaractereItalic = True
- ElseIf Not Gest_RichTB.SelectionFont.Italic And IsCaractereItalic Then
- Str_XHTML += CharSelected & "</em>"
- IsCaractereItalic = False
- Else
- Str_XHTML += CharSelected
- End If
- End If
-
-
- Next
- If IsCaractereBold Then Str_XHTML += "</strong>"
- If IsCaractereItalic Then Str_XHTML += "</em>"
- If IsCaractereH3 Then Str_XHTML += "</h3>"
- If NextPara_close Then Str_XHTML += "</p>"
-
- Return Str_XHTML.Replace("<p></p>", "")
- End Function
''' <summary>
''' Met en gras le texte sélectionné du richtextbox (chp_contenu1)
''' </summary>
Private Sub BoutonGras_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonGras.Click
Dim newFontStyle As System.Drawing.FontStyle
Dim currentFont As System.Drawing.Font = chp_contenu1.SelectionFont
If chp_contenu1.SelectionFont.Bold = True Then
newFontStyle = FontStyle.Regular
Else
newFontStyle = FontStyle.Bold
End If
chp_contenu1.SelectionColor = Color.Black
chp_contenu1.SelectionFont = New Font(currentFont.FontFamily, 10, newFontStyle)
End Sub
''' <summary>
''' Met en italic le texte sélectionné du richtextbox (chp_contenu1)
''' </summary>
Private Sub Bouton_Italic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bouton_Italic.Click
Dim newFontStyle As System.Drawing.FontStyle
Dim currentFont As System.Drawing.Font = chp_contenu1.SelectionFont
If chp_contenu1.SelectionFont.Italic = True Then
newFontStyle = FontStyle.Regular
Else
newFontStyle = FontStyle.Italic
End If
chp_contenu1.SelectionColor = Color.Black
chp_contenu1.SelectionFont = New Font(currentFont.FontFamily, 10, newFontStyle)
End Sub
''' <summary>
''' style rtf qui représente ma balise h3
''' </summary>
Private Sub Bouton_titre3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bouton_titre3.Click
Dim currentFont As System.Drawing.Font = chp_contenu1.SelectionFont
Dim TailleH3 As Integer = 10
Dim IndexSelection As Integer = chp_contenu1.SelectionStart
Dim TailleSelection As Integer = chp_contenu1.SelectionLength
'copy richtextbox pour recuperer la mise en forme du caractère suivant
Dim Gest_RichTB As New RichTextBox
Gest_RichTB.Rtf = chp_contenu1.Rtf
Dim charSuivant As Char
Gest_RichTB.SelectionStart = IndexSelection + TailleSelection
Gest_RichTB.SelectionLength = 1
charSuivant = Gest_RichTB.SelectedText
If chp_contenu1.SelectionFont.Size = 10 Then
TailleH3 = 14
chp_contenu1.SelectionColor = Color.BlueViolet
Else
chp_contenu1.SelectionColor = Color.Black
End If
chp_contenu1.SelectionFont = New Font(currentFont.FontFamily, TailleH3, FontStyle.Regular)
'retour à la ligne après
If charSuivant <> Chr(10) Then chp_contenu1.SelectedText += vbCrLf
'Si pas premier caractère
If IndexSelection > 0 Then
chp_contenu1.SelectionStart = IndexSelection - 1
chp_contenu1.SelectionLength = 1
'Retour à la ligne avant
chp_contenu1.SelectedText = chp_contenu1.SelectedText.Replace(Chr(10), "") & vbCrLf
End If
End Sub
''' <summary>
''' recupere le contenu de la rictextbox (contenu1) et traduction en xhtml
''' </summary>
Private Function RTF_To_XHTML() As String
Dim Str_XHTML As String = ""
Dim IsCaractereBold As Boolean = False
Dim IsCaractereH3 As Boolean = False
Dim IsCaractereItalic As Boolean = False
Dim IsSuivanth3 As Boolean = False
Dim NextPara_close As Boolean = False 'un paragraphe est il ouvert
Dim TaillerichBox As Integer = chp_contenu1.Text.Length 'Nb de caractères à traiter
Dim CharSelected As String = "" 'caratères sélectionnés
Dim CharPrecedent As Char = "" 'caractère précédent
chp_contenu1.DeselectAll() 'aucune sélection dans la richtextbox
'Traitement du premier caractère ******************************************************
'selection du caractère Premier
chp_contenu1.SelectionStart = 0
chp_contenu1.SelectionLength = 1
'Recup Premier caractère
CharSelected = chp_contenu1.SelectedText
'si pas titre alors ouverture paragraphe sinon traitement
If (chp_contenu1.SelectionColor <> Color.BlueViolet) Then
Str_XHTML += "<p>"
NextPara_close = True
Else
Str_XHTML += "<h3>"
IsCaractereH3 = True
End If
If chp_contenu1.SelectionFont.Bold = True Then
Str_XHTML += "<strong>"
IsCaractereBold = True
ElseIf chp_contenu1.SelectionFont.Italic = True Then
Str_XHTML += "<em>"
IsCaractereItalic = True
End If
CharPrecedent = CharSelected
Str_XHTML += CharSelected
'Traitement des autres caractères
For x As Integer = 1 To TaillerichBox + 1
'copy richtextbox pour suivant
Dim Gest_RichTB As New RichTextBox
Gest_RichTB.Rtf = chp_contenu1.Rtf
Dim charSuivant As Char
'selection du caractère x
chp_contenu1.SelectionStart = x
chp_contenu1.SelectionLength = 1
CharSelected = chp_contenu1.SelectedText
'caractère suivant
Gest_RichTB.SelectionStart = x + 1
Gest_RichTB.SelectionLength = 1
charSuivant = Gest_RichTB.SelectedText
If CharSelected = Chr(10) Then
If Gest_RichTB.SelectionColor = Color.BlueViolet Then
IsSuivanth3 = True
End If
If NextPara_close Then
Str_XHTML += "</p>" & vbCrLf
NextPara_close = False
If Not IsSuivanth3 Then
Str_XHTML += vbCrLf & "<p>"
NextPara_close = True
IsSuivanth3 = False
End If
Else
If IsCaractereH3 Then
Str_XHTML += "</h3>"
IsCaractereH3 = False
End If
If Gest_RichTB.SelectionColor <> Color.BlueViolet Then
Str_XHTML += vbCrLf & "<p>"
NextPara_close = True
End If
End If
Else
If chp_contenu1.SelectionColor = Color.BlueViolet And Not IsCaractereH3 Then
Str_XHTML += "<h3>" & CharSelected
IsCaractereH3 = True
ElseIf chp_contenu1.SelectionFont.Bold And Not IsCaractereBold Then
Str_XHTML += "<strong>" & CharSelected
IsCaractereBold = True
ElseIf Not Gest_RichTB.SelectionFont.Bold And IsCaractereBold Then
Str_XHTML += CharSelected & "</strong>"
IsCaractereBold = False
ElseIf chp_contenu1.SelectionFont.Italic And Not IsCaractereItalic Then
Str_XHTML += "<em>" & CharSelected
IsCaractereItalic = True
ElseIf Not Gest_RichTB.SelectionFont.Italic And IsCaractereItalic Then
Str_XHTML += CharSelected & "</em>"
IsCaractereItalic = False
Else
Str_XHTML += CharSelected
End If
End If
Next
If IsCaractereBold Then Str_XHTML += "</strong>"
If IsCaractereItalic Then Str_XHTML += "</em>"
If IsCaractereH3 Then Str_XHTML += "</h3>"
If NextPara_close Then Str_XHTML += "</p>"
Return Str_XHTML.Replace("<p></p>", "")
End Function
Conclusion
J'utilise le caractère suivant afin de bien fermer mes balises
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Convertion HTML en Gif ou jpg ? SVP [ par nounours22 ]
Bonjour,quelqu'un pourrait il me dire comment effectuer une vconvertion d'une page HTML en Image par porgrammation ?Merci de vos réponses à venir.noun
SVP Help me >Conversion rtf html [ par pekinio ]
hello a tlmvoila, en fait, je voudrais enregistrer le contenu d'une rtf box , avec caracteres en couleurs, eventuellement des photos et tout, en html.
Imprimer un fichier (html. rtf..) en VB? [ par jeromax ]
Tout est dit dans le sujetMerci
Bilan => Conversion Rtf to HTML ! Propriétés Emplacement [ par scottmat ]
<span style="FONT-SIZE: 12pt; COLOR: #4f81bd; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; mso-themec
Conversion RTF/TXT -> HTML [ par OneHacker ]
Je programme avec VS Express 2005 .NET. Je voulais savoir s'il était possible de convertir du texte simple HTML ou du RTF en HTML.J'ai essayé ça mais
Rtf to Html via Word automation [ par pattex62 ]
Rtf to Html via Word automation Bonjour à tous !!! Je souhaiterais convertir le contenu d'un Richtexbox (format RTF) en format HTML !!! </p
Rtf Richtextbox vers html [ par amita ]
salut les amis surment que j'ai trové plein de source concernant cette question mais ce que j'arrive pas a trouver c'est comment convertir une image i
Convertir rtf/text richtextbox en Html, Binaire, Héxadécimale et Décimale VB.NET [ par Gabilach ]
Bonjour, cela fait longtemps que je cherche et je ne trouve vraiment rien qui réponde vraiment à mes attentes, je voudrait convertir du text/rtf dans
Lire contenu Page HTML, rechercher informations, et afficher label ... [ par onsedemande ]
Merci, merci d’avance pour votre aide, je poste à présent dans la bonne section. Etant novice sous viual basic express 10, je cherche à récupérer des
|
Derniers Blogs
XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|