示例#1
0
    def post(self, mode=None):
        text = request.data.decode("utf-8")

        if mode == "nonpost":
            render_classes = current_app.pluggy.hook.\
                flaskbb_load_nonpost_markdown_class(
                    app=current_app
                )
        else:
            render_classes = current_app.pluggy.hook.\
                flaskbb_load_post_markdown_class(
                    app=current_app
                )

        renderer = make_renderer(render_classes)
        preview = renderer(text)
        return preview
示例#2
0
文件: views.py 项目: justanr/flaskbb
    def post(self, mode=None):
        text = request.data.decode("utf-8")

        if mode == "nonpost":
            render_classes = current_app.pluggy.hook.\
                flaskbb_load_nonpost_markdown_class(
                    app=current_app
                )
        else:
            render_classes = current_app.pluggy.hook.\
                flaskbb_load_post_markdown_class(
                    app=current_app
                )

        renderer = make_renderer(render_classes)
        preview = renderer(text)
        return preview
示例#3
0
from flaskbb.markup import FlaskBBRenderer, make_renderer

markdown = make_renderer([FlaskBBRenderer])


def test_custom_renderer():
    # custom paragraph
    p_plain = "@sh4nks is developing flaskbb."
    assert "/user/sh4nks" in markdown(p_plain)

    # custom block code with pygments highlighting (jus)
    b_plain = """
```
print("Hello World")
```
"""
    b_plain_lang = """
```python
print("Hello World")
```
"""

    assert "<pre>" in markdown(b_plain)
    assert "highlight" in markdown(b_plain_lang)

    # typo in language
    bad_language = """
```notpython
print("Hello World")
```
"""
示例#4
0
from flaskbb.markup import FlaskBBRenderer, make_renderer, DEFAULT_PLUGINS


markdown = make_renderer([FlaskBBRenderer], DEFAULT_PLUGINS)


def test_userify():
    # user link rendering plugin
    result = markdown("@sh4nks is developing flaskbb.")
    assert all(
        substring in result
        for substring in ("/user/sh4nks", "<a href=")
    )


def test_highlighting():
    # custom block code with pygments highlighting (jus)
    b_plain = """
```
print("Hello World")
```
"""
    b_plain_lang = """
```python
print("Hello World")
```
"""

    assert "<pre>" in markdown(b_plain)
    assert "highlight" in markdown(b_plain_lang)