Giter Site home page Giter Site logo

mozmeao / django-jinja-markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nrsimha/jingo-markdown

4.0 2.0 0.0 25 KB

Django-Jinja (Jinja2) extension and filter for parse markdown text markup.

Home Page: https://pypi.python.org/pypi/django-jinja-markdown

License: MIT License

Python 100.00%

django-jinja-markdown's Introduction

Django-Jinja-Markdown

https://img.shields.io/pypi/v/django-jinja-markdown.svg?maxAge=2592000

Django-Jinja (Jinja2) extension and filter to parse markdown text in templates.

Requirements

Installation

Install django-jinja-markdown:

pip install django-jinja-markdown

Add django_jinja_markdown to INSTALLED_APPS.

To be able to use the {% markdown %} tag you should add the Jinja extension to your django_jinja TEMPLATES extensions list:

TEMPLATES = [
    {
        'BACKEND': 'django_jinja.backend.Jinja2',
        'OPTIONS': {
            'extensions': [
                'django_jinja_markdown.extensions.MarkdownExtension',
            ],
        }
    },
]

Basic Use

Examples of using filter in template:

{{ content|markdown }}
{{ markdown('this is **bold**') }}

Or with additional settings:

{{ content|markdown(extensions=['nl2br',]) }}
{{ markdown(content, extensions=['nl2br',]) }}

Example of using extension:

{% markdown %}
Text which will get converted with Markdown.
{% endmarkdown %}

License

This software is licensed under The MIT License (MIT). For more information, read the file LICENSE.

History

Forked in 2016 from the jingo-markdown project. Please see CHANGELOG for more history.

Releasing

  1. Update the version number in django_jinja_markdown/__about__.py.
  2. Add an entry to the change log in the README file.
  3. Tag the commit where you changed the above with the version number: e.g. 1.21.
  4. Push the commit and tag to the github repo.
  5. Create a new GitHub release, selecting the tag you just pushed to specify the commit. Hit Publish.
  6. Github will build and release the package to PyPI. Monitor the progress via the Actions tab.

django-jinja-markdown's People

Contributors

nrsimha avatar pmac avatar stevejalim avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-jinja-markdown's Issues

Unable to use

I am unable to use with the 3 basic usages.
django1.9
python3.5.1

setup:

settings.py

INSTALLED_APPS += (
    django_jinja,
    django_jinja_markdown,
)
TEMPLATES = [
    # Enabling markdown on templates
    {
        'BACKEND': 'django_jinja.backend.Jinja2',
        'OPTIONS': {
            'match_extension': '.jinja',
            'extensions': DEFAULT_EXTENSIONS + [
                'django_jinja_markdown.extensions.MarkdownExtension',
            ],
        },
    },
    {
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
        'DIRS': [
            str(APPS_DIR.path('templates')),
        ],
        'OPTIONS': {
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
            'debug': DEBUG,
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
            # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                # Your stuff: custom template context processors go here
            ],
        },
    },
]

index.html

{% extends "base.html" %}
{% block content %}
  {% markdown %}
    {{ content }}
  {% endmarkdown %}
{% endblock %}

error traceback

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/app/es_dashboard/home/views.py", line 12, in get
    return render(request, 'pages/home.html', {'content': content})
  File "/usr/local/lib/python3.5/site-packages/django/shortcuts.py", line 67, in render
    template_name, context, request=request, using=using)
  File "/usr/local/lib/python3.5/site-packages/django/template/loader.py", line 96, in render_to_string
    template = get_template(template_name, using=using)
  File "/usr/local/lib/python3.5/site-packages/django/template/loader.py", line 32, in get_template
    return engine.get_template(template_name, dirs)
  File "/usr/local/lib/python3.5/site-packages/django/template/backends/django.py", line 40, in get_template
    return Template(self.engine.get_template(template_name, dirs), self)
  File "/usr/local/lib/python3.5/site-packages/django/template/engine.py", line 190, in get_template
    template, origin = self.find_template(template_name, dirs)
  File "/usr/local/lib/python3.5/site-packages/django/template/engine.py", line 157, in find_template
    name, template_dirs=dirs, skip=skip,
  File "/usr/local/lib/python3.5/site-packages/django/template/loaders/cached.py", line 39, in get_template
    template_name, template_dirs, skip,
  File "/usr/local/lib/python3.5/site-packages/django/template/loaders/base.py", line 46, in get_template
    contents, origin, origin.template_name, self.engine,
  File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 189, in __init__
    self.nodelist = self.compile_nodelist()
  File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 231, in compile_nodelist
    return parser.parse()
  File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 516, in parse
    raise self.error(token, e)
  File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 514, in parse
    compiled_result = compile_func(self, token)
  File "/usr/local/lib/python3.5/site-packages/django/template/loader_tags.py", line 267, in do_extends
    nodelist = parser.parse()
  File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 510, in parse
    self.invalid_block_tag(token, command, parse_until)
  File "/usr/local/lib/python3.5/site-packages/django/template/base.py", line 572, in invalid_block_tag
    "or load this tag?" % (token.lineno, command)
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 4: 'markdown', expected 'endblock'. Did you forget to register or load this tag?

Please help me what am I doing wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.