Пример #1
0
 def tooltipify(txt):
     for gk, gt in GLOSSARY.items():
         tooltip = u"<a href='{}' class='term' data-tooltip-offset='0' data-tooltip-id='data-tooltip-term' data-tooltip='{}'>{}</a>"
         txt = txt.replace(gk, tooltip.format(gt['link'], gt["def"], gk))
         txt = txt.replace(
             gk.lower(), tooltip.format(gt['link'], gt["def"], gk.lower()))
     return txt
Пример #2
0
    def tooltipify(txt):
        def replaceText(t, k, gt):
            tooltip = u"<a href='{0}' class='term' data-tooltip-offset='0' data-tooltip-id='data-tooltip-term' data-tooltip='{1}' data-default='{2}'>{2}</a>"
            return t.replace(k, tooltip.format(gt["link"], gt["def"], k))

        for gk, gt in GLOSSARY.items():
            txt = replaceText(txt, gk, gt)
            if "alts" in gt:
                for a in gt["alts"]:
                    txt = replaceText(txt, a, gt)
        return txt
Пример #3
0
    def tooltipify(txt):

        def replaceText(t, k, gt):
            tooltip = u"<a href='{}' class='term' data-tooltip-offset='0' data-tooltip-id='data-tooltip-term' data-tooltip='{}'>{}</a>"
            return t.replace(k, tooltip.format(gt["link"], gt["def"], k))

        for gk, gt in GLOSSARY.items():
            txt = replaceText(txt, gk, gt)
            if "alts" in gt:
                for a in gt["alts"]:
                    txt = replaceText(txt, a, gt)
        return txt
Пример #4
0
    def tooltipify(txt):
        def replaceText(t, k, gt):
            if k not in t:
                return t
            elif "link" in gt:
                tooltip = u"<a href='{0}' class='term' data-tooltip-offset='0' data-tooltip-id='data-tooltip-term' data-tooltip='{1} Click for more info.' data-default='{2}'>{2}</a>\\1"
                res = re.sub(
                    re.escape(k) + r"((?!\<|\=|\&|\?|\&|\,|\+|\%).{1}|$)",
                    tooltip.format(gt["link"], gt["def"], k), t)
            else:
                tooltip = u"<span class='term' data-tooltip-offset='0' data-tooltip-id='data-tooltip-term' data-tooltip='{0}' data-default='{1}'>{1}</span>\\1"
                res = re.sub(
                    re.escape(k) + r"((?!\<|\=|\&|\?|\&|\,|\+|\%).{1}|$)",
                    tooltip.format(gt["def"], k), t)
            return res if res else t

        for gk, gt in GLOSSARY.items():
            txt = replaceText(txt, gk, gt)
            if "alts" in gt:
                for a in gt["alts"]:
                    txt = replaceText(txt, a, gt)
        return txt
Пример #5
0
 def tooltipify(txt):
     for gk, gt in GLOSSARY.items():
         tooltip = u"<a href='{}' class='term' data-tooltip-offset='0' data-tooltip-id='data-tooltip-term' data-tooltip='{}'>{}</a>"
         txt = txt.replace(gk, tooltip.format(gt['link'], gt["def"], gk))
         txt = txt.replace(gk.lower(), tooltip.format(gt['link'], gt["def"], gk.lower()))
     return txt