def get_api_representation(self, value, context=None):
     """Expand the default serialization to turn the Markdown into HTML"""
     raw_markdown = super().get_api_representation(value, context)
     if raw_markdown:
         return render_markdown(raw_markdown)
     else:
         return ''
def test_render_markdown_table():
    md_table = """
|fooo|barr|xyzz|
|--- |--- |--- |
|abcd|abcd|abcd|
    """
    html = render_markdown(md_table)
    assert html == '<table>\n<thead>\n<tr>\n<th>fooo</th>\n<th>barr</th>\n<th>xyzz</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>abcd</td>\n<td>abcd</td>\n<td>abcd</td>\n</tr>\n</tbody>\n</table>'  # NOQA
 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(" ", ""),
     )
Example #4
0
 def to_representation(self, instance):
     representation = super().to_representation(instance)
     return helpers.render_markdown(representation)
Example #5
0
def slug_hyperlinks(value):
    try:
        helpers.render_markdown(value)
    except ObjectDoesNotExist:
        raise forms.ValidationError(INCORRECT_SLUG)
import os
import json
from wagtail.rich_text import expand_db_html, features
from core.helpers import render_markdown

from markdown_exporter import render
from wagtail_features import converter

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"],