def convert(text, attrib=None, withlineno=False): output = """<div class="%s">%s</div>""" class_attrib = attrib if attrib: attribs = attrib.split(",") if len(attribs) > 1: return common.multi_attrib_error("info", text) # attribs = [ i.strip() for i in attribs ] class_attrib = re.sub(r"@(\w+)", r"info-\1", attribs[0]) else: class_attrib = "info" return output % (class_attrib, text.strip())
def convert(text, attrib=None, withlineno=False): # Generate random number for "div" id. # The same id is used to determine if decryption was successful. # This may collide for long time use. TODO: use hash. genid = random.randint(1, 1000000000) atext = "Hint" password = None js_decrypt = "false" attrib_text = "" if attrib: attrib = re.sub(r"^@", "", attrib) attlist = attrib.split(",") if len(attlist) > 2: return common.multi_attrib_error("info", text) attlist = map(string.strip, attlist) if len(attlist) == 1: attlist.append(None) (attrib_text, key) = attlist # Prepend the id. This id string will be compared after decryption to check if it's successful if key: text_with_id = ("{{%s}}" % genid) + text cipher_text = _encrypt(key, text_with_id) _register(attrib_text, key, text) text = cipher_text js_decrypt = "true" link = """<div class="disclose"><a class="disclose-link" href="javascript:void(0)" onclick="noword.handleDisclose('%s', %s);">%s</a>\n""" % (genid, js_decrypt, attrib_text) html = """ <div class="disclose-key" id="%s-key"> <input type="text" class="disclose-key-text" id="%s-key-text"> <input type="button" value="decrypt" onclick="noword.decrypt('%s');"> <span class="disclose-error" id="%s-error"></span> </div>\n """ % (genid, genid, genid, genid) html += """<div class="disclose-text" id="%s-text">%s</div>\n </div>\n """ % (genid, text) _print_encrypted_list() return link + html