PB2HTML, is this around somewhere?
Posted: Thu Mar 10, 2011 4:05 pm
Saw it here viewtopic.php?f=18&t=5269 but it seems to be the old fourms and I don't know what the "resource site" is
Thannks
Thannks
http://www.purebasic.com
https://www.purebasic.fr/english/
I'll see if I can find it.pdwyer wrote:Saw it here viewtopic.php?f=18&t=5269 but it seems to be the old fourms and I don't know what the "resource site" is
Thannks
Code: Select all
Import "SyntaxHilighting.lib"
SyntaxHighlight(*Buffer, Length, Callback, InlineAsm)
EndImport
Enumeration
#SYNTAX_Text
#SYNTAX_Keyword
#SYNTAX_Comment
#SYNTAX_Constant
#SYNTAX_String
#SYNTAX_Function
#SYNTAX_Asm
#SYNTAX_Operator
#SYNTAX_Structure
#SYNTAX_Number
#SYNTAX_Pointer
#SYNTAX_Separator
#SYNTAX_Label
EndEnumeration
Procedure FileToList(Filename.s, List Lines.s())
F = ReadFile(#PB_Any, Filename)
Fmt = ReadStringFormat(F)
If F
Repeat
AddElement(Lines())
Lines() = ReadString(F)
Until Eof(F)
CloseFile(F)
ProcedureReturn 1
EndIf
EndProcedure
Procedure Callback(*Start.Ascii, Length, Color)
Shared PB_SYNTAX_HIGHLIGHT.s
Protected EndSpan = 1
Select Color
Case #SYNTAX_Keyword
PB_SYNTAX_HIGHLIGHT + "<span class=pb_keyword>"
Case #SYNTAX_Comment
PB_SYNTAX_HIGHLIGHT + "<span class=pb_comment>"
Case #SYNTAX_Constant
PB_SYNTAX_HIGHLIGHT + "<span class=pb_constant>"
Case #SYNTAX_String
PB_SYNTAX_HIGHLIGHT + "<span class=pb_string>"
Case #SYNTAX_Function
PB_SYNTAX_HIGHLIGHT + "<span class=pb_function>"
Case #SYNTAX_Asm
PB_SYNTAX_HIGHLIGHT + "<span class=pb_asm>"
Case #SYNTAX_Operator
PB_SYNTAX_HIGHLIGHT + "<span class=pb_operator>"
Case #SYNTAX_Structure
PB_SYNTAX_HIGHLIGHT + "<span class=pb_structure>"
Case #SYNTAX_Number
PB_SYNTAX_HIGHLIGHT + "<span class=pb_number>"
Case #SYNTAX_Pointer
PB_SYNTAX_HIGHLIGHT + "<span class=pb_pointer>"
Case #SYNTAX_Separator
PB_SYNTAX_HIGHLIGHT + "<span class=pb_separator>"
Case #SYNTAX_Label
PB_SYNTAX_HIGHLIGHT + "<span class=pb_label>"
Default
EndSpan = 0
EndSelect
Tmp.s = PeekS(*Start, Length, #PB_UTF8)
Tmp = ReplaceString(Tmp, "<", "<")
Tmp = ReplaceString(Tmp, ">", ">")
Tmp = ReplaceString(Tmp, " ", " ")
PB_SYNTAX_HIGHLIGHT + Tmp
If EndSpan
PB_SYNTAX_HIGHLIGHT + "</span>"
EndIf
EndProcedure
Procedure.s PBSyntaxHighlight(Text.s)
Shared PB_SYNTAX_HIGHLIGHT.s
PB_SYNTAX_HIGHLIGHT = ""
*Buffer = AllocateMemory(StringByteLength(Text, #PB_UTF8)+2)
Written = PokeS(*Buffer, Text, -1, #PB_UTF8)
SyntaxHighlight(*Buffer, Written, @Callback(), 0)
FreeMemory(*Buffer)
ProcedureReturn PB_SYNTAX_HIGHLIGHT
EndProcedure
Procedure SkipBlank(List Lines.s())
FirstElement(Lines())
While Trim(Lines()) = ""
DeleteElement(Lines(), 1)
Wend
EndProcedure
Procedure SkipBlankFromEnd(List Lines.s())
LastElement(Lines())
While Trim(Lines()) = ""
DeleteElement(Lines(), 1)
Wend
EndProcedure
Procedure SkipIDEComments(List Lines.s())
LastElement(Lines())
Options.s = "; IDE Options = PureBasic "
Options_Len = Len(Options)
While Left(Lines(), Options_Len) <> Options And PreviousElement(Lines())
Wend
If Left(Lines(), Options_Len) = Options
Repeat
DeleteElement(Lines())
Until NextElement(Lines()) = 0
EndIf
EndProcedure
Procedure.s GetLineNumber(n)
ProcedureReturn "<td class=pb_lnum>" + Str(n) + "<div class=ln_cont>↪<br>↪<br>↪</div></td>"
EndProcedure
Procedure CropToPage(List Lines.s(), Page.s)
Protected Line = 1
Protected Found = 0
ForEach Lines()
If Left(Lines(), 2) = ";@"
P.s = Trim(Mid(Lines(), 3))
DeleteElement(Lines())
;Line - 1
If Found
; Delete the rest of Lines()
While NextElement(Lines())
DeleteElement(Lines())
Wend
ProcedureReturn Line
ElseIf P = Page
Found = 1
EndIf
ElseIf Found = 0
DeleteElement(Lines())
Line + 1
EndIf
Next
ProcedureReturn Line
EndProcedure
Procedure.s PBSyntaxHighlightFile(Fn.s, Page.s="")
Protected NewList Lines.s()
Protected Line = 1
If FileSize(Fn) <= 0
ProcedureReturn "File not found: " + Fn
EndIf
FileToList(Fn, Lines())
; SkipBlank(Lines())
; SkipIDEComments(Lines())
If Page
Line = CropToPage(Lines(), Page)
EndIf
;SkipBlankFromEnd(Lines())
T.s = "<table class=pb_code>"
ForEach Lines()
T + "<tr>" + GetLineNumber(Line)
T + "<td class=pb_code_td>"
T + PBSyntaxHighlight(Lines()) + "</td></tr>" + #CRLF$
Line + 1
Next
T.s + "</table>"
ProcedureReturn T
EndProcedure
; Debug PBSyntaxHighlight("global foreach")
Code: Select all
/* PureBasic syntax highlight */
.pb_code {
font-family: consolas;
font-size: 10pt;
line-height: 160%;
background-color: white;
color: black;
/* table */
border-spacing: 0px;
width: 100%;
}
td {
vertical-align: top;
}
.pb_code_td {
padding: 0px;
padding-left: 3px;
}
.pb_lnum {
width: 1em;
color: rgb(102, 102, 102);
font-weight: normal;
/*background-color: rgb(255, 198, 230);*/
background-color: rgb(255, 212, 235);
text-align: right;
padding: 0px;
padding-right: 0.3em;
padding-left: 0.4em;
overflow: hidden;
}
div.ln_cont {
max-height: 0em;
}
.pb_code {
font-weight: normal;
}
.pb_keyword {
font-weight: bold;
/*color: rgb(10, 108, 18);*/
color: rgb(30,70,138);
}
.pb_comment {
color: blue;
font-style: italic;
}
.pb_constant {
color: rgb(122, 24, 112);
color: rgb(170, 0, 80);
}
.pb_number {
color: rgb(170, 0, 80);
}
.pb_string {
color: rgb(150, 94, 0);
}
.pb_function {
color: rgb(0, 102, 0);
}
.pb_asm {
color: rgb(132, 0, 72);
}
.pb_operator {
color: rgb(0, 0, 0);
}
.pb_structure {
}
.pb_pointer {
color: blue;
}
.pb_separator {
/*color: red;*/
}
.pb_label {
}
Code: Select all
;@ elephant
Structure MyPointType
X.d
Y.d
EndStructure
;@ burning_duck
Define MyPoint.MyPointType
MyPoint\X = 4
MyPoint\Y = 7
Debug MyPoint\X ; Shows 4.0
Debug MyPoint\Y ; Shows 7.0