コード例 #1
0
ファイル: wikilinks.py プロジェクト: SashaBorandi/taiga-back
    def run(self, root):
        links = root.getiterator("a")
        for a in links:
            href = a.get("href", "")

            if SLUG_RE.search(href):
                # [wiki](wiki_page) -> <a href="FRONT_HOST/.../wiki/wiki_page" ...
                url = resolve("wiki", self.project.slug, href)
                a.set("href", url)
                a.set("class", "reference wiki")

            elif href and href[0] == "/":
                # [some link](/some/link) -> <a href="FRONT_HOST/some/link" ...
                url = "{}{}".format(resolve("home"), href[1:])
                a.set("href", url)
コード例 #2
0
ファイル: references.py プロジェクト: SashaBorandi/taiga-back
    def handleMatch(self, m):
        obj_ref = m.group(2)

        instance = get_instance_by_ref(self.project.id, obj_ref)
        if instance is None or instance.content_object is None:
            return "#{}".format(obj_ref)

        subject = instance.content_object.subject

        if instance.content_type.model == "userstory":
            html_classes = "reference user-story"
        elif instance.content_type.model == "task":
            html_classes = "reference task"
        elif instance.content_type.model == "issue":
            html_classes = "reference issue"
        else:
            return "#{}".format(obj_ref)

        url = resolve(instance.content_type.model, self.project.slug, obj_ref)

        link_text = "&num;{}".format(obj_ref)

        a = etree.Element('a')
        a.text = link_text
        a.set('href', url)
        a.set('title', "#{} {}".format(obj_ref, subject))
        a.set('class', html_classes)

        self.md.extracted_data['references'].append(instance.content_object)

        return a
コード例 #3
0
    def run(self, root):
        home_url = resolve("home")
        links = root.getiterator("a")
        for a in links:
            href = a.get("href", "")
            url = a.get("href", "")
            if url.endswith("/"):
                url = url[:-1]

            if not url.startswith(home_url):
                a.set("target", "_blank")
コード例 #4
0
ファイル: wikilinks.py プロジェクト: SashaBorandi/taiga-back
    def handleMatch(self, m):
        label = m.group(2).strip()
        url = resolve("wiki", self.project.slug, slugify(label))

        if m.group(3):
            title = m.group(3).strip()[1:]
        else:
            title = label

        a = etree.Element("a")
        a.text = title
        a.set("href", url)
        a.set("title", title)
        a.set("class", "reference wiki")
        return a