Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles not working #2

Open
erikcw opened this issue Dec 17, 2012 · 7 comments
Open

Styles not working #2

erikcw opened this issue Dec 17, 2012 · 7 comments

Comments

@erikcw
Copy link

erikcw commented Dec 17, 2012

I'm trying to use styles with the markdown templatetag. I've setup settings.MARKDOWN_DEUX_STYLES to match the 3 styles in the README -- but regardless of which I call (trusted or recipe), the "default" style always gets used.

In [14]: from markdown_deux.conf import settings

In [15]: settings.MARKDOWN_DEUX_STYLES
Out[15]: {'default': {'extras': {'code-friendly': None}, 'safe_mode': 'escape'}}

In [16]: settings.settings.MARKDOWN_DEUX_STYLES                                                                                                                         
Out[16]: 
{'default': {'extras': {'code-friendly': None}, 'safe_mode': 'escape'},
 'recipe': {'extras': {'code-friendly': None,
   'cuddled-lists': None,
   'demote-headers': 3,
   'footnotes': None,
   'header-ids': None,
   'html-classes': {'pre': 'prettyprint'},
   'link-patterns': None,
   'pyshell': None},
  'link_patterns': [(re.compile(r'recipe\s+#?(\d+)\b', re.IGNORECASE),
    'http://code.activestate.com/recipes/\\1/')],
  'safe_mode': 'escape'},
 'trusted': {'extras': {'code-friendly': None}, 'safe_mode': False}}

# notice how it returns "default" even though "trusted" is being requested
In [18]: markdown_deux.get_style('trusted')
Out[18]: {'extras': {'code-friendly': None}, 'safe_mode': 'escape'}

It looks like the get_style function is only looking at the default settings, and not the updated settings.

@ajt
Copy link

ajt commented Mar 15, 2013

@erikcw Did you ever get this worked out?

@erikcw
Copy link
Author

erikcw commented Mar 15, 2013

@ajt No, never did get it working...

@mitchelljkotler
Copy link

Don't import the default style before setting the custom styles. This causes the settings to be loaded before they are defined and you end up with only the default style. Put this (with no imports from markdown_deux) into your settings.py and it should work:

    MARKDOWN_DEUX_STYLES = {
        "default": {
            "extras": {
                "code-friendly": None,
            },
            "safe_mode": "escape",
        },
        "trusted": {
            "extras": {
                "code-friendly": None,
            },
            "safe_mode": False,
        }
    }

@trentm
Copy link
Owner

trentm commented Apr 17, 2013

Hi all. Sorry on the non-response here. I haven't been working on a Django site for a while so I'm a little clueless on Django settings import mechanics.

I'd welcome a cleaner way to have this module pick up on MARKDOWN_DEUX_* settings from the site's settings.py file. Do you know of other django apps that have a better way here?

It looks like the README.md might be showing usage that will cause this problem:

Here is how you might add styles of your own, and preserve the default style:

    # settings.py
    from markdown_deux.conf.settings import MARKDOWN_DEUX_DEFAULT_STYLE

    MARKDOWN_DEUX_STYLES = {
        "default": MARKDOWN_DEUX_DEFAULT_STYLE,
        "trusted": {
    ...

@mitchelljkotler Does that look like the README is wrong here.

@mitchelljkotler
Copy link

The README is wrong.

The problem is that when you import MARKDOWN_DEUX_DEFAULT_STYLE, markdown_deux's settings.py is run, and since the user's MARKDOWN_DEUX_STYLES isn't defined yet, markdown duex's MARKDOWN_DEUX_STYLES is set to the default.

If you do not imoprt MARKDOWN_DEUX_DEFAULT_STYLE and just hard code it, as in my example, all works fine. By the time markdown deux's settings.py is imported, the user's MARKDOWN_DEUX_STYLES is defined and markdown deux's MARKDOWN_DEUX_STYLES picks it up correctly.

I can't think of a good way to allow this to work how you have it now. I think a decent compromise might be to always add the default style to the user's MARKDOWN_DEUX_STYLES.

So if the user wants to add a trusted style, they can do:

    MARKDOWN_DEUX_STYLES = {
        "trusted": {
            "extras": {
                "code-friendly": None,
            },
            "safe_mode": False,
        }
    }

And in markdown_deux.conf.settings.py:

MARKDOWN_DEUX_STYLES = getattr(settings, "MARKDOWN_DEUX_STYLES", {})
MARKDOWN_DEUX_STYLES.update({'default': MARKDOWN_DEUX_DEFAULT_STYLE})

This way, the default style is always accessible without the user having to put it in. Just one idea though.

@RevolutionTech
Copy link

Sorry to revive such an old thread here, but another potential solution would be to define MARKDOWN_DEUX_DEFAULT_STYLE in a different module (say conf/styles.py) and then import it into settings.py.

Then in the README you would instruct the user to import MARKDOWN_DEUX_DEFAULT_STYLE from styles.py instead.

@Wtower
Copy link

Wtower commented Jun 10, 2017

First off, thanks to the contributors for this nice project.

Having said that, in its innocence, this issue is a very serious one. I am sure many people have wasted time trying to debug both their and this code before they found out that this is a mere bad documentation issue existing for 5 years already.

I will create a merge request to apply the correct recommendation by @mitchelljkotler .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants