Gambas Forge BETA

Espace Membres Connexion Inscription
Vous devez être connecté pour accéder au chat.

coloration syntaxique et HTML

Ce sujet est résolu.

1
AuteurMessages
spheris#Posté le 26/01 à 22:06
Gambas Forever !Bonsoir,
Existe t il un composant dans GB qui nous permet de convertir un code coloré GB dans l'IDE en texte HTML tout en gardant les propriétés des couleurs ? genre ce qui se produit entre les balises "code" et "/code" de la forge ?
merci pour vos reponses.
;)
gambix#Posté le 26/01 à 23:20
Faire simple !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Public Sub GambasToHtml(sValue As String) As HtmlElement

Dim sLignes, s, sCode As String
Dim i, nbLignes, lenligne As Integer
Dim sTypes As String[] = ["", "normal", "keyword", "function", "operator", "symbol", "number", "string", "comment", "", "", "datatype", "", "", "", "", "error", "help", "preprocessor"]
Dim Positions, Types, Lengths As New Integer[]
Dim lignes As String[]
Dim tableau As New HtmlTable
Dim elmt As HtmlElement
Dim conteneur As New HtmlElement("code")

If Not sValue Then Return
'sret = "<table class=\"code\"><tr><td class=\"numlignes\">"
tableau.ClassName = "code"
tableau[0, 0].ClassName = "numlignes"
tableau[0, 1].ClassName = "code"
tableau[0, 1].AppendChild(conteneur)
sValue = Replace$(sValue, "\r\n", "\n") 'Compatibilité win/mac/linux
sValue = Trim$(sValue) 'Espaces indésirables
lignes = Split(sValue, "\r\n", "", False)
For Each s In lignes

Highlight.Analyze(s)

If Highlight.Positions.Count = 0 Then
conteneur.AppendText(s)
conteneur.AppendFromText("<br />")
'sCode &= s & "<br />"
Inc nbLignes
Continue
Endif
Positions = Highlight.Positions
Types = Highlight.Types
Lengths.Clear()

For i = 0 To Highlight.Symbols.Max
Lengths.Push(Len(Highlight.Symbols[i]))
Next

lenligne = Len(s)

For i = 1 To lenligne
If Positions.Count <= 0
'sCode &= String.Mid(s, i, 1)
conteneur.AppendText(Mid(s, i, 1))
Else If i = (Positions[0] + 1)
'sCode &= "<span class=\"" & sTypes[Types[0]] & "\">" & String.Mid$(s, Positions[0] + 1, Lengths[0]) & "</span>"
elmt = New HtmlElement("span")
elmt.ClassName = sTypes[Types[0]]
elmt.TextContent = Mid$(s, Positions[0] + 1, Lengths[0])
conteneur.AppendChild(elmt)
i += (Lengths[0] - 1)
Positions.Extract(0)
Lengths.Extract(0)
Types.Extract(0)
' Else If Mid$(s, i, 1) = " "
' 'sCode &= " "
' tableau[0, 1].AppendFromText(" ")
Else
'sCode &= String.Mid$(s, i, 1)
conteneur.AppendText(String.Mid(s, i, 1))
Endif
Next
'sCode &= "<br />"
conteneur.AppendFromText("<br />")
Inc nbLignes

Next

For i = 1 To nbLignes
sLignes &= (i & "<br />\n")
Next

tableau[0, 0].AppendFromText(sLignes)

' sCode = Replace$(sCode, "&", "&amp;")
' sCode = Replace$(sCode, "<", "&lt;")
' sCode = Replace$(sCode, ">", "&gt;")
' sCode = RegexpReplace(sCode, "&lt;(/?(span|br).*)&gt;", "<&1>")
' sCode = Replace$(sCode, "&amp;nbsp;", " ")
' sRet &= "</td><td class=\"code\">"
' sret &= sCode
' sRet &= "</td></tr></table>"
' Return HtmlElement.FromText(sRet)[0]
elmt = New HtmlElement("div")
elmt.ClassName = "code"
elmt.AppendChild(tableau)
Return elmt

End


avec le bon css

table.code .keyword {color: #0080FF; font-weight: bold;}
table.code .function {color: #0000FF; font-weight: normal;}
table.code .operator {color: #0000FF; font-weight: bold;}
table.code .symbol {color: #000000;}
table.code .number {color: #FF0000;}
table.code .string {color: #FF00FF;}
table.code .comment {color: #808080;}
table.code .datatype {color: #0080FF;}
table.code .error {color: #808000;font-style: italic;}
table.code .help {color: #808080; font-weight: bold;}

div.code
{
margin: 10px;
overflow: auto;
padding: 8px;
}

table.code
{
border: none !important;
border-collapse: collapse;
}

table.code code
{
white-space: pre;

font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif !important;
}

table.code tr:hover
{
background-color: transparent;
}

table.code tr td
{
text-align: left;
border: none !important;
padding: 5px;
}

table.code tr td.numlignes
{
background: rgba(198, 221, 235, 0.7);
width: 30px;
text-align: right;
color: black;
}


et le composant gb.eval.highlight
gambix#Posté le 26/01 à 23:21
Faire simple !bon la ça utilise gb.html
spheris#Posté le 26/01 à 23:39
Gambas Forever !Merci, c'est top !
;)
1

Connexion