diff --git a/texla/Parser/Blocks/CodeBlocks.py b/texla/Parser/Blocks/CodeBlocks.py new file mode 100644 index 0000000..19d28f1 --- /dev/null +++ b/texla/Parser/Blocks/CodeBlocks.py @@ -0,0 +1,33 @@ +import logging +from .Utilities import * +from .Block import Block + +class ListingsEnvironment(Block): + + @staticmethod + def parse_environment(parser, tex, parent_block, params): + print(tex) + opts , content = CommandParser.parse_options(tex, + [('options', '[',']')]) + options = {} + + if (opts['options'] != None): + for l in opts['options'].split(','): + print(l) + ll = l.split('=') + options[ll[0].strip()] = ll[1].strip() + block = ListingsEnvironment(content, options, parent_block) + return block + + + + + def __init__(self, content, options, parent_block): + super().__init__('lstlisting', content, parent_block) + self.options = options + + + +parser_hooks = { + "lstlisting": ListingsEnvironment.parse_environment +} diff --git a/texla/Parser/Blocks/__init__.py b/texla/Parser/Blocks/__init__.py index e280e61..0f64ea0 100644 --- a/texla/Parser/Blocks/__init__.py +++ b/texla/Parser/Blocks/__init__.py @@ -1,27 +1,27 @@ import os import importlib import logging '''We can import here all the submodules and create the dictionary of parser__hooks ''' parser_hooks={} not_import = ('__init__.py', 'utility.py', 'DocumentBlock.py', - 'CommandParser.py', 'MacroParser.py') + 'CommandParser.py','EnvironmentParser.py', 'MacroParser.py') #getting path of the modules for module in os.listdir(os.path.dirname(__file__)): #utility module is not imported under Blocks if module in not_import: continue if module.endswith('.py'): m = importlib.import_module(__name__+'.'+ module[:-3]) logging.debug('BLOCKS_MODULE @ imported %s', m.__name__) if hasattr(m,"parser_hooks"): for key,value in m.parser_hooks.items(): logging.debug('BLOCKS_HOOK @ parser_hook: %s | %s', key, value) parser_hooks[key] = value logging.debug('Supported commands/environments:\n%s', '\n'.join(['@ '+key for key in sorted(parser_hooks.keys())]))