def render_checklist(content):
    i = 0
    while 1:
        m = re.search(RE_CHECKBOX_IN_HTML, content)
        if not m:
            break
        t = m.group(0).replace('<li>', '').replace('</li>', '')
        source = '<li><label><input type="checkbox" data-item-index="%d"' % i
        end = lambda type, idx: '> ' + t.lstrip(type).strip() + \
              '</label></li>' + content[idx + len(t) + len('<li></li>'):]

        if t.startswith(CHECKED):
            checked_idx = content.find(HTML_CHECKED)
            content = content[:checked_idx] + source + ' checked' + \
                      end(CHECKED, checked_idx)
        else:
            unchecked_idx = content.find(HTML_UNCHECKED)
            content = content[:unchecked_idx] + source + \
                      end(UNCHECKED, unchecked_idx)
        i += 1
    return content
dataset/ETHPy150Open qingfeng/mikoto/mikoto/checklist.py/render_checklist/original