Ticket #17714: 17714_markdown_extensions_multiple_options.diff

File 17714_markdown_extensions_multiple_options.diff, 1.6 KB (added by Scott McGinness, 13 years ago)
  • django/contrib/markup/templatetags/markup.py

     
    4343    generated by actual Markdown syntax, pass "safe" as the first
    4444    extension in the list.
    4545
     46    Extensions may be given configuration options in the form of key=value
     47    pairs, separated by commas and enclosed in parenthesis immediately after
     48    the extension name. For example:
     49
     50        {{ value|markdown:"ext_name(key1=val1, key2=val2),ext2,ext3,..." }}
     51
    4652    If the version of Markdown in use does not support extensions,
    4753    they will be silently ignored.
    4854
     
    5763        # markdown.version was first added in 1.6b. The only version of markdown
    5864        # to fully support extensions before 1.6b was the shortlived 1.6a.
    5965        if hasattr(markdown, 'version'):
    60             extensions = [e for e in arg.split(",") if e]
     66            extensions = []
     67            # Ensure that splitting into extensions by commas ignores those
     68            # commas contained within parenthesis, so that extensions are
     69            # allowed multiple configuration options.
     70            for part in arg.split("("):
     71                if ")" in part and extensions:
     72                    config, part = part.split(")")
     73                    extensions[-1] += "(%s)" % config
     74                extensions.extend(e for e in part.split(",") if e)
     75
    6176            if len(extensions) > 0 and extensions[0] == "safe":
    6277                extensions = extensions[1:]
    6378                safe_mode = True
Back to Top