#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import markdown
from htmlentitydefs import codepoint2name, name2codepoint
import re


def htmlencode(source):
    new_source = ''

    for char in source:
        if ord(char) in codepoint2name:
            char = '&%s;' % codepoint2name[ord(char)]
        new_source += char

    return new_source

def htmltest(source):
    new_source = ''

    for char in source:
        new_source += char
        # if ord(char) in codepoint2name:
        #     char = '&%s;' % codepoint2name[ord(char)]
        # new_source += char

    return new_source

def htmldecode(source):
    for entitie in re.findall('&(?:[a-z][a-z0-9]+);', source):
        entitie = entitie.replace('&', '')
        entitie = entitie.replace(';', '')
        source = source.replace('&%s;' % entitie, unichr(name2codepoint[entitie]))
    return source

if __name__ == '__main__':
    # print [a for a in "\<me么法weism a 的"]
    # # print ("<\<me么法weism a 的")
    # print len(htmltest("<\me么法weism"))
    # print htmlencode()
    # 
    a ="><script>alert('thisis ia a ')\nprint md=\\"
    print a
    # md = markdown
    # print md.markdown("><script>alert('thisis ia a ')\nprint md")