Wiki TEXT pages downloader
#1
Code: (Select All)
On Error GoTo errorchecker
GoTo skip_errorchecker

errorchecker:
glitch = glitch + 1
Locate 8 + glitch, 1
Print "Glitch in a file somewhere.  Something didn't get downloaded properly. :P"
Resume Next
skip_errorchecker:

Dim Shared Cache_Folder As String
Cache_Folder$ = "./"
If InStr(_OS$, "WIN") = 0 Then Cache_Folder$ = ".\"

'If _DirExists(Cache_Folder$) = 0 Then MkDir Cache_Folder$
Dim Shared Help_sx, Help_sy, Help_cx, Help_cy
Dim Shared Help_Select, Help_cx1, Help_cy1, Help_SelX1, Help_SelX2, Help_SelY1, Help_SelY2
Dim Shared Help_MSelect
Help_sx = 1: Help_sy = 1: Help_cx = 1: Help_cy = 1
Dim Shared Help_wx1, Help_wy1, Help_wx2, Help_wy2 'defines the text section of the help window on-screen
Dim Shared Help_ww, Help_wh 'width & height of text region
Dim Shared help_h, help_w 'width & height
Dim Shared Help_Txt$ '[chr][col][link-byte1][link-byte2]
Dim Shared Help_Txt_Len
Dim Shared Help_Line$ 'index of first txt element of a line
Dim Shared Help_Link$ 'the link info [sep][type:]...[sep]
Dim Shared Help_Link_Sep$: Help_Link_Sep$ = Chr$(13)
Dim Shared Help_LinkN
Dim Shared Help_NewLineIndent
Dim Shared Help_Underline
'Link Types:
' PAGE:wikipagename
' EXTL:external link url
Dim Shared Help_Pos, Help_Wrap_Pos
Dim Shared Help_BG_Col
Dim Shared Help_Col_Normal: Help_Col_Normal = 7
Dim Shared Help_Col_Link: Help_Col_Link = 9
Dim Shared Help_Col_Bold: Help_Col_Bold = 15
Dim Shared Help_Col_Italic: Help_Col_Italic = 15
Dim Shared Help_Col_Section: Help_Col_Section = 8
Dim Shared Help_Bold, Help_Italic, Help_DList
Dim Shared Help_LockWrap, Help_LockParse
Dim Shared Help_Center, Help_CIndent$
ReDim Shared Help_LineLen(1)
ReDim Shared Back$(1)
ReDim Shared Back_Name$(1)
Type Help_Back_Type
    sx As Long
    sy As Long
    cx As Long
    cy As Long
End Type
ReDim Shared Help_Back(1) As Help_Back_Type
Back$(1) = "QB64 Help Menu"
Back_Name$(1) = Back2BackName$(Back$(1))
Help_Back(1).sx = 1: Help_Back(1).sy = 1: Help_Back(1).cx = 1: Help_Back(1).cy = 1
Dim Shared Help_Back_Pos
Help_Back_Pos = 1
Dim Shared Help_Search_Time As Double
Dim Shared Help_Search_Str As String
Dim Shared Help_PageLoaded As String
Dim Shared Help_Recaching, Help_IgnoreCache

'Unicode replacements
Type wikiUtf8Replace
    utf8 As String * 4 '= MKI$(reversed hex 2-byte UTF-8 sequence) or MKL$(reversed hex 3/4-byte UTF-8 sequence)
    repl As String * 8 '= replacement string (1-8 chars)
End Type
Dim Shared wpUtfRepl(0 To 50) As wikiUtf8Replace
Dim Shared wpUtfReplCnt: wpUtfReplCnt = -1 'wpUtfRepl index counter (pre-increment, hence
'you don't need "wpUtfReplCnt - 1" when used in loops, just do "0 TO wpUtfReplCnt"
'Note: All UTF-8 values must be reversed in MKI$/MKL$, as it flips them to little endian.
'      In the wiki text they are noted in big endian, hence we need to pre-flip them.
'2-byte sequences
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA9C2): wpUtfRepl(wpUtfReplCnt).repl = "(c)" 'copyright
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA9C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(130) 'accent (é)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA2C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(131) 'accent (â)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA0C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(133) 'accent (à)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA5C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(134) 'accent (å)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA7C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(135) 'accent (ç)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HAAC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(136) 'accent (ê)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HABC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(137) 'accent (ë)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA8C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(138) 'accent (è)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HAFC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(139) 'accent (ï)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HAEC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(140) 'accent (î)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA2C2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(155) 'cents (ø)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HBDC2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(171) 'fraction (½)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HBCC2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(172) 'fraction (¼)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA0C2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(255) 'non-breaking space
'3-byte sequences
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HA680E2): wpUtfRepl(wpUtfReplCnt).repl = "..." 'ellipsis
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8C94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(218) 'single line draw (top/left corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9094E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(191) 'single line draw (top/right corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9494E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(192) 'single line draw (bottom/left corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9894E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(217) 'single line draw (bottom/right corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8094E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(196) 'single line draw (horizontal line)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8294E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(179) 'single line draw (vertical line)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HB494E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(193) 'single line draw (hori. line + up connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HAC94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(194) 'single line draw (hori. line + down connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HA494E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(180) 'single line draw (vert. line + left connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9C94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(195) 'single line draw (vert. line + right connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HBC94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(197) 'single line draw (hori./vert. line cross)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HB296E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(30) 'triangle up
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HBC96E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(31) 'triangle down
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8497E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(17) 'triangle left
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HBA96E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(16) 'triangle right
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9186E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(24) 'arrow up
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9386E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(25) 'arrow down
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9086E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(27) 'arrow left
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9286E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(26) 'arrow right
'4-byte sequences
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H80989FF0): wpUtfRepl(wpUtfReplCnt).repl = ":)" 'smily
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H88989FF0): wpUtfRepl(wpUtfReplCnt).repl = ";)" 'wink
'========= END OF WIKI.BI

updatestep = 1
Do 'main loop

    '-------- custom display changes --------
    'update steps
    Select Case updatestep
        Case 1
            Print "Generating list of cached content..."
        Case 2
            Print "Adding core help pages to list..."
        Case 3
            Print "Regenerating keyword list..."
        Case 4
            Print "Building download queue..."
        Case 5
            Locate 8, 1: Print "Updating help content file...";
    End Select

    If updatestep = 5 Then
        maxprogresswidth = 52 'arbitrary
        percentage = Int(n / c * 100)
        percentagechars = Int(maxprogresswidth * n / c)
        'percentageMsg$ = "[" + STRING$(percentagechars, 254) + SPACE$(maxprogresswidth - percentagechars) + "]" + STR$(percentage) + "%"
        percentageMsg$ = Str$(percentage) + "%"
        Print percentageMsg$
    ElseIf updatestep = 6 Then
        percentageMsg$ = " 100%"
        Print percentageMsg$
    End If
    '-------- end of custom display changes --------

    '-------- update routine -------------------------------------
    Select Case updatestep
        Case 1
            'Create a list of all files to be recached
            f$ = Chr$(0)

            'Prepend core pages to list
            f$ = Chr$(0) + "Keyword_Reference_-_By_usage.txt" + f$
            f$ = Chr$(0) + "QB64_Help_Menu.txt" + f$
            f$ = Chr$(0) + "QB64_FAQ.txt" + f$
            updatestep = updatestep + 1
        Case 2
            updatestep = updatestep + 1
        Case 3
            'Download and PARSE alphabetical index to build required F1 help links
            FullMessage$(1) = "Regenerating keyword list..."
            Help_Recaching = 1: Help_IgnoreCache = 1
            Print "Downloading: Keyword Reference - Alphabetical "
            a$ = Wiki$("Keyword Reference - Alphabetical")
            Help_Recaching = 0: Help_IgnoreCache = 0
            WikiParse a$

            fh1 = FreeFile
            Open "Keyword_Reference_-_Alphabetical_1000000_100000000_-_100000000000.txt" For Binary As #fh1
            temp$ = Space$(LOF(fh1))
            Get #fh1, 1, temp$
            Close #fh1
            Open "links.txt" For Output As #fh1
            Print "GENERATING KEYWORDS..."

            Do
                p = InStr(p + 2, temp$, "]]")
                If p = 0 Then Exit Do
                p1 = _InStrRev(p, temp$, "[[")
                If p1 < oldp Or p1 = 0 Then Exit Do
                l$ = Mid$(temp$, p1 + 2, p - p1 - 2)
                If Left$(l$, 1) = "_" Then l$ = Mid$(l$, 2)
                If Left$(l$, 1) <> "#" Then Print #fh1, l$
                oldp = p + 2
            Loop
            Close #fh1
            Print "GENERATED KEYWORDS..."
            updatestep = updatestep + 1
        Case 4
            'Add all linked pages to download list (if not already in list)
            fh = FreeFile
            Open "links.txt" For Input As #fh
            Do Until EOF(fh)
                Line Input #fh, l$
                If Len(l$) Then
                    c = InStr(l$, ","): l$ = Right$(l$, Len(l$) - c)
                    'Escape all invalid and other critical chars in filenames
                    PageName2$ = ""
                    For i = 1 To Len(l$)
                        c = Asc(l$, i)
                        Select Case c
                            Case 32 '                                    '(space)
                                PageName2$ = PageName2$ + "_"
                            Case 34, 38, 42, 47, 58, 60, 62, 63, 92, 124 '("&*/:<>?\|)
                                PageName2$ = PageName2$ + "%" + Hex$(c)
                            Case Else
                                PageName2$ = PageName2$ + Chr$(c)
                        End Select
                    Next
                    PageName2$ = PageName2$ + ".txt"
                    If InStr(f$, Chr$(0) + PageName2$ + Chr$(0)) = 0 Then
                        f$ = f$ + PageName2$ + Chr$(0)
                    End If
                End If
            Loop
            Close #fh

            'Redownload all listed files
            If f$ <> Chr$(0) Then
                c = 0 'count files to download
                For x = 2 To Len(f$)
                    If Asc(f$, x) = 0 Then c = c + 1
                Next
                c = c - 1

                f$ = Right$(f$, Len(f$) - 1)
                z$ = Chr$(0)
                n = 0
            Else
                GoTo stoprecache
            End If
            FullMessage$(2) = ""
            updatestep = updatestep + 1
        Case 5
            If Len(f$) > 0 Then
                x2 = InStr(f$, z$)
                f2$ = Left$(f$, x2 - 1): f$ = Right$(f$, Len(f$) - x2)

                If Right$(f2$, 4) = ".txt" Then
                    f2$ = Left$(f2$, Len(f2$) - 4)
                    n = n + 1
                    FullMessage$(2) = "Page title: " + f2$
                    Help_IgnoreCache = 1: Help_Recaching = 1: ignore$ = Wiki(f2$): Help_Recaching = 0: Help_IgnoreCache = 0
                End If
            Else
                updatestep = updatestep + 1
            End If
        Case 6
            stoprecache:
            FullMessage$(1) = "All pages updated."
            FullMessage$(2) = ""
            Print "Finished!"
            End
            _Limit 20
    End Select
    '-------- end of update routine ------------------------------

    mousedown = 0
    mouseup = 0
Loop







'========= START OF WIKI.BM
Function Back2BackName$ (a$)
    If a$ = "Keyword Reference - Alphabetical" Then Back2BackName$ = "Alphabetical": Exit Function
    If a$ = "Keyword Reference - By usage" Then Back2BackName$ = "By Usage": Exit Function
    If a$ = "QB64 Help Menu" Then Back2BackName$ = "Help": Exit Function
    If a$ = "QB64 FAQ" Then Back2BackName$ = "FAQ": Exit Function
    Back2BackName$ = a$
End Function

Function Wiki$ (PageName$) 'Read cached wiki page (download, if not yet cached)
    Help_PageLoaded$ = PageName$

    'Escape all invalid and other critical chars in filenames
    PageName2$ = ""
    For i = 1 To Len(PageName$)
        c = Asc(PageName$, i)
        Select Case c
            Case 32 '                                    '(space)
                PageName2$ = PageName2$ + "_"
            Case 34, 38, 42, 47, 58, 60, 62, 63, 92, 124 '("&*/:<>?\|)
                PageName2$ = PageName2$ + "%" + Hex$(c)
            Case Else
                PageName2$ = PageName2$ + Chr$(c)
        End Select
    Next
    PageName3$ = wikiSafeName$(PageName2$) 'case independent name

    'Is this page in the cache?
    If Help_IgnoreCache = 0 Then
        If _FileExists(Cache_Folder$ + PageName3$ + ".txt") Then
            fh = FreeFile
            Open Cache_Folder$ + PageName3$ + ".txt" For Binary As #fh
            a$ = Space$(LOF(fh))
            Get #fh, , a$
            Close #fh
            chr13 = InStr(a$, Chr$(13))
            removedchr13 = 0
            Do While chr13 > 0
                removedchr13 = -1
                a$ = Left$(a$, chr13 - 1) + Mid$(a$, chr13 + 1)
                chr13 = InStr(a$, Chr$(13))
            Loop
            If removedchr13 Then
                fh = FreeFile
                Open Cache_Folder$ + PageName3$ + ".txt" For Output As #fh: Close #fh
                Open Cache_Folder$ + PageName3$ + ".txt" For Binary As #fh
                Put #fh, 1, a$
                Close #fh
            End If
            Wiki$ = a$
            Exit Function
        End If
    End If

    'Check for curl
    If _ShellHide("curl --version") <> 0 Then
        Print "Can not find cURL.  Terminating program."
        _Delay 3
        System
    End If

    'Download message (Status Bar)
    If Help_Recaching = 0 Then
        a$ = "Downloading '" + PageName$ + "' page..."
        If Len(a$) > 60 Then a$ = Left$(a$, 57) + String$(3, 250)
        If Len(a$) < 60 Then a$ = a$ + Space$(60 - Len(a$))
        Color 0, 3
        Print a$
    End If


    'Url query and output arguments for curl
    url$ = Chr$(34) + "https://www.qb64phoenix.com/qb64wiki/index.php?title=" + PageName2$ + "&action=edit" + Chr$(34)
    outputFile$ = Cache_Folder$ + PageName3$ + ".txt"
    'Wikitext delimiters
    s1$ = "name=" + Chr$(34) + "wpTextbox1" + Chr$(34) + ">"
    s2$ = "</textarea>"

    'Download page using curl
    Shell _Hide "curl -o " + Chr$(34) + outputFile$ + Chr$(34) + " " + url$
    fh = FreeFile
    Open outputFile$ For Binary As #fh 'get new content
    a$ = Space$(LOF(fh))
    Get #fh, 1, a$
    Close #fh



    'Find wikitext in the downloaded page
    s1 = InStr(a$, s1$)
    If s1 > 0 Then a$ = Mid$(a$, s1 + Len(s1$)): s2 = InStr(a$, s2$): Else s2 = 0
    If s2 > 0 Then a$ = Left$(a$, s2 - 1)
    If s1 > 0 And s2 > 0 And a$ <> "" Then
        'If wikitext was found, then substitute stuff & save it
        '--- first HTML specific entities
        While InStr(a$, "&amp;") > 0 '         '&amp; must be first and looped until all
            a$ = StrReplace$(a$, "&amp;", "&") 'multi-escapes are resolved (eg. &amp;lt; &amp;amp;lt; etc.)
        Wend
        a$ = StrReplace$(a$, "&lt;", "<")
        a$ = StrReplace$(a$, "&gt;", ">")
        a$ = StrReplace$(a$, "&quot;", Chr$(34))
        '--- then other entities
        a$ = StrReplace$(a$, "&verbar;", "|")
        a$ = StrReplace$(a$, "&pi;", Chr$(227))
        a$ = StrReplace$(a$, "&theta;", Chr$(233))
        a$ = StrReplace$(a$, "&sup1;", Chr$(252))
        a$ = StrReplace$(a$, "&sup2;", Chr$(253))
        a$ = StrReplace$(a$, "&nbsp;", Chr$(255))
        '--- useless styles in blocks
        a$ = StrReplace$(a$, "Start}}'' ''", "Start}}")
        a$ = StrReplace$(a$, "Start}} '' ''", "Start}}")
        a$ = StrReplace$(a$, "Start}}" + Chr$(10) + "'' ''", "Start}}")
        a$ = StrReplace$(a$, "'' ''" + Chr$(10) + "{{", Chr$(10) + "{{")
        a$ = StrReplace$(a$, "'' '' " + Chr$(10) + "{{", Chr$(10) + "{{")
        a$ = StrReplace$(a$, "'' ''" + MKI$(&H0A0A) + "{{", Chr$(10) + "{{")
        '--- wiki redirects
        a$ = StrReplace$(a$, "#REDIRECT", "See page")
        '--- put a download date/time entry
        a$ = "{{QBDLDATE:" + Date$ + "}}" + Chr$(10) + "{{QBDLTIME:" + Time$ + "}}" + Chr$(10) + a$
        '--- now save it
        fh = FreeFile
        Open outputFile$ For Output As #fh
        Print #fh, a$
        Close #fh
    Else
        'Delete page, if empty or corrupted (force re-download on next access)
        Kill outputFile$
        a$ = CHR$(10) + "{{PageInternalError}}" + CHR$(10) +_
             "* Either the requested page is not yet available in the Wiki," + CHR$(10) +_
             "* or the download from Wiki failed and corrupted the page data." + CHR$(10) +_
             "** You may try ''Update Current Page'' from the ''Help'' menu." + CHR$(10)
    End If



    Wiki$ = a$
End Function

Sub Help_AddTxt (t$, col, link) 'Add help text, handle word wrap
    If t$ = Chr$(13) Then Help_NewLine: Exit Sub

    For i = 1 To Len(t$)
        c = Asc(t$, i)

        If Help_LockParse = 0 And Help_LockWrap = 0 Then

            If c = 32 Then
                If Help_Pos = Help_ww Then Help_NewLine: _Continue

                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 32
                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = col + Help_BG_Col * 16
                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link And 255
                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link \ 256

                Help_Wrap_Pos = Help_Txt_Len 'pos to backtrack to when wrapping content
                Help_Pos = Help_Pos + 1: _Continue
            End If

            If Help_Pos > Help_ww Then
                If Help_Wrap_Pos Then 'attempt to wrap
                    'backtrack, insert new line, continue

                    b$ = Mid$(Help_Txt$, Help_Wrap_Pos + 1, Help_Txt_Len - Help_Wrap_Pos)

                    Help_Txt_Len = Help_Wrap_Pos

                    Help_NewLine

                    Mid$(Help_Txt$, Help_Txt_Len + 1, Len(b$)) = b$: Help_Txt_Len = Help_Txt_Len + Len(b$)

                    Help_Pos = Help_Pos + Len(b$) \ 4
                End If
            End If

        End If

        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = c
        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = col + Help_BG_Col * 16
        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link And 255
        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link \ 256

        Help_Pos = Help_Pos + 1
    Next
End Sub

Sub Help_NewLine 'Start a new help line, apply indention (if any)
    If Help_Pos > help_w Then help_w = Help_Pos

    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 13
    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = Help_BG_Col * 16
    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 0
    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 0

    help_h = help_h + 1
    Help_Line$ = Help_Line$ + MKL$(Help_Txt_Len + 1)
    Help_Wrap_Pos = 0

    If Help_Underline Then
        w = Help_Pos
        Help_Pos = 1
        If Help_Underline = Help_Col_Section Then
            Help_AddTxt String$(w - 1, 205), Help_Underline, 0
        Else
            Help_AddTxt String$(w - 1, 196), Help_Underline, 0
        End If
        Help_Underline = 0 'keep before Help_NewLine (recursion)
        Help_NewLine
    End If
    Help_Pos = 1

    If Help_Center > 0 Then 'center overrides regular indent
        Help_NewLineIndent = 0
        Help_AddTxt Space$(Asc(Help_CIndent$, 1)), Help_Col, 0
        Help_CIndent$ = Mid$(Help_CIndent$, 2)
    ElseIf Help_NewLineIndent > 0 Then
        Help_AddTxt Space$(Help_NewLineIndent), Help_Col, 0
    End If
End Sub

Sub Help_CheckFinishLine 'Make sure the current help line is finished
    If Help_Txt_Len >= 4 Then
        If Asc(Help_Txt$, Help_Txt_Len - 3) <> 13 Then Help_NewLine
    End If
End Sub

Sub Help_CheckBlankLine 'Make sure the last help line is a blank line (implies finish current)
    If Help_Txt_Len >= 8 Then
        If Asc(Help_Txt$, Help_Txt_Len - 3) <> 13 Then Help_NewLine
        If Asc(Help_Txt$, Help_Txt_Len - 7) <> 13 Then Help_NewLine
    End If
End Sub

Sub Help_CheckRemoveBlankLine 'If the last help line is blank, then remove it
    If Help_Txt_Len >= 8 Then
        If Asc(Help_Txt$, Help_Txt_Len - 3) = 13 Then
            Help_Txt_Len = Help_Txt_Len - 4
            help_h = help_h - 1
            Help_Line$ = Left$(Help_Line$, Len(Help_Line$) - 4)
        End If
        For i = Help_Txt_Len - 3 To 1 Step -4
            If Asc(Help_Txt$, i) <> 32 Then
                Help_Txt_Len = i + 3: Exit For
            End If
        Next
        If Asc(Help_Txt$, Help_Txt_Len - 3) <> 13 Then Help_NewLine
    End If
End Sub

Function Help_Col 'Helps to calculate the default color
    col = Help_Col_Normal
    If Help_Italic Then col = Help_Col_Italic
    If Help_Bold Then col = Help_Col_Bold 'Note: Bold overrides italic
    Help_Col = col
End Function

Sub WikiParse (a$) 'Wiki page interpret

    'Clear info
    help_h = 0: help_w = 0: Help_Line$ = "": Help_Link$ = "": Help_LinkN = 0
    Help_Txt$ = Space$(1000000)
    Help_Txt_Len = 0

    Help_Pos = 1: Help_Wrap_Pos = 0
    Help_Line$ = MKL$(1)
    'Word wrap locks (lock wrapping only, but continue parsing regularly)
    Help_LockWrap = 0
    'Parser locks (neg: soft lock, zero: unlocked, pos: hard lock)
    'hard:  2 = inside code blocks,  1 = inside output blocks
    'soft: -1 = inside text blocks, -2 = inside fixed blocks
    '=> all parser locks also imply a wrapping lock
    '=> hard locks almost every parsing except utf-8 substitution and line breaks
    '=> soft allows all elements not disrupting the current block, hence only
    '   paragraph creating things are locked (eg. headings, lists, rulers etc.),
    '   but text styles, links and template processing is still possible
    Help_LockParse = 0
    Help_Bold = 0: Help_Italic = 0
    Help_Underline = 0
    Help_BG_Col = 0
    Help_Center = 0: Help_CIndent$ = ""
    Help_DList = 0

    link = 0: elink = 0: cb = 0: nl = 1

    col = Help_Col

    'Syntax Notes:
    '=============
    'everywhere in text
    '------------------
    ' ''' = bold text style
    ' ''  = italic text style
    ' [url text]    = external link to url with text to appear (url ends at 1st found space)
    ' [[page]]      = link to another wikipage
    ' [[page|text]] = link to another wikipage with alternative text to appear
    ' {{templatename|param|param|param}} or simply {{templatename}} = predefined styles
    '---------------------
    'at start of line only
    '---------------------
    ' *  = dot list point
    ' ** = sub (ie. further indented) dot list point
    ' ;def:desc = full definition/description list
    ' :desc     = description only, but indented as in a full def/desc list
    ' ;* def:desc = combi list, list dot always belongs to description
    ' :* desc     = combi, description only

    'First find and write the page title and last update
    d$ = "Page not yet updated, expect visual glitches.": i = InStr(a$, "{{QBDLDATE:")
    If i > 0 Then
        d$ = "Last updated: " + Mid$(a$, i + 11, InStr(i + 11, a$, "}}") - i - 11)
        i = InStr(a$, "{{QBDLTIME:")
        If i > 0 Then d$ = d$ + ", at " + Mid$(a$, i + 11, InStr(i + 11, a$, "}}") - i - 11)
    ElseIf InStr(a$, "{{PageInternalError}}") > 0 Then
        d$ = "Page not found."
    End If
    t$ = Help_PageLoaded$: i = InStr(a$, "{{DISPLAYTITLE:")
    If i > 0 Then t$ = Mid$(a$, i + 15, InStr(i + 15, a$, "}}") - i - 15)
    If Left$(t$, 4) = "agp@" Then
        d$ = "Auto-generated temporary page."
        t$ = Mid$(t$, 5)
    End If
    i = Len(d$): ii = Len(t$)
    Help_AddTxt "   Ú" + String$(ii + 2, "Ä") + "¿", 14, 0: Help_NewLine
    Help_AddTxt "   ³ ", 14, 0: Help_AddTxt t$, 12, 0: Help_AddTxt " ³", 14, 0
    Help_AddTxt Space$(Help_ww - i - 2 - Help_Pos) + Chr$(4), 14, 0
    If Left$(d$, 4) = "Page" Then i = 8: Else i = 7
    Help_AddTxt " " + d$, i, 0: Help_NewLine
    Help_AddTxt "ÄÄÄÁ" + String$(ii + 2, "Ä") + "Á" + String$(Help_ww - ii - 7, "Ä"), 14, 0: Help_NewLine

    'Init prefetch array
    prefetch = 20
    Dim c$(prefetch)
    For ii = 1 To prefetch
        c$(ii) = Space$(ii)
    Next

    'BEGIN_PARSE_LOOP
    n = Len(a$)
    i = 1
    Do While i <= n

        'Get next char and fill prefetch array
        c = Asc(a$, i): c$ = Chr$(c)
        For i1 = 1 To prefetch
            ii = i
            For i2 = 1 To i1
                If ii <= n Then
                    Asc(c$(i1), i2) = Asc(a$, ii)
                Else
                    Asc(c$(i1), i2) = 32
                End If
                ii = ii + 1
            Next
        Next

        'Wiki specific code handling (no restrictions)
        s$ = "__NOEDITSECTION__" + Chr$(10): If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "__NOEDITSECTION__": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "__NOTOC__" + Chr$(10): If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "__NOTOC__": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "<nowiki>": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "</nowiki>": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone

        'Direct HTML code is not handled in Code/Output blocks (hard lock), as all text
        'could be part of the code example itself (just imagine a HTML parser/writer demo)
        If Help_LockParse <= 0 Then
            s$ = "<sup>": If c$(Len(s$)) = s$ Then Help_AddTxt "^", col, 0: i = i + Len(s$) - 1: GoTo charDone
            s$ = "</sup>": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone

            s$ = "<center>" 'centered section
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                wla$ = wikiLookAhead$(a$, i + 1, "</center>")
                If InStr(wla$, "#toc") > 0 Or InStr(wla$, "to Top") > 0 Then
                    i = i + Len(wla$) + 9 'ignore TOC links
                Else
                    Help_Center = 1: Help_CIndent$ = wikiBuildCIndent$(wla$)
                    Help_AddTxt Space$(Asc(Help_CIndent$, 1)), col, 0 'center content
                    Help_CIndent$ = Mid$(Help_CIndent$, 2)
                End If
                GoTo charDone
            End If
            s$ = "</center>"
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                Help_Center = 0
                Help_NewLine
                GoTo charDone
            End If
            s$ = "<p style=" 'custom paragraph (maybe centered)
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 1) = ">" Then
                        wla$ = wikiLookAhead$(a$, ii + 1, "</p>")
                        If InStr(wla$, "#toc") > 0 Or InStr(wla$, "to Top") > 0 Then
                            i = ii + Len(wla$) + 4 'ignore TOC links
                        ElseIf InStr(Mid$(a$, i, ii - i), "center") > 0 Then
                            Help_Center = 1: Help_CIndent$ = wikiBuildCIndent$(wla$)
                            Help_AddTxt Space$(Asc(Help_CIndent$, 1)), col, 0 'center (if in style)
                            Help_CIndent$ = Mid$(Help_CIndent$, 2)
                            i = ii
                        End If
                        Exit For
                    End If
                Next
                GoTo charDone
            End If
            s$ = "</p>"
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                Help_Center = 0
                Help_NewLine
                GoTo charDone
            End If
            s$ = "<span" 'custom inline attributes ignored
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 1) = ">" Then i = ii: Exit For
                Next
                GoTo charDone
            End If
            s$ = "</span>"
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                GoTo charDone
            End If

            s$ = "<div" 'ignore divisions (TOC and letter links)
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 6) = "</div>" Then i = ii + 5: Exit For
                Next
                GoTo charDone
            End If
            s$ = "<!--" 'ignore HTML comments
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 3) = "-->" Then i = ii + 2: Exit For
                Next
                GoTo charDone
            End If
        End If

        'Wiki text styles are not handled in Code/Output blocks (hard lock),
        'as they could be part of the code example itself
        If Help_LockParse <= 0 Then
            'Bold style
            If c$(3) = "'''" Then
                i = i + 2
                If Help_Bold = 0 Then Help_Bold = 1 Else Help_Bold = 0
                col = Help_Col
                GoTo charDone
            End If
            'Italic style
            If c$(2) = "''" Then
                i = i + 1
                If Help_Italic = 0 Then Help_Italic = 1 Else Help_Italic = 0
                col = Help_Col
                GoTo charDone
            End If
        End If

        'Wiki links ([ext], [[int]]) are not handled in Code/Output blocks (hard lock),
        'as all text could be part of the code example itself
        If Help_LockParse <= 0 Then
            'External links
            If c$(5) = "[http" And elink = 0 Then
                elink = 1
                elink$ = ""
                GoTo charDone
            End If
            If elink = 1 Then
                If c$ = "]" Then
                    elink = 0
                    etext$ = elink$
                    i2 = InStr(elink$, " ")
                    If i2 > 0 Then
                        etext$ = Right$(elink$, Len(elink$) - i2)
                        elink$ = Left$(elink$, i2 - 1)
                    End If

                    Help_LinkN = Help_LinkN + 1
                    Help_Link$ = Help_Link$ + "EXTL:" + elink$ + Help_Link_Sep$

                    If Help_LockParse = 0 Then
                        Help_AddTxt etext$, Help_Col_Link, Help_LinkN
                    Else
                        Help_AddTxt etext$, Help_Col_Bold, Help_LinkN
                    End If
                    GoTo charDone
                End If
                elink$ = elink$ + c$
                GoTo charDone
            End If
            'Internal links
            If c$(2) = "[[" And link = 0 Then
                i = i + 1
                link = 1
                link$ = ""
                GoTo charDone
            End If
        End If
        'However, the internal link logic must run always, as it also handles
        'the template {{Cb|, {{Cl| and {{KW| links used in code blocks
        If link = 1 Then
            If c$(2) = "]]" Or c$(2) = "}}" Then
                i = i + 1
                link = 0
                text$ = link$
                i2 = InStr(link$, "|")
                If i2 > 0 Then
                    text$ = Right$(link$, Len(link$) - i2)
                    link$ = Left$(link$, i2 - 1)
                End If

                If InStr(link$, "#") Then 'local page links not supported
                    Help_AddTxt text$, 8, 0
                    GoTo charDone
                ElseIf Left$(link$, 9) = "Category:" Then 'ignore category links
                    Help_CheckRemoveBlankLine
                    GoTo charDone
                End If

                Help_LinkN = Help_LinkN + 1
                Help_Link$ = Help_Link$ + "PAGE:" + link$ + Help_Link_Sep$

                If Help_LockParse = 0 Then
                    Help_AddTxt text$, Help_Col_Link, Help_LinkN
                Else
                    Help_AddTxt text$, Help_Col_Bold, Help_LinkN
                End If
                GoTo charDone
            End If
            link$ = link$ + c$
            GoTo charDone
        End If

        'Wiki tables ({|...|}) are not handled in Code/Output blocks (hard lock),
        'as everything could be part of the code example itself
        If Help_LockParse <= 0 Then
            'Tables (ignored, give info, if not in blocks)
            If c$(2) = "{|" Then
                wla$ = wikiLookAhead$(a$, i + 2, "|}"): iii = 0
                For ii = 1 To Len(wla$)
                    If Mid$(wla$, ii, 1) = "|" And Mid$(wla$, ii, 2) <> "|-" Then iii = iii + 1
                Next
                i = i + 1 + Len(wla$) + 2
                If iii > 1 Or InStr(wla$, "__TOC__") = 0 Then 'ignore TOC only tables
                    If Help_LockParse = 0 Then
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "The original help page has a table here, please ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "use the ", 15, 0: ii = Help_BG_Col: Help_BG_Col = 3: Help_AddTxt " View on Wiki ", 15, 0: Help_BG_Col = ii: Help_AddTxt " button in the upper right", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "corner to load the page into your browser.      ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ", 8, 0
                    End If
                End If
                GoTo charDone
            End If
        End If

        'Wiki templates are handled always, as these are the basic building blocks of all
        'the wiki pages, but look for special conditions inside (Help_LockParse checks)
        If c$(5) = "{{Cb|" Or c$(5) = "{{Cl|" Or c$(5) = "{{KW|" Then 'just nice wrapped links
            i = i + 4 '                                               'KW is deprecated (but kept for existing pages)
            link = 1
            link$ = ""
            GoTo charDone
        End If
        If c$(2) = "{{" Then 'any other templates
            i = i + 1
            cb = 1
            cb$ = ""
            GoTo charDone
        End If
        If cb > 0 Then
            If c$ = "|" Or c$(2) = "}}" Then
                If c$ = "|" And cb = 2 Then
                    wla$ = wikiLookAhead$(a$, i + 1, "}}")
                    cb = 0: i = i + Len(wla$) + 2 'after 1st, ignore all further template parameters
                ElseIf c$(2) = "}}" Then
                    If LCase$(Left$(cb$, 5)) = "small" Then
                        If Asc(cb$, 6) = 196 Then
                            Help_AddTxt " " + String$(Help_ww - Help_Pos, 196), 15, 0
                            Help_BG_Col = 0: col = Help_Col
                        Else
                            Help_Center = 0
                        End If
                        Help_NewLine: cb$ = "" 'avoid reactivation below
                    End If
                    cb = 0: i = i + 1
                End If
                If c$ = "|" And cb = 1 Then cb = 2

                If Help_LockParse = 0 Then 'no section headings in blocks
                    cbo$ = ""
                    'Standard section headings (section color, h3 w/o underline, h2 with underline)
                    'Recommended order of main page sections (h2) with it's considered sub-sections (h3)
                    If cb$ = "PageSyntax" Then cbo$ = "Syntax:"
                    If cb$ = "PageLegacySupport" Then cbo$ = "Legacy support" 'sub-sect
                    If cb$ = "PageParameters" Or cb$ = "Parameters" Then cbo$ = "Parameters:" 'w/o Page suffix is deprecated (but kept for existing pages)
                    If cb$ = "PageDescription" Then cbo$ = "Description:"
                    If cb$ = "PageQBasic" Then cbo$ = "QBasic/QuickBASIC" 'sub-sect
                    If cb$ = "PageNotes" Then cbo$ = "Notes" 'sub-sect
                    If cb$ = "PageErrors" Then cbo$ = "Errors" 'sub-sect
                    If cb$ = "PageUseWith" Then cbo$ = "Use with" 'sub-sect
                    If cb$ = "PageAvailability" Then cbo$ = "Availability:"
                    If cb$ = "PageExamples" Then cbo$ = "Examples:"
                    If cb$ = "PageSeeAlso" Then cbo$ = "See also:"
                    'Independent main page end sections (centered, no title)
                    If cb$ = "PageCopyright" Then cbo$ = "Copyright"
                    If cb$ = "PageNavigation" Then cbo$ = "" 'ignored for built-in help
                    'Internally used templates (not available in Wiki)
                    If cb$ = "PageInternalError" Then cbo$ = "Sorry, an error occurred:"
                    '----------
                    If cbo$ <> "" Then
                        If Right$(cbo$, 1) = ":" Then Help_Underline = Help_Col_Section
                        Help_AddTxt cbo$, Help_Col_Section, 0: Help_NewLine
                        If cbo$ = "Copyright" Then '_gl commands only
                            Help_NewLine: Help_AddTxt "1991-2006 Silicon Graphics, Inc.", 7, 0: Help_NewLine
                            Help_AddTxt "This document is licensed under the SGI Free Software B License.", 7, 0: Help_NewLine
                            Help_AddTxt "https://spdx.org/licenses/SGI-B-2.0.html https://spdx.org/licenses/SGI-B-2.0.html", 15, 0: Help_NewLine
                        End If
                    End If
                End If

                'Code Block
                If cb$ = "InlineCode" And Help_LockParse = 0 Then
                    Help_BG_Col = 1: Help_LockParse = 2
                End If
                If cb$ = "InlineCodeEnd" And Help_LockParse <> 0 Then
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                If cb$ = "CodeStart" And Help_LockParse = 0 Then
                    Help_CheckBlankLine
                    Help_BG_Col = 1: Help_LockParse = 2
                    Help_AddTxt String$(Help_ww - 15, 196) + " Code Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If cb$ = "CodeEnd" And Help_LockParse <> 0 Then
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$(Help_ww, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                'Output Block
                If Left$(cb$, 11) = "OutputStart" And Help_LockParse = 0 Then 'does also match new OutputStartBGn templates
                    Help_CheckBlankLine
                    Help_BG_Col = 2: Help_LockParse = 1
                    Help_AddTxt String$(Help_ww - 17, 196) + " Output Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If cb$ = "OutputEnd" And Help_LockParse <> 0 Then
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$((Help_ww - 54) \ 2, 196), 15, 0
                    Help_AddTxt " This block does not reflect the actual output colors ", 15, 0
                    Help_AddTxt String$(Help_ww - Help_Pos + 1, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                'Text Block
                If cb$ = "TextStart" And Help_LockParse = 0 Then
                    Help_CheckBlankLine
                    Help_BG_Col = 6: Help_LockParse = -1
                    Help_AddTxt String$(Help_ww - 15, 196) + " Text Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If cb$ = "TextEnd" And Help_LockParse <> 0 Then
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$(Help_ww, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                'Fixed Block
                If (cb$ = "FixedStart" Or cb$ = "WhiteStart") And Help_LockParse = 0 Then 'White is deprecated (but kept for existing pages)
                    Help_CheckBlankLine
                    Help_BG_Col = 6: Help_LockParse = -2
                    Help_AddTxt String$(Help_ww - 16, 196) + " Fixed Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If (cb$ = "FixedEnd" Or cb$ = "WhiteEnd") And Help_LockParse <> 0 Then 'White is deprecated (but kept for existing pages)
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$(Help_ww, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If

                'Template wrapped table
                If Right$(cb$, 5) = "Table" And Help_LockParse = 0 Then 'no table info in blocks
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "The original help page has a table here, please ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "use the ", 15, 0: ii = Help_BG_Col: Help_BG_Col = 3: Help_AddTxt " View on Wiki ", 15, 0: Help_BG_Col = ii: Help_AddTxt " button in the upper right", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "corner to load the page into your browser.      ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ", 8, 0
                End If

                'Small template text will be centered (maybe as block note)
                If LCase$(cb$) = "small" And Help_LockParse <= 0 Then 'keep as is in Code/Output blocks
                    wla$ = wikiLookAhead$(a$, i + 1, "}}")
                    Help_CIndent$ = wikiBuildCIndent$(wla$): iii = 0
                    If i > 31 And Asc(Help_CIndent$, 1) >= Help_ww / 4 Then
                        If InStr(Mid$(a$, i - 30, 30), "{{CodeEnd}}") > 0 Then iii = -1
                        If InStr(Mid$(a$, i - 30, 30), "{{TextEnd}}") > 0 Then iii = -6
                        If InStr(Mid$(a$, i - 31, 31), "{{FixedEnd}}") > 0 Then iii = -6
                        If InStr(Mid$(a$, i - 31, 31), "{{WhiteEnd}}") > 0 Then iii = -6
                    End If
                    If iii <> 0 Then
                        For ii = Help_Txt_Len - 3 To 1 Step -4
                            If Asc(Help_Txt$, ii) = 13 And iii < 0 Then
                                help_h = help_h - 1: Help_Line$ = Left$(Help_Line$, Len(Help_Line$) - 4)
                            ElseIf Asc(Help_Txt$, ii) = 196 And iii < 0 Then
                                iii = -iii
                            ElseIf Asc(Help_Txt$, ii) = 13 And iii > 0 Then
                                Help_Txt_Len = ii + 3: Exit For
                            End If
                        Next
                        Help_BG_Col = iii: cb$ = cb$ + Chr$(196) 'special signal byte
                        Help_AddTxt String$(Asc(Help_CIndent$, 1) - 1, 196) + " ", 15, 0
                        col = 15 'further text color until closing
                    Else
                        Help_Center = 1: cb$ = cb$ + Chr$(0) 'no special signal
                        Help_AddTxt Space$(Asc(Help_CIndent$, 1)), col, 0 'center content
                    End If
                    Help_CIndent$ = Mid$(Help_CIndent$, 2)
                End If

                GoTo charDone
            End If

            If cb = 1 Then cb$ = cb$ + c$ 'reading macro name
            If cb = 2 Then Help_AddTxt Chr$(c), col, 0 'copy macro'd text
            GoTo charDone
        End If

        'Wiki headings (==...==}) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Custom section headings (current color, h3 w/o underline, h2 with underline)
            ii = 0
            If c$(5) = " === " Then ii = 4
            If c$(4) = "=== " Then ii = 3
            If c$(4) = " ===" Then ii = 3
            If c$(3) = "===" Then ii = 2
            If ii > 0 Then i = i + ii: GoTo charDone
            ii = 0
            If c$(4) = " == " Then ii = 3
            If c$(3) = "== " Then ii = 2
            If c$(3) = " ==" Then ii = 2
            If c$(2) = "==" Then ii = 1
            If ii > 0 Then i = i + ii: Help_Underline = col: GoTo charDone
        End If

        'Wiki/HTML rulers (----, <hr>) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Rulers
            If c$(4) = "----" And nl = 1 Then
                i = i + 3
                Help_AddTxt String$(Help_ww, 196), 8, 0
                GoTo charDone
            End If
            If c$(4) = "<hr>" Or c$(6) = "<hr />" Then
                If c$(4) = "<hr>" Then i = i + 3
                If c$(6) = "<hr />" Then i = i + 5
                Help_CheckFinishLine
                Help_AddTxt String$(Help_ww, 196), 8, 0
                GoTo charDone
            End If
        End If

        'Wiki definition lists (;...:...) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Definition lists
            If c$ = ";" And nl = 1 Then 'definition (new line only)
                If c$(2) = "; " Then i = i + 1
                Help_Bold = 1: col = Help_Col: Help_DList = 1
                If c$(3) = ";* " Then i = i + 2: Help_DList = 3 'list dot belongs to description
                If c$(2) = ";*" Then i = i + 1: Help_DList = 2 'list dot belongs to description
                GoTo charDone
            End If
            If c$ = ":" And Help_DList > 0 Then 'description (same or new line)
                If c$(2) = ": " Then i = i + 1
                Help_Bold = 0: col = Help_Col
                If nl = 0 Then Help_NewLine
                Help_AddTxt "   ", col, 0
                Help_NewLineIndent = Help_NewLineIndent + 3
                If Help_DList > 1 Then
                    Help_AddTxt Chr$(4) + " ", 14, 0
                    Help_NewLineIndent = Help_NewLineIndent + 2
                End If
                Help_DList = 0
                GoTo charDone
            End If
            If c$ = ":" And nl = 1 Then 'description w/o definition (new line only)
                If c$(2) = ": " Then i = i + 1
                Help_AddTxt "   ", col, 0
                Help_NewLineIndent = Help_NewLineIndent + 3
                GoTo charDoneKnl 'keep nl state for possible <UL> list bullets
            End If
        End If

        'Wiki lists (*, **) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Unordered lists
            If nl = 1 Then
                If c$(2) = "**" Then
                    If c$(3) = "** " Then i = i + 2: Else i = i + 1
                    Help_AddTxt "   " + Chr$(4) + " ", 14, 0
                    Help_NewLineIndent = Help_NewLineIndent + 5
                    GoTo charDone
                End If
                If c$ = "*" Then
                    If c$(2) = "* " Then i = i + 1
                    Help_AddTxt Chr$(4) + " ", 14, 0
                    Help_NewLineIndent = Help_NewLineIndent + 2
                    GoTo charDone
                End If
            End If
        End If

        'Unicode handling (no restrictions)
        If ((c And &HE0~%%) = 192) And ((Asc(c$(2), 2) And &HC0~%%) = 128) Then '2-byte UTF-8
            i = i + 1
            For ii = 0 To wpUtfReplCnt
                If wpUtfRepl(ii).utf8 = c$(2) + MKI$(&H2020) Then
                    Help_AddTxt RTrim$(wpUtfRepl(ii).repl), col, 0: Exit For
                End If
            Next
            GoTo charDone
        End If
        If ((c And &HF0~%%) = 224) And ((Asc(c$(2), 2) And &HC0~%%) = 128) And ((Asc(c$(3), 3) And &HC0~%%) = 128) Then '3-byte UTF-8
            i = i + 2
            For ii = 0 To wpUtfReplCnt
                If wpUtfRepl(ii).utf8 = c$(3) + Chr$(0) Then
                    Help_AddTxt RTrim$(wpUtfRepl(ii).repl), col, 0: Exit For
                End If
            Next
            GoTo charDone
        End If
        If ((c And &HF8~%%) = 240) And ((Asc(c$(2), 2) And &HC0~%%) = 128) And ((Asc(c$(3), 3) And &HC0~%%) = 128) And ((Asc(c$(4), 4) And &HC0~%%) = 128) Then '4-byte UTF-8
            i = i + 3
            For ii = 0 To wpUtfReplCnt
                If wpUtfRepl(ii).utf8 = c$(4) Then
                    Help_AddTxt RTrim$(wpUtfRepl(ii).repl), col, 0: Exit For
                End If
            Next
            GoTo charDone
        End If

        'Line break handling (no restrictions)
        If c = 10 Or c$(4) = "<br>" Or c$(6) = "<br />" Then
            If c$(4) = "<br>" Then i = i + 3
            If c$(6) = "<br />" Then i = i + 5
            Help_NewLineIndent = 0

            If Help_LockParse > -2 Then 'everywhere except in fixed blocks
                If Help_Txt_Len >= 8 Then 'allow max. one blank line (ie. collapse multi blanks to just one)
                    If Asc(Help_Txt$, Help_Txt_Len - 3) = 13 And Asc(Help_Txt$, Help_Txt_Len - 7) = 13 Then
                        If Help_Center > 0 Then Help_CIndent$ = Mid$(Help_CIndent$, 2) 'drop respective center indent
                        GoTo skipMultiBlanks
                    End If
                End If
            End If
            Help_AddTxt Chr$(13), col, 0

            skipMultiBlanks:
            If Help_LockParse <> 0 Then 'in all blocks reset styles at EOL
                Help_Bold = 0: Help_Italic = 0: col = Help_Col
            Else
                If c = 10 Then Help_DList = 0: Help_Bold = 0: col = Help_Col 'def list incl. style ends after real new line
            End If
            nl = 1
            GoTo charDoneKnl 'keep just set nl state
        End If
        Help_AddTxt Chr$(c), col, 0

        charDone:
        nl = 0
        charDoneKnl: 'done, but keep nl state
        i = i + 1
    Loop
    'END_PARSE_LOOP

    'Trim Help_Txt$
    Help_Txt$ = Left$(Help_Txt$, Help_Txt_Len) + Chr$(13) 'chr13 stops reads past end of content
End Sub

Function wikiSafeName$ (page$) 'create a unique name for both case sensitive & insensitive systems
    ext$ = Space$(Len(page$))
    For i = 1 To Len(page$)
        c = Asc(page$, i)
        Select Case c
            Case 65 To 90: Asc(ext$, i) = 49 'upper = 1
            Case 97 To 122: Asc(ext$, i) = 48 'lower = 0
            Case Else: Asc(ext$, i) = c 'non-letter = take as is
        End Select
    Next
    wikiSafeName$ = page$ + "_" + ext$
End Function

Function wikiLookAhead$ (a$, i, token$) 'Prefetch further wiki text
    wikiLookAhead$ = "": If i >= Len(a$) Then Exit Function
    j = InStr(i, a$, token$)
    If j = 0 Then
        wikiLookAhead$ = Mid$(a$, i)
    Else
        wikiLookAhead$ = Mid$(a$, i, j - i)
    End If
End Function

Function wikiBuildCIndent$ (a$) 'Pre-calc center indentions
    wikiBuildCIndent$ = "": If a$ = "" Then Exit Function

    org$ = a$: b$ = "" 'eliminate internal links
    For i = 1 To Len(org$)
        If Mid$(org$, i, 2) = "[[" Then
            For ii = i + 2 To Len(org$)
                If Mid$(org$, ii, 1) = "|" Then i = ii + 1: Exit For
                If Mid$(org$, ii, 2) = "]]" Then i = i + 2: Exit For
            Next
        End If
        If Mid$(org$, i, 2) = "]]" Then i = i + 2
        b$ = b$ + Mid$(org$, i, 1)
    Next
    org$ = b$: b$ = "" 'eliminate external links
    For i = 1 To Len(org$)
        If Mid$(org$, i, 5) = "[http" Then
            For ii = i + 5 To Len(org$)
                If Mid$(org$, ii, 1) = " " Then i = ii + 1: Exit For
                If Mid$(org$, ii, 1) = "]" Then i = i + 1: Exit For
            Next
        End If
        If Mid$(org$, i, 1) = "]" Then i = i + 1
        b$ = b$ + Mid$(org$, i, 1)
    Next
    org$ = b$: b$ = "" 'eliminate templates
    For i = 1 To Len(org$)
        If Mid$(org$, i, 2) = "{{" Then
            For ii = i + 2 To Len(org$)
                If Mid$(org$, ii, 1) = "|" Then i = ii + 1: Exit For
                If Mid$(org$, ii, 2) = "}}" Then i = i + 2: Exit For
            Next
        End If
        If Mid$(org$, i, 1) = "|" Then
            For ii = i + 1 To Len(org$)
                If Mid$(org$, ii, 2) = "}}" Then i = ii: Exit For
            Next
        End If
        If Mid$(org$, i, 2) = "}}" Then i = i + 2
        b$ = b$ + Mid$(org$, i, 1)
    Next
    org$ = b$: b$ = "" 'eliminate text styles
    For i = 1 To Len(org$)
        If Mid$(org$, i, 3) = "'''" Then i = i + 3
        If Mid$(org$, i, 2) = "''" Then i = i + 2
        b$ = b$ + Mid$(org$, i, 1)
    Next
    b$ = StrReplace$(b$, "<br>", Chr$(10)) 'convert HTML line breaks
    b$ = StrReplace$(b$, "<br />", Chr$(10)) 'convert XHTML line breaks
    b$ = _Trim$(b$) + Chr$(10) 'safety fallback

    i = 1: st = 1: br = 0: res$ = ""
    While i <= Len(b$)
        ws = InStr(i, b$, " "): lb = InStr(i, b$, Chr$(10))
        If lb > 0 And (ws > lb Or lb - st <= Help_ww) Then Swap ws, lb
        If ws > 0 And ws - st <= Help_ww Then
            br = ws: i = ws + 1
            If Asc(b$, ws) <> 10 And i <= Len(b$) Then _Continue
        End If
        If br = 0 Then
            If lb < ws Then
                br = lb
            Else
                If ws > 0 Then br = ws: Else br = lb
            End If
        End If
        ci = (Help_ww - (br - st)) \ 2: If ci < 0 Then ci = 0
        res$ = res$ + Chr$(ci)
        i = br + 1: st = br + 1: br = 0
    Wend
    wikiBuildCIndent$ = res$
End Function



'===== Strings.bas
Function StrRemove$ (myString$, whatToRemove$) 'noncase sensitive
    Dim a$, b$
    Dim As Long i

    a$ = myString$
    b$ = LCase$(whatToRemove$)
    i = InStr(LCase$(a$), b$)
    Do While i
        a$ = Left$(a$, i - 1) + Right$(a$, Len(a$) - i - Len(b$) + 1)
        i = InStr(LCase$(a$), b$)
    Loop
    StrRemove$ = a$
End Function

Function StrReplace$ (myString$, find$, replaceWith$) 'noncase sensitive
    Dim a$, b$
    Dim As Long basei, i
    If Len(myString$) = 0 Then Exit Function
    a$ = myString$
    b$ = LCase$(find$)
    basei = 1
    i = InStr(basei, LCase$(a$), b$)
    Do While i
        a$ = Left$(a$, i - 1) + replaceWith$ + Right$(a$, Len(a$) - i - Len(b$) + 1)
        basei = i + Len(replaceWith$)
        i = InStr(basei, LCase$(a$), b$)
    Loop
    StrReplace$ = a$
End Function

Function AddQuotes$ (s$)
    AddQuotes$ = Chr$(34) + s$ + Chr$(34)
End Function


"So what is this, and what does it do," you ask?

It takes a look at our wiki and basically does the same thing externally that QB64.bas does internally with the Help menu -- it downloads our wiki in a simplified TEXT format.  

Now, one important caveat before you guys load this and run it:  Save this program in a directory by itself, as it *WILL* download about 870 files from the internet into that directory.  If you run this is your main QB64 folder, and come back later to complain about the mess it made of things, I *WILL* giggle at you and point at the big red warning here.   Remember -- make a directory for this program, save it inside that directory, and OUTPUT EXE TO SOURCE FOLDER.

Or not... And have a very cluttered directory which this download tons of junk off the web to...  The choice is yours.  Wink



I just figured this might be something nice which folks who code without using the IDE might want to use for offline reference from time to time, without having to grab the whole wiki itself.  

Note2: As is, this doesn't download any of the _gl keywords.  We almost never see programs which use _gl commands in them on the forums here, so I figured there wasn't a large demand to have those files downloaded from the wiki.  Why waste bandwidth and tie up the wiki with requests for something which folks don't generally use?  The files which are downloaded here are all the QB45 A-Z commands, and all the QB64 _A-_Z commands.  Other pages can be added later, if wanted/needed.  Smile

Note3: This is still a work in progress, hence the forum I posted it under.  Don't expect it to be 100% glitch free yet. Big Grin
Reply


Messages In This Thread
Wiki TEXT pages downloader - by SMcNeill - 05-23-2022, 04:15 AM
RE: Wiki TEXT pages downloader - by RhoSigma - 05-23-2022, 08:54 AM
RE: Wiki TEXT pages downloader - by Coolman - 05-23-2022, 09:37 AM
RE: Wiki TEXT pages downloader - by SMcNeill - 05-23-2022, 08:45 PM
RE: Wiki TEXT pages downloader - by SMcNeill - 05-24-2022, 09:50 AM



Users browsing this thread: 1 Guest(s)