Commits

Lukasz Balcerzak committed 6167406

Added RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES

  • Participants
  • Parent commits 6607be1

Comments (0)

Files changed (2)

File richtemplates/rstdirectives.py

 except ImportError:
     raise ImproperlyConfigured("Install pygments first")
 
+
 class CodeBlock(Directive):
     """
     Directive for a code block with pygments support.  Took from Sphinx,

File richtemplates/settings.py

     """
     Registers restructuredText directives given as dictionary
     with keys being names and paths to directive function.
+    If directive_path is None then we would turn directive off.
     """
     for name, directive_path in directives_items:
+        if directive_path is None:
+            directives.register_directive(name, None)
+            msg = "Turned off '%s' directive" % name
+            logger.debug(msg)
+            continue
         try:
             splitted = directive_path.split('.')
             mod_path, method_name = '.'.join(splitted[:-1]), splitted[-1]
 RESTRUCTUREDTEXT_DIRECTIVES = getattr(settings,
     'RICHTEMPLATES_RESTRUCTUREDTEXT_DIRECTIVES', {})
 
+
+RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = getattr(settings,
+    'RICHTEMPLATES_RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES',
+    ['include', 'meta', 'raw'])
+
+# Turn off directives first - this allows to optionally turn them on
+# using RESTRUCTUREDTEXT_DIRECTIVES
+turned_off = dict([(alias, None) for alias in
+    RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES])
+register_rst_directives(turned_off.items())
+
+# Register directives
 register_rst_directives(RESTRUCTUREDTEXT_DIRECTIVES.items())
 
 RESTRUCTUREDTEXT_PARSER_MAX_CHARS = getattr(settings,