Пример #1
0
    def normalizeWikiWord(self, word):
        """
        Try to normalize text to a valid wiki word and return it or None
        if it can't be normalized.
        """
        mat = matchWhole(self.WikiWordEditorRE, word)
        if mat:
            return mat.group("wikiword")
            
        mat = matchWhole(self.WikiWordEditorRE2, word)
        if mat:
            if not self.footnotesAsWws and matchWhole(self.FootnoteRE, word):
                return None

            if matchWhole(self.WikiWordEditorRE, mat.group("wikiwordncc")):
                # If word is '[WikiWord]', return 'WikiWord' instead
                return mat.group("wikiwordncc")
            else:
                return self.wikiWordStart + mat.group("wikiwordncc") + \
                        self.wikiWordEnd
        
        # No valid wiki word -> try to add brackets
        parword = self.wikiWordStart + word + self.wikiWordEnd
        mat = matchWhole(self.WikiWordEditorRE2, parword)
        if mat:
            if not self.footnotesAsWws and self.FootnoteRE.match(parword):
                return None

            return self.wikiWordStart + mat.group("wikiwordncc") + self.wikiWordEnd

        return None
Пример #2
0
 def isCcWikiWord(self, word):
     """
     Test if word is syntactically a naked camel-case wiki word
     """
     if matchWhole(self.WikiWordEditorRE, word):
         return not word in self.ccWordBlacklist
         
     return False       
Пример #3
0
    def normalizeWikiWordImport(self, word):
        """
        Special version for WikidPadCompact to support importing of
        .wiki files into the database
        """
        if matchWhole(self.WikiWordEditorRE, word):
            return word
            
        if matchWhole(self.WikiWordEditorRE2, word):
            if matchWhole(self.WikiWordEditorRE,
                    word[len(self.wikiWordStart):-len(self.wikiWordEnd)]):
                # If word is '[WikiWord]', return 'WikiWord' instead
                return word[len(self.wikiWordStart):-len(self.wikiWordEnd)]
            else:
                return word
        
        # No valid wiki word -> try to add brackets
        parword = self.wikiWordStart + word + self.wikiWordEnd
        if self.WikiWordRE2.match(parword):
            return parword

        return None
Пример #4
0
    def isWikiWord(self, word):
        """
        Test if word is syntactically a wiki word
        """
        if matchWhole(self.WikiWordEditorRE, word):
            return not word in self.ccWordBlacklist
        if self.WikiWordRE2.match(word):
            if self.footnotesAsWws:
                return True
            else:
                return not self.FootnoteRE.match(word)

        return False
Пример #5
0
def isNakedWikiWordForNewWiki(word):
    """
    Function to solve a hen-egg problem:
    We need a name to create a new wiki, but the wiki must exist already
    to check if wiki name is syntactically correct.
    """
    global WikiWordEditorRE, WikiWordRE2

    if matchWhole(WikiWordEditorRE, word):
        return True

    parword = u"[" + word + u"]"
    if WikiWordRE2.match(parword):
        return True

    return False