예제 #1
0
    def test_expand_db_html_with_embed(self, get_embed):
        from wagtail.embeds.models import Embed

        get_embed.return_value = Embed(html="test html")
        html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
        result = expand_db_html(html)
        self.assertIn("test html", result)
예제 #2
0
def richtext(value):
    if isinstance(value, RichText):
        # passing a RichText value through the |richtext filter should have no effect
        return value
    elif value is None:
        html = ""
    else:
        if isinstance(value, str):
            html = expand_db_html(value)
        else:
            raise TypeError(
                "'richtext' template filter received an invalid value; expected string, got {}.".format(
                    type(value)
                )
            )
    return render_to_string("wagtailcore/shared/richtext.html", {"html": html})
 def test(self):
     # self.assertEqual(exporter.render(content), html)
     # raw_content_state_string = converter.from_database_format(
     #     render_markdown(content)
     # )
     # raw_content_state = json.loads(raw_content_state_string)
     # markdown = exporter.render(raw_content_state)[:-4]
     # self.assertEqual(
     #    content.replace("\r", "").replace("\n", "").replace(' ', "")
     #    markdown.replace("\r", "").replace("\n", "").replace(' ', ""),
     # )
     raw_content_state_string = converter.from_database_format(
         render_markdown(content))
     dbhtml = converter.to_database_format(raw_content_state_string)
     # markdown = exporter.render(raw_content_state)[:-4]
     self.assertEqual(
         html.replace("\r", "").replace("\n", "").replace(" ", ""),
         expand_db_html(dbhtml).replace("\r", "").replace(
             "\n", "").replace(" ", ""),
     )
예제 #4
0
    def test_expand_html_escaping_end_to_end(self, get_embed):
        get_embed.return_value = Embed(
            url="http://www.youtube.com/watch/",
            max_width=None,
            type="video",
            html="test html",
            title="test title",
            author_name="test author name",
            provider_name="test provider name",
            thumbnail_url="http://test/thumbnail.url",
            width=1000,
            height=1000,
        )

        result = expand_db_html(
            '<p>1 2 <embed embedtype="media" url="https://www.youtube.com/watch?v=O7D-1RG-VRk&amp;t=25" /> 3 4</p>'
        )
        self.assertIn("test html", result)
        get_embed.assert_called_with(
            "https://www.youtube.com/watch?v=O7D-1RG-VRk&t=25", None, None
        )
예제 #5
0
 def test_expand_db_html_no_linktype(self):
     html = '<a id="1">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, '<a id="1">foo</a>')
예제 #6
0
 def test_expand_db_html_with_linktype(self):
     html = '<a id="1" linktype="document">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, "<a>foo</a>")
예제 #7
0
examples_path = os.path.join(os.path.dirname(__file__), "example.json")
examples = json.loads(open(examples_path, "r").read())

new_examples = []

for example in examples:
    if "skip" not in example and example["markdown"] is not None:
        dbhtml = render_markdown(example["markdown"])
        contentstate = converter.from_database_format(dbhtml)

        new_example = {
            "markdown": example["markdown"],
            "md_exprt": render(json.loads(contentstate)),
            "html": example["html"],
            "dbml": dbhtml,
            "exml": expand_db_html(dbhtml),
            "contentstate": contentstate,
            "model": example["model"],
            "field": example["field"],
        }
    else:
        new_example = {
            "markdown": example["markdown"],
            "md_exprt": "",
            "html": example["html"],
            "dbml": "",
            "exml": "",
            "contentstate": "",
            "model": example["model"],
            "field": example["field"],
        }
예제 #8
0
 def resolve_value(self, info, **kwargs):
     # Allow custom markup for RichText
     return render_to_string("wagtailcore/richtext.html",
                             {"html": expand_db_html(self.value.source)})