Ejemplo n.º 1
0
    def __call__(self, parent, info, page):
        """
        MooseDocs internal method, this should not be called, please use the createToken method.

        The lexer system within MooseDocs expects a function this method allows this class to act
        as a function.

        Inputs:
            info[LexerInformation]: Object containing the lexer information object.
            parent[tokens.Token]: The parent node in the AST for the token being created.
        """
        # Disable inactive extensions, the "is not None" allows this method to work when
        # components are added outside of an extension, which is needed for testing
        if (self.extension is not None) and (not self.extension.active):
            tokens.DisabledToken(parent, string=info[0])
            return parent

        # Define the settings
        defaults = self.defaultSettings()
        if self.PARSE_SETTINGS and ('settings' in info):
            self.__settings, _ = parse_settings(defaults, info['settings'])
        else:
            self.__settings = {k: v[0] for k, v in defaults.iteritems()}

        # Call user method and reset settings
        token = self.createToken(parent, info, page)
        self.__settings = None
        return token
Ejemplo n.º 2
0
    def createToken(self, parent, info, page):

        cmd = (info['command'], info['subcommand'])
        settings = info['settings']

        # Handle filename and None subcommand
        match = self.FILENAME_RE.search(
            info['subcommand']) if info['subcommand'] else None
        if match:
            cmd = (info['command'], match.group('ext'))
        elif info['subcommand'] and info['subcommand'].startswith('http'):
            cmd = (info['command'], None)
        elif info['subcommand'] and '=' in info['subcommand']:
            settings = info['subcommand'] + ' ' + settings
            cmd = (info['command'], None)

        # Locate the command object to call
        try:
            obj = CommandExtension.EXTENSION_COMMANDS[cmd]
        except KeyError:
            try:
                obj = CommandExtension.EXTENSION_COMMANDS[(cmd[0], '*')]
            except KeyError:
                msg = "The following command combination is unknown: '{} {}'."
                raise common.exceptions.MooseDocsException(msg.format(*cmd))

        if not obj.extension.active:
            if isinstance(self, InlineCommand):
                tokens.DisabledToken(parent, tag='span', string=info[0])
            tokens.DisabledToken(parent, tag='p', string=info[0])
            return parent

        # Build the token
        if obj.PARSE_SETTINGS:
            settings, _ = common.parse_settings(obj.defaultSettings(),
                                                settings)
            obj.setSettings(settings)
        token = obj.createToken(parent, info, page)
        return token