from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import SafeString
import markdown
import urllib

register = template.Library()

@register.filter
def strip_space(value):
    return value.replace(' ', '')

@register.filter
@stringfilter
def commonmark(value):
    return markdown.Markdown().convert(value)

@register.filter(name="getID")
def get_ID(value):
    if not type(value) is str:
        return value
    return value.split('/')[-1]

@register.filter(name="getNav")
def get_nav(value):
    return value.split('/')[-2]

@register.filter(name="encode_url")
def encode_url(value):
    return urllib.parse.quote(value)

@register.filter
def get_post_id(url):
    """
    gets the post id from the comment page url
    """
    return urllib.parse.urlparse(url.get_full_path()).path.rsplit('/', 1)[0]
[((7, 11, 7, 29), 'django.template.Library', 'template.Library', ({}, {}), '()', False, 'from django import template\n'), ((30, 11, 30, 36), 'urllib.parse.quote', 'urllib.parse.quote', ({(30, 30, 30, 35): 'value'}, {}), '(value)', False, 'import urllib\n'), ((16, 11, 16, 30), 'markdown.Markdown', 'markdown.Markdown', ({}, {}), '()', False, 'import markdown\n')]