Exemplo n.º 1
0
def test_generate_rich_content():
    value = "~~del~~"
    result = generate_rich_content(value)
    assert result["content"] == "<p><del>del</del></p>"
    assert result["toc"] == ""

    value = "# 标题"
    result = generate_rich_content(value)
    assert result["content"] == '<h1 id="标题">标题</h1>'
    assert result["toc"] == '<li><a href="#标题">标题</a></li>'

    value = "# header"
    result = generate_rich_content(value, toc_url="/absolute/")
    assert result["toc"] == '<li><a href="/absolute/#header">header</a></li>'
Exemplo n.º 2
0
def show_course_toc(course, current=None):
    material_list = course.material_set.all().values("id", "title", "body")

    key = make_template_fragment_key("course_toc", [course.pk])
    result = cache.get(key)
    # if not cached, regenerate the course's toc
    if result is None:
        # attach toc to material
        for material in material_list:
            toc_url = reverse(
                "courses:material_detail",
                kwargs={
                    "slug": course.slug,
                    "pk": material["id"]
                },
            )
            material["toc"] = generate_rich_content(material["body"],
                                                    toc_url=toc_url)["toc"]

    context = {
        "material_list": material_list,
        "course": course,
        "current": current,
    }
    return context
Exemplo n.º 3
0
def show_course_toc(course, current=None):
    material_list = course.material_set.all().values('id', 'title', 'body')

    # attach toc to material
    for material in material_list:
        toc_url = reverse('courses:material_detail',
                          kwargs={
                              'slug': course.slug,
                              'pk': material['id']
                          })
        material['toc'] = generate_rich_content(material['body'],
                                                toc_url=toc_url)['toc']

    context = {
        'material_list': material_list,
        'course': course,
        'current': current,
    }
    return context
def show_course_toc(course, current=None):
    material_list = course.material_set.all().values("id", "title", "body")

    # attach toc to material
    for material in material_list:
        toc_url = reverse(
            "courses:material_detail",
            kwargs={"slug": course.slug, "pk": material["id"]},
        )
        material["toc"] = generate_rich_content(material["body"], toc_url=toc_url)[
            "toc"
        ]

    context = {
        "material_list": material_list,
        "course": course,
        "current": current,
    }
    return context
Exemplo n.º 5
0
 def rich_content(self):
     return generate_rich_content(self.description)
Exemplo n.º 6
0
 def rich_content(self):
     return generate_rich_content(self.body)
 def comment_html(self):
     rich_content = generate_rich_content(self.comment)
     return rich_content.get("content", "")
Exemplo n.º 8
0
 def comment_html(self):
     rich_content = generate_rich_content(self.comment)
     return rich_content.get('content', '')