• Code added: treating [word] as a wiki word

    By Julian Buss 2 decades ago

    Hi,



    thanks for your Wiki, I like it very much. The only thing I missed was to mark a WikiWord by using brackets [ and ].

    So I changed some code, perhaps you will build that into the next version :-)

    Here are my changes:



    Skript-library WikiPages.class:


    Private Function parseWikiWord(aLine As String, aString As String) As String<br/>
        '// Called by parseLine<br/>
        Dim c As String<br/>
        Dim i As Integer<br/>
        Dim nrCaps As Integer<br/>
        <br/>
        If Len(aString) &gt; 0 Then<br/>
    

    %REM

            If Instr(aString, &quot;:&quot;) Then<br/>
                Select Case Left(aString, Instr(aString, &quot;:&quot;))<br/>
                Case &quot;https&quot;, &quot;http&quot;, &quot;mailto&quot;, &quot;ftp&quot;:<br/>
                    parseWikiWord = {&lt;a href=&quot;} &amp; aString &amp;_<br/>
                    {&quot;&gt;} &amp; aString &amp; {&lt;/a&gt;}<br/>
                End Select<br/>
            Else<br/>
    

    %END REM

            c = Left(aString, 1)<br/>
            ' *** jbuss@youatnotes.de 5 nov 2004<br/>
            If isUCase(c) Or c = &quot;[&quot; Then ' is the first letter UPPER-CASE or it s [<br/>
                ' *** end jbuss@youatnotes.de 5 nov 2004<br/>
                nrCaps = 1      <br/>
                For i = 2 To Len(aString)<br/>
                    c = Mid(aString, i, 1)<br/>
                    If isUCase(c) Then<br/>
                        nrCaps = nrCaps + 1<br/>
                    End If<br/>
                Next<br/>
                ' *** jbuss@youatnotes.de 5 nov 2004<br/>
                If (nrCaps &gt; 1 And nrCaps &lt;&gt; Len(aString)) Or (Right(aString, 1) = &quot;]&quot;) Then ' we have a WikiWord when we have a [someword]<br/>
                    ' *** end jbuss@youatnotes.de 5 nov 2004<br/>
                    Dim dummyDoc As NotesDocument<br/>
                    Dim escaped As String<br/>
                    ' *** jbuss@youatnotes.de 5 nov 2004: moved line &quot;escape = ..&quot; some lines later<br/>
                    <br/>
                    '// Test whether wikiword is in an a link<br/>
                    If testLink(aLine, aString) Then<br/>
                        parseWikiWord = aString<br/>
                        Exit Function<br/>
                    End If<br/>
                    <br/>
                    ' *** jbuss@youatnotes.de 5 nov 2004                    <br/>
                    '// remove [ ] if present<br/>
                    If Left(aString,1) = &quot;[&quot; And Right(aString, 1) = &quot;]&quot; Then<br/>
                        aString = Right(aString, Len(aString)-1)<br/>
                        aString = Left(aString, Len(aString)-1)<br/>
                    End If<br/>
                    escaped = EscapeString(aString)<br/>
                    ' *** end jbuss@youatnotes.de 5 nov 2004<br/>
                    <br/>
                    Select Case aString<br/>
                    Case &quot;RecentChanges&quot;<br/>
                        parseWikiWord = {&lt;a href=&quot;/} &amp; dbPath &amp;_<br/>
                        {/} &amp; escaped &amp; {&quot;&gt;} &amp; aString &amp; {&lt;/a&gt;}   <br/>
                    Case &quot;BackLinks&quot;<br/>
                        parseWikiWord = {&lt;a href=&quot;/} &amp; dbPath &amp;_<br/>
                        {/} &amp; escaped &amp; {?Open&amp;Link=} &amp;_<br/>
                        EscapeString(strSubj) &amp; {&quot;&gt;} &amp;_<br/>
                        aString &amp; {&lt;/a&gt;}<br/>
                    Case Else<br/>
                        Set dummyDoc = findWikiPage(aString)<br/>
                        If dummyDoc Is Nothing Then<br/>
                            parseWikiWord = aString &amp; {&lt;a href=&quot;/} &amp;_<br/>
                            dbPath &amp; &quot;/&quot; &amp; FRM &amp; &quot;?OpenForm&amp;Title=&quot; &amp;_<br/>
                            escaped &amp; {&quot; title=&quot;Create a wiki page for '} &amp;_<br/>
                            escaped &amp; {&quot;&gt;?&lt;/a&gt;}<br/>
                        Else<br/>
                            updateLinks escaped<br/>
                            parseWikiWord = {&lt;a href=&quot;/} &amp;_<br/>
                            dbPath &amp; {/Pages/} &amp;_<br/>
                            escaped &amp; {&quot;&gt;} &amp;_<br/>
                            aString &amp; {&lt;/a&gt;}<br/>
                        End If<br/>
                    End Select<br/>
                    Exit Function<br/>
                Else <br/>
                    parseWikiWord = aString<br/>
                End If  '// If nrCaps...<br/>
            Else<br/>
                parseWikiWord = aString<br/>
            End If  '// If IsUCase...<br/>
    

    ' End If '// If Instr….

        Else <br/>
            parseWikiWord = &quot;&quot;<br/>
        End If  '// If Len...<br/>
        <br/>
    End Function<br/>
    


    Private Function isUCase(ch As String) As Integer<br/>
        Dim a As Integer<br/>
        <br/>
        ' **** jbuss@youatnotes.de 4 nov 2004<br/>
        If ch = &quot;[&quot; Then <br/>
            isUCase = True<br/>
            Exit Function<br/>
        End If<br/>
        ' **** end jbuss@youatnotes.de 4 nov 2004<br/>
        <br/>
        a = Asc(ch)<br/>
        isUCase =  (65 &lt;= a) And (a &lt;= 90)<br/>
    End Function<br/>
    <br/>
    <br/>
    Private Function isChar(ch As String) As Integer<br/>
        Dim a As Integer<br/>
        <br/>
        ' **** jbuss@youatnotes.de 4 nov 2004<br/>
        If ch = &quot;]&quot; Or ch = &quot;[&quot; Then <br/>
            isChar = True<br/>
            Exit Function<br/>
        End If<br/>
        ' **** end jbuss@youatnotes.de 4 nov 2004<br/>
        <br/>
        <br/>
        If Len(ch) = 1 Then <br/>
            a = Asc(ch)<br/>
            isChar =  (65 &lt;= a) And (a &lt;= 90) Or (97 &lt;= a)_<br/>
            And (a &lt;= 122) <br/>
        Else<br/>
            isChar = False<br/>
        End If<br/>
    End Function<br/>
    <br/>
    <br/>
    Private Function isLCase(ch As String) As Integer<br/>
        Dim a As Integer<br/>
        <br/>
        ' **** jbuss@youatnotes.de 4 nov 2004<br/>
        If ch = &quot;]&quot; Then <br/>
            isLCase = True<br/>
            Exit Function<br/>
        End If<br/>
        ' **** end jbuss@youatnotes.de 4 nov 2004<br/>
        <br/>
        a = Asc(ch)<br/>
        isLCase = (97 &lt;= a) And (a &lt;= 122) Or (a = Asc(&quot;ü&quot;))_<br/>
        Or (a = Asc(&quot;ä&quot;)) Or (a = Asc(&quot;ö&quot;)) Or (a = Asc(&quot;&amp;&quot;))_<br/>
        Or (a = Asc(&quot;;&quot;))<br/>
    End Function<br/>
    


    Function testLink(content As String, testword As String) As Boolean<br/>
        '// If one char to the left of the proposed WikiWord is NOT<br/>
        '// a blank space, assume it's buried in a URL or similar &amp;<br/>
        '// therefore leave alone -- i.e. NO wiki mark-up<br/>
        testLink = True<br/>
        Dim v As Variant<br/>
        Dim strval As String<br/>
        Dim macro As String<br/>
        <br/>
        ' *** jbuss@youatnotes.de 5 nov 2004<br/>
        ' make sure something with a starting [ is not threated as link<br/>
        If Left(testword, 1) = &quot;[&quot; Then<br/>
            testLink = False<br/>
            Exit Function<br/>
        End If<br/>
        ' *** end jbuss@youatnotes.de 5 nov 2004        <br/>
        <br/>
        '// if content contains double quotes, replace them with<br/>
        '// single ones as doubles screw up Evaluate call<br/>
        If Instr(content, {&quot;}) &gt; 0 Then<br/>
            content = ReplaceSubString(content, {&quot;}, &quot;'&quot;)<br/>
        End If<br/>
        <br/>
        macro = {@Right(@Left(&quot;} &amp; content &amp; {&quot;; &quot;} &amp;_<br/>
        testword &amp; {&quot;); 1)}<br/>
        <br/>
        v = Evaluate(macro)<br/>
        strVal = v(0)<br/>
        If strval = &quot; &quot; Then testLink = False<br/>
    End Function<br/>
    






    • Isn't DOUBLE brackets the standard?

      By Dovid Gross/NotesOSS 2 decades ago

      WikiWords don't need brackets, unless you want to use a non-CamelCase capitalization to reference an automatic wiki link. In that case, I've always seen [[doublebracketing]] as the "force wikiword" format.



      Personally, I don't find that much use for it, except where you wish to define a single-word entry (which makes CamelCase more or less impossible, unless you PuRpOsElY ObScUrE the word).

      • I could not live without it...

        By Julian Buss 2 decades ago

        I know the single bracket syntax from PHPWiki, and I have many Words which I wants to make to wiki links, but I don't want to write every word in CamelCase.

        But if OpenWiki will get single or double bracket notation doesn't matter for me :-)

    • Thanks Julian

      By Benedict R Poole 2 decades ago

      That's on my to-do list for 0.9.5, so thanks for that!