示例#1
0
def convert_text_simple(text):
    '''This function convert a tex document in a single
    wikitext output collapsing the content at the  -1 level'''
    config = {"input_path":filein,
              "output_path":fileout,
              "doc_title":"texla_min",
              "lang":"it",
              "keywords":json.loads(
                  open('lang.txt').read())['it'],
              "collapse_content_level":-1,
              "base_path":'',
              "create_index":0,
              }
    logging.info('######## STARTING PARSING ########')
    p = Parser(config)
    tree = p.parse(text)
    n_blocks = tree.n_blocks()
    logging.info('PARSED %i Blocks', n_blocks)

    logging.info('######## STARTING RENDERING ########')
    #rendering
    rend = MediaWikiRenderer(config)
    rend.start_rendering(tree)
    #collpasing tree
    tree = rend.tree
    tree.collapse_content_level(config['collapse_content_level'])
    tree.collapse_urls()
    tree.fix_references()
    #getting text of root_page
    output_text = rend.tree.root_page.text
    return output_text
    logging.info('Finished')
示例#2
0
def execute_texla_mediawiki(config):
    p = Parser(config)
    a = open(config['input_path'], 'r').read()
    try:
        tree = p.parse(a)
    except (PreparserError, ParserError) as err:
        err.print_error()
        err.print_complete_tree('debug/crash_tree')
        exit()
    f = open(config['output_path'] + '.tree', 'w')
    json_tree = tree.print_raw_tree()
    n_blocks = tree.get_number_blocks()
    logging.info('PARSED %i Blocks', n_blocks)
    f.write(json_tree)
    logging.info(
        '\033[0;34m############### STARTING RENDERING ###############\033[0m')
    #creating Reporter
    reporter = Reporter(tree)
    #rendering
    rend = MediaWikiRenderer(config, reporter)
    rend.start_rendering(tree)
    o = open(config['output_path'] + '.json', 'w')
    o.write(json.dumps(rend.tree.get_tree_json(), indent=3))
    #print page tree before POST-PROCESSING
    logging.info('PageTree:\n' + rend.tree.get_tree_debug())
    #collpasing
    logging.info(
        '\033[0;34m############### STARTING POST-PROCESSING ###############\033[0m'
    )
    tree = rend.tree
    tree.collapse_tree(config['collapse_content_level'],
                       config['collapse_pages_level'])
    #printing tree after POST-PROCESSING
    logging.info('PageTree:\n' + rend.tree.get_tree_debug())
    oc = open(config['output_path'] + '-coll.json', 'w')
    oc.write(json.dumps(rend.tree.get_tree_json(), indent=3))
    logging.info('\033[0;34m############### EXPORTING ###############\033[0m')
    if config['create_index']:
        tree.create_indexes(config["export_book_page"])
    exporter.exportPages(tree.pages, config['output_path'] + '.mw',
                         config['export_format'])
    if config['export_single_pages']:
        exporter.export_singlePages(tree.pages,
                                    config['output_path'] + '_pages',
                                    config['export_format'])
    if config['export_pages_tree']:
        exporter.export_pages_tree(tree.pages.values(),
                                   config['output_path'] + "_pages")
    reporter.print_report(console=True)
    logging.info('Finished')
示例#3
0
def execute_texla_mediawiki(config):
    logging.info('######## STARTING PARSING ########')
    p = Parser(config)
    a = open(config['input_path'], 'r').read()
    tree = p.parse(a)
    f = open(config['output_path'] + '.tree', 'w')
    json_tree = tree.to_json(0)
    n_blocks = tree.n_blocks()
    logging.info('PARSED %i Blocks', n_blocks)
    f.write(json_tree)
    logging.info('######## STARTING RENDERING ########')
    #rendering
    rend = MediaWikiRenderer(config)
    rend.start_rendering(tree)
    o = open(config['output_path'] + '.json', 'w')
    o.write(json.dumps(rend.tree.get_tree_json(), indent=3))
    p = open(config['output_path'] + '.debug', 'w')
    p.write(json.dumps(rend.used_tags, indent=2))
    #print page tree before POST-PROCESSING
    logging.info('PageTree:\n'+rend.tree.get_tree_debug())
    #collpasing
    logging.info('######## STARTING POST-PROCESSING ########')
    tree = rend.tree
    tree.collapse_tree(config['collapse_content_level'],
                       config['collapse_pages_level'])
    #printing tree after POST-PROCESSING
    logging.info('PageTree:\n'+rend.tree.get_tree_debug())
    oc = open(config['output_path'] + '-coll.json', 'w')
    oc.write(json.dumps(rend.tree.get_tree_json(), indent=3))
    logging.info('######## STARTING EXPORTING ########')
    if config['create_index']:
        tree.create_indexes()
    exporter.exportPages(tree.pages, config['output_path'] + '.mw',
                         config['export_format'])
    if config['export_single_pages']:
        exporter.export_singlePages(tree.pages,
                                    config['output_path'] + '_pages',
                                    config['export_format'])
    if config['export_pages_tree']:
        exporter.export_pages_tree(tree.pages.values(),
                                   config['output_path'] + "_pages")

    logging.info('Finished')