Exemple #1
0
def get_output(content, namespaces, visonly, full, strict):
    output = ''
    if visonly:
        return bbcode.get_visual(content)
    elif strict:
        output += 'Errors:\n-------\n\n'
        output += get_errors(content, namespaces)
        return output
    elif full:
        output += 'Arguments:\n----------\n\n'
        output += '  namespaces: %s\n' % namespaces
        output += '  visonly:    %s\n' % visonly
        output += '  full:       %s\n' % full
        output += '  strict:     %s\n' % strict
        output += '\nVisual:\n-------\n\n'
        output += bbcode.get_visual(content, namespaces)
        output += '\n\nTags:\n-----\n\n'
        for tag in bbcode.lib.get_tags(namespaces):
            output += '  %s\n' % tag.__name__ 
        output += '\nErrors:\n-------\n\n'
        output += get_errors(content, namespaces)
        output += '\nInput:\n------\n\n'
        output += content
        output += '\nOutput:\n-------\n\n'
    parsed, errors = bbcode.parse(content, namespaces, strict=False)
    output += parsed
    return output
Exemple #2
0
def get_output(content, namespaces, visonly, full, strict):
    output = ''
    if visonly:
        return bbcode.get_visual(content)
    elif strict:
        output += 'Errors:\n-------\n\n'
        output += get_errors(content, namespaces)
        return output
    elif full:
        output += 'Arguments:\n----------\n\n'
        output += '  namespaces: %s\n' % namespaces
        output += '  visonly:    %s\n' % visonly
        output += '  full:       %s\n' % full
        output += '  strict:     %s\n' % strict
        output += '\nVisual:\n-------\n\n'
        output += bbcode.get_visual(content, namespaces)
        output += '\n\nTags:\n-----\n\n'
        for tag in bbcode.lib.get_tags(namespaces):
            output += '  %s\n' % tag.__name__
        output += '\nErrors:\n-------\n\n'
        output += get_errors(content, namespaces)
        output += '\nInput:\n------\n\n'
        output += content
        output += '\nOutput:\n-------\n\n'
    parsed, errors = bbcode.parse(content, namespaces, strict=False)
    output += parsed
    return output
Exemple #3
0
def bbcode_to_html(bbcode_string):
    ######
    ## transform sting with bbcode to string with html, uses postmarkup lib
    ## http://code.google.com/p/postmarkup/wiki/Usage
    ######
    import bbcode
    converted_string = bbcode.parse(bbcode_string, auto_discover=True)
    return converted_string[0]
Exemple #4
0
 def parse(self, text):
     return bbcode.parse(text)
Exemple #5
0
import bbcode
import unittest

parse = lambda x: bbcode.parse(x, auto_discover=True)[0]


class LinkTestCase(unittest.TestCase):
    def testAutoLinks(self):
        self.assertEquals(parse("Check out ]http://example.com"), "Check out ]http://example.com")
        self.assertEquals(parse("Check outhttp://example.com"), "Check outhttp://example.com")
        self.assertEquals(
            parse("Check out http://example.com"), 'Check out <a href="http://example.com">http://example.com</a>'
        )
        self.assertEquals(
            parse("Check out www.example.com"), 'Check out <a href="http://www.example.com">www.example.com</a>'
        )

    def testURL(self):
        self.assertEquals(
            parse("Check out [url]http://example.com[/url]"),
            'Check out <a href="http://example.com">http://example.com</a>',
        )


if __name__ == "__main__":
    unittest.main()
Exemple #6
0
 def toHtml(text):
     """
 @param  text  unicode
 @return  unicode
 """
     return bbcode.parse(text) if '[' in text else text