Настройка скрипта Python (Anki аддон) - PullRequest
0 голосов
/ 05 июня 2018

Как сделать так, чтобы предложения примеров показывались курсивом и в новой строке в надстройке anki "Autodefine".Это написано на питоне.Я провел пару часов, возиться с этим, но безрезультатно. источник

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"
...