1

如何使例句在anki插件“Autodefine”中以斜体和换行显示。它是用python编写的。我花了几个小时弄乱它,但无济于事。资源

toReturn = ""
for definition in definitionArray:
    lastFunctionalLabel = ""
    toPrint = ""
    for dtTag in definition.findall("dt"):

        if dtTag.tail == "obsolete":
            dtTag.tail = "" #take away the tail word so that when printing it does not show up.
            if IGNORE_ARCHAIC:
                continue


        # We don't really care for 'verbal illustrations' or 'usage notes', even though they are occasionally useful.
        for usageNote in dtTag.findall("un"):
            dtTag.remove(usageNote)
        for verbalIllustration in dtTag.findall("vi"):
            dtTag.remove(verbalIllustration)

        # Directional cross reference doesn't make sense for us
        for dxTag in dtTag.findall("dx"):
            for dxtTag in dxTag.findall("dxt"):
                for dxnTag in dxtTag.findall("dxn"):
                    dxtTag.remove(dxnTag)

        toPrint = ET.tostring(dtTag, "", "xml").strip() # extract raw XML from <dt>...</dt>
        toPrint = toPrint.replace("<sx>", "; ") # attempt to remove 'synonymous cross reference tag' and replace with semicolon
        toPrint = toPrint.replace("<dx>", "; ") # attempt to remove 'Directional cross reference tag' and replace with semicolon
        toPrint = re.sub('<[^>]*>', '', toPrint) # remove all other XML tags
        toPrint = re.sub(':', '', toPrint) # remove all colons, since they are usually useless and have been replaced with semicolons above
        toPrint = toPrint.replace(" ; ", "; ").strip() # erase space between semicolon and previous word, if exists, and strip any extraneous whitespace
        toPrint += "<br>\n"
4

0 回答 0