Faire simple !![](images/avatars/avatar-1.jpeg) | 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, "&", "&") ' sCode = Replace$(sCode, "<", "<") ' sCode = Replace$(sCode, ">", ">") ' sCode = RegexpReplace(sCode, "<(/?(span|br).*)>", "<&1>") ' sCode = Replace$(sCode, "&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.highlightMoins de texte dans une signature c'est agrandir son espace. |