def abc_navigation_bar(items): """ Returns alphabet ordered links to given items :param items: all items :return: html div object """ html = htmltree('div') sorted_items = sorted(items, cmp=HTMLFormatter.__cmp) html.bold('Records ') HTMLFormatter._add_items(sorted_items, html, 'Record', reverse=False) html.bold('Abstract record ') HTMLFormatter._add_items(sorted_items, html, 'AbstractRecord', reverse=False) html.bold('Selections ') HTMLFormatter._add_items(sorted_items, html, 'Selection', reverse=False) return html
def format(items): """ Formats given items to HTML format :param items: json items :return: html div element containing all given elements """ html = htmltree('div') html.id('input-reference') for item in items: # format only IST nodes if issubclass(item.__class__, ISTNode): # do no format certain objects if not item.include_in_format(): continue try: fmt = HTMLFormatter.get_formatter_for(item) fmt.format(item) html.add(fmt.current()) except NotImplementedException as e: # NotImplementedException pass return html
def format(items): """ Formats given items to HTML format :param items: json items :return: html div element containing all given elements """ html = htmltree('div') html.id('ist') Logger.instance().info('Processing items...') i = 0 for item in items: i += 1 if i > 1050: break # do no format certain objects if not item.include_in_format(): Logger.instance().info('[SKIP] %s skipped\n' % str(item)) continue Logger.instance().info('[ OK ] formatting item %s\n' % str(item)) fmt = HTMLFormatter.get_formatter_for(item) fmt.format(item) html.add(fmt.current()) return html
def format(items): """ Formats given items to HTML format :param items: json items :return: html div element containing all given elements """ html = htmltree('div') html.id('input-reference') for item in items: # format only IST nodes if issubclass(item.__class__, ISTNode): # do no format certain objects if not item.include_in_format(): continue try: fmt = HTMLFormatter.get_formatter_for(item) fmt.format(item) html.add(fmt.current()) except Exception as e: # print e continue return html
def __init__(self, html): self.html = html if html is not None else htmltree('div', 'record-key-default') self.format_rules = { 'value at read time': self.raw_format, 'value at declaration': self.textlangle_format, 'optional': self.textlangle_format, 'obligatory': self.textlangle_format }
def __init__(self, html): self.html = html if html is not None else htmltree( 'div', 'record-key-default') self.format_rules = { 'value at read time': self.raw_format, 'value at declaration': self.textlangle_format, 'optional': self.textlangle_format, 'obligatory': self.textlangle_format }
def tree_navigation_bar(items): """ Returns default ordered links to given items :param items: all items :return: html div object """ html = htmltree('div') # sorted_items = sorted(items, cmp=HTMLFormatter.__cmp) html.bold('All items ') HTMLFormatter._add_items(items, html) return html
def abc_navigation_bar(items): """ Returns alphabet ordered links to given items :param items: all items :return: html div object """ html = htmltree('div', 'menu-items') import functools sorted_items = sorted(items, key=functools.cmp_to_key(HTMLFormatter.__cmp)) html.h3('Records') HTMLFormatter._add_items(sorted_items, html, 'Record', reverse=False, cls='r') html.h3('Tuples') HTMLFormatter._add_items(sorted_items, html, 'Tuple', reverse=False, cls='t') html.h3('Abstract records') HTMLFormatter._add_items(sorted_items, html, 'Abstract', reverse=False, cls='a') html.h3('Selections') HTMLFormatter._add_items(sorted_items, html, 'Selection', reverse=False, cls='s') return html
def format(items): """ Formats given items to HTML format :param items: json items :return: html div element containing all given elements """ html = htmltree('div') html.id('input-reference') Logger.instance().info('Processing items...') for item in items: # do no format certain objects if not item.include_in_format(): Logger.instance().info(' - item skipped: %s' % str(item)) continue Logger.instance().info(' - formatting item: %s' % str(item)) fmt = HTMLFormatter.get_formatter_for(item) fmt.format(item) html.add(fmt.current()) return html
def json2html(input_file, output_file, focus_element_id='root', skip_block_creation=[]): """ Method converts given input file to single html output file :param input_file: input json file :param output_file: output html file :param focus_element_id: id of element which will be visible, default root :param skip_block_creation: list of items which won't be created: [title, button-control, left-list, ist, right-list] :return: """ with open(input_file, 'r') as fp: json_object = json.load(fp, encoding="utf-8", cls=ProfilerJSONDecoder) html_content = HTMLFormatter.format(json_object) html_nav_abc = HTMLFormatter.abc_navigation_bar(json_object) html_nav_tree = HTMLFormatter.tree_navigation_bar(json_object) # show specified element by given id for child in html_content.current(): if child.attrib['id'].lower() == focus_element_id.lower(): child.attrib['class'] = child.attrib['class'].replace('hidden', '') print "Element {:s} is displayed".format(child.attrib['id']) break max_cols = 12 if 'right-list' not in skip_block_creation or 'left-list' not in skip_block_creation: max_cols -= 3 html_body = htmltree('body') generated = 'Generated {:s}'.format(datetime.datetime.today().strftime('%d-%m-%Y %X')) html_body.span(generated, id='info-generated') with html_body.open('div', '', cls='jumbotron', id='top'): with html_body.open('div', '', cls='container'): if 'title' not in skip_block_creation: with html_body.open('h1', 'Flow123d '): html_body.tag('small', 'input reference') if 'search' not in skip_block_creation: with html_body.open('div', cls='form-group has-default has-feedback search-wrapper'): html_body.tag('span', cls='glyphicon glyphicon-search form-control-feedback') html_body.tag('input', type='text', cls='form-control', id='search', placeholder='type to search') with html_body.open('div', cls='row'): if 'right-list' not in skip_block_creation or 'left-list' not in skip_block_creation: with html_body.open('div', cls="col-md-3 tree-list"): with html_body.open('ul', cls="nav nav-tabs", role="tablist"): classes = ['', 'active'] if 'left-list' not in skip_block_creation: with html_body.open('li', cls=classes.pop(), role="presentation"): html_body.tag('a', 'Tree', attrib={ 'role': 'rab', 'aria-controls': 'tree-view', 'data-toggle': 'tab' }) if 'right-list' not in skip_block_creation: with html_body.open('li', role="presentation", cls=classes.pop()): html_body.tag('a', 'Abcd', attrib={ 'role': 'rab', 'aria-controls': 'abc-view', 'data-toggle': 'tab' }, ) with html_body.open('div', cls='tab-content'): classes = ['tab-pane', 'tab-pane active'] if 'left-list' not in skip_block_creation: with html_body.open('div', role='tabpanel', cls=classes.pop(), id='tree-view'): html_body.add(html_nav_tree.current()) if 'right-list' not in skip_block_creation: with html_body.open('div', role='tabpanel', cls=classes.pop(), id='abc-view'): html_body.add(html_nav_abc.current()) if 'ist' not in skip_block_creation: with html_body.open('div', cls='col-md-{:d} input-reference'.format(max_cols)): if 'button-control' not in skip_block_creation: with html_body.open('div', id='button-control', cls='row'): with html_body.open('div', cls='col-md-12'): with html_body.open('div', id='btn-filter-one-wrapper'): html_body.tag('input', '', attrib={ 'type': 'checkbox', 'class': 'btn btn-default', 'id': 'btn-filter-one', 'data-toggle': 'toggle', 'data-on': 'Single-item', 'data-off': 'Multi-item', 'checked': 'checked' }) with html_body.open('div', cls='btn-group filter-btns'): btn_cls = dict() btn_cls['data-type'] = 'record' btn_cls['class'] = 'btn btn-warning btn-filter' html_body.tag('a', 'Records', btn_cls) btn_cls['data-type'] = 'abstract-record' btn_cls['class'] = 'btn btn-success btn-filter' html_body.tag('a', 'Abstract records', btn_cls) btn_cls['data-type'] = 'selection' btn_cls['class'] = 'btn btn-info btn-filter' html_body.tag('a', 'Selections', btn_cls) with html_body.open('div', cls='row'): with html_body.open('a', id='top-link-block', title='Scroll to top', href='#input-reference', cls='well well-sm'): html_body.span(cls='glyphicon glyphicon-menu-up') html_body.add(html_content.current()) html_head = htmltree('head') html_head.tag('title', 'Flow123d input reference') html_head.style('css/main.css') html_head.style('css/bootstrap.min.css') html_head.style('css/bootstrap-toggle.min.css') html_head.style('css/katex.min.css') html_body.script('js/jquery-2.1.3.min.js') html_body.script('js/bootstrap.min.js') html_body.script('js/bootstrap-toggle.min.js') html_body.script('js/katex.min.js') html_body.script('js/main.js') html = htmltree('html') html.add(html_head.current()) html.add(html_body.current()) with open(output_file, 'w') as fp: fp.write(r'<!DOCTYPE html>') fp.write(html.dump())
def main(): """ Run main program """ parser = create_parser() options, args = parse_args(parser) # create instance of formatter from ist.ist_formatter_module import ISTFormatter formatter = ISTFormatter() # read input json file with open(options.input, 'r') as fp: json_data = json.load(fp) ist_info = { 'version': json_data['version']['flow123d_version'] if 'version' in json_data else 'Input reference' } json_data = json_data['ist_nodes'] if 'ist_nodes' in json_data else json_data # filter out unsupported types, they won't be formatted items = list() for json_item in json_data: input_type = json_item['input_type'] if 'input_type' in json_item else None if input_type in registered_nodes: item = registered_nodes[input_type]() item.parse(json_item) items.append(item) else: Logger.instance().info(' - item type not supported: %s' % str(item)) # if we have all items parsed we create references for item in items: if getattr(item, 'input_type', InputType.UNKNOWN) == InputType.MAIN_TYPE: if item.input_type == InputType.RECORD: for key in getattr(item, 'keys', []): if key.type.get_reference().input_type == InputType.ARRAY: key.type.get_reference().subtype.get_reference().add_ref(item) else: key.type.get_reference().add_ref(item) if item.input_type == InputType.ABSTRACT_RECORD: for imp in getattr(item, 'implementations', []): imp.get_reference().add_ref(item) # sort items by type and name items = sorted(items, key=lambda x: '{}{}'.format(x.input_type.value, x.name)) # convert to tex format if options.format.lower() in ('tex', 'latex'): Logger.instance().info('Formatting ist to tex format') from ist.utils.texlist2 import TexList TexList.PRETTY_FORMAT = options.debug formatter.json2latex(items, options.output, info=ist_info) if os.path.isfile(options.output): print('Ok: File "{:s}" created'.format(options.output)) sys.exit(0) else: print('Error: File "{:s}" does not exists'.format(options.output)) sys.exit(1) # convert to HTML format if options.format.lower() in ('html', 'html5', 'www', 'htm'): Logger.instance().info('Formatting ist to html format') formatter.json2html(items, options.output, info=ist_info) if os.path.isfile(options.output): print('Ok: File "{:s}" created'.format(options.output)) sys.exit(0) else: print('Error: File "{:s}" does not exists'.format(options.output)) sys.exit(1) if options.format.lower() in ('markdown', 'md'): Logger.instance().info('Testing markdown') text = ''' # Using markdown in description **Description field** supports markdown syntax (support is partial and some techniques may not work in Python markdown implementation). ## Links Link to record [[root]] selection [[DG_output_fields]] or abstract [[Transport]]. All links are in the same format. If `link_name` is specified in `attributes` (let say DG_output_fields has link_name of DG), we can use that [[DG]] Record and Selection types offer links to their keys/values, so you can write [[DG#porosity]], to specify link text use following syntax [[DG#porosity:poro]] or link to key in Root item [[root#flow123d_version]] Every name should be unique, if `link_name` is duplicate first occurrence will be used! To avoid conflict with `link_name` or `name` we can use type specification like this [[record#root]]. 3 types are registered: 1. type RECORD supporting prefixes: - r - record 2. type SELECTION supporting prefixes: - s - selection 3. type ABSTRACT supporting prefixes: - a - ar - abstract ## Basics We can write **bold** statements (or *italic* if needed). We can also ~~strkkethrg~~ strikethrough some text to express some change. Another usage can be in lists, we can write both unordered and ordered list. Important is to place one empty line before list starts. Unordered list: - important item - another important item Ordered list have same rules: 1. item number 1 2. and item number 2 To write code section with monospaced font, such as variable use `this` syntax. **Note** Use line breaks \\n chars sparely, and only break text-flow if necessarily. Full markdown specification can be found [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) but since Python is used to parse markdown, there may be slight differences. (($q_w$)) ''' o = htmltree() o.description(text) print(o.dump()) sys.exit(0) Logger.instance().error("Error: Unsupported format '{:s}'".format(options.format)) sys.exit(1)
def json2html(input_file, output_file, focus_element_id='root', skip_block_creation=[]): """ Method converts given input file to single html output file :param input_file: input json file :param output_file: output html file :param focus_element_id: id of element which will be visible, default root :param skip_block_creation: list of items which won't be created: [title, button-control, left-list, ist, right-list] :return: """ with open(input_file, 'r') as fp: json_object = json.load(fp, encoding="utf-8", cls=ProfilerJSONDecoder) html_content = HTMLFormatter.format(json_object) html_nav_abc = HTMLFormatter.abc_navigation_bar(json_object) html_nav_tree = HTMLFormatter.tree_navigation_bar(json_object) max_cols = 12 if 'right-list' not in skip_block_creation or 'left-list' not in skip_block_creation: max_cols -= 3 html_body = htmltree('body') generated = 'Generated {:s}'.format( datetime.datetime.today().strftime('%d-%m-%Y %X')) html_body.span(generated, id='info-generated') with html_body.open('div', '', cls='jumbotron', id='top'): with html_body.open('div', '', cls='container'): if 'title' not in skip_block_creation: with html_body.open('h1', 'Flow123d '): html_body.tag('small', 'input reference') if 'search' not in skip_block_creation: with html_body.open( 'div', cls= 'form-group has-default has-feedback search-wrapper' ): html_body.tag( 'span', cls= 'glyphicon glyphicon-search form-control-feedback') html_body.tag('input', type='text', cls='form-control', id='search', placeholder='type to search') with html_body.open('div', cls='row'): if 'right-list' not in skip_block_creation or 'left-list' not in skip_block_creation: with html_body.open('div', cls="col-md-3 tree-list"): with html_body.open('ul', cls="nav nav-tabs", role="tablist"): classes = ['', 'active'] if 'left-list' not in skip_block_creation: with html_body.open('li', cls=classes.pop(), role="presentation"): html_body.tag('a', 'Tree', attrib={ 'role': 'rab', 'aria-controls': 'tree-view', 'data-toggle': 'tab' }) if 'right-list' not in skip_block_creation: with html_body.open('li', role="presentation", cls=classes.pop()): html_body.tag( 'a', 'Abcd', attrib={ 'role': 'rab', 'aria-controls': 'abc-view', 'data-toggle': 'tab' }, ) with html_body.open('div', cls='tab-content'): classes = ['tab-pane', 'tab-pane active'] if 'left-list' not in skip_block_creation: with html_body.open('div', role='tabpanel', cls=classes.pop(), id='tree-view'): html_body.add(html_nav_tree.current()) if 'right-list' not in skip_block_creation: with html_body.open('div', role='tabpanel', cls=classes.pop(), id='abc-view'): html_body.add(html_nav_abc.current()) if 'ist' not in skip_block_creation: with html_body.open( 'div', cls='col-md-{:d} input-reference'.format( max_cols)): if 'button-control' not in skip_block_creation: with html_body.open('div', id='button-control', cls='row'): with html_body.open('div', cls='col-md-12'): with html_body.open( 'div', id='btn-filter-one-wrapper'): html_body.tag( 'input', '', attrib={ 'type': 'checkbox', 'class': 'btn btn-default', 'id': 'btn-filter-one', 'data-toggle': 'toggle', 'data-on': 'Single-item', 'data-off': 'Multi-item', 'checked': 'checked' }) with html_body.open( 'div', cls='btn-group filter-btns'): btn_cls = dict() btn_cls['data-type'] = 'record' btn_cls[ 'class'] = 'btn btn-warning btn-filter' html_body.tag( 'a', 'Records', btn_cls) btn_cls[ 'data-type'] = 'abstract-record' btn_cls[ 'class'] = 'btn btn-success btn-filter' html_body.tag( 'a', 'Abstract records', btn_cls) btn_cls['data-type'] = 'selection' btn_cls[ 'class'] = 'btn btn-info btn-filter' html_body.tag( 'a', 'Selections', btn_cls) with html_body.open('div', cls='row'): with html_body.open('a', id='top-link-block', title='Scroll to top', href='#input-reference', cls='well well-sm'): html_body.span( cls='glyphicon glyphicon-menu-up') html_body.add(html_content.current()) # show specified element by given id for child in html_body.current()._children[0]: if child.attrib['id'].lower( ) == focus_element_id.lower(): child.attrib['class'] = child.attrib[ 'class'].replace('hidden', '') html_head = htmltree('head') html_head.tag('title', 'Flow123d input reference') html_head.style('css/main.css') html_head.style('css/bootstrap.min.css') html_head.style('css/bootstrap-toggle.min.css') html_head.style('css/katex.min.css') html_body.script('js/jquery-2.1.3.min.js') html_body.script('js/bootstrap.min.js') html_body.script('js/bootstrap-toggle.min.js') html_body.script('js/katex.min.js') html_body.script('js/main.js') html = htmltree('html') html.add(html_head.current()) html.add(html_body.current()) with open(output_file, 'w') as fp: fp.write(r'<!DOCTYPE html>') fp.write(html.dump())
def json2html(items, output_file, focus_element_id='root', skip_block_creation=[], multi_mode=[False, False, True], info=None): """ Method converts given input file to single html output file :param items: list of parsed IST items :param output_file: output html file :param focus_element_id: id of element which will be visible, default root :param skip_block_creation: list of items which won't be created: [title, button-control, tree-list, ist, abcd-list] :return: """ FormatMode.format_mode = FormatMode.HTML_MODE multi_mode.reverse() html_content = HTMLFormatter.format(items) html_nav_abc = HTMLFormatter.abc_navigation_bar(items) html_nav_tree = HTMLFormatter.tree_navigation_bar(items) skip_block_creation.append('tree-list') # show specified element by given id for child in html_content.current(): if child.attrib['id'].lower() == focus_element_id.lower(): child.attrib['class'] = child.attrib['class'].replace('hidden', '') break max_cols = 12 if 'abcd-list' not in skip_block_creation or 'tree-list' not in skip_block_creation: max_cols -= 3 html_body = htmltree('body') generated = 'Generated {:s}'.format(datetime.datetime.today().strftime('%d-%m-%Y %X')) html_body.span(generated, id='info-generated') with html_body.open('div', '', cls='jumbotron', id='top'): with html_body.open('div', '', cls='container'): if 'title' not in skip_block_creation: with html_body.open('h1', 'Flow123d '): version = 'input reference' if not info else info['version'] if version.startswith('0.0.'): version = version.replace('0.0.', '') version = re.sub(r'_+', ' ', version) html_body.tag('small', version) if 'search' not in skip_block_creation: with html_body.open('div', cls='form-group has-default has-feedback search-wrapper'): html_body.tag('span', cls='glyphicon glyphicon-search form-control-feedback') html_body.tag('input', type='text', cls='form-control', id='search', placeholder='type to search') with html_body.open('div', cls='row'): if 'abcd-list' not in skip_block_creation or 'tree-list' not in skip_block_creation: with html_body.open('div', cls="col-md-3 tree-list"): with html_body.open('ul', cls="nav nav-tabs", role="tablist"): classes = ['', 'active'] if 'tree-list' not in skip_block_creation: with html_body.open('li', cls=classes.pop(), role="presentation"): html_body.tag('a', 'Tree', attrib={ 'role': 'rab', 'aria-controls': 'tree-view', 'data-toggle': 'tab' }) if 'abcd-list' not in skip_block_creation: with html_body.open('li', role="presentation", cls=classes.pop()): html_body.tag('a', 'Abc', attrib={ 'role': 'rab', 'aria-controls': 'abc-view', 'data-toggle': 'tab' }, ) with html_body.open('div', cls='tab-content'): classes = ['tab-pane', 'tab-pane active'] if 'tree-list' not in skip_block_creation: with html_body.open('div', role='tabpanel', cls=classes.pop(), id='tree-view'): html_body.add(html_nav_tree.current()) if 'abcd-list' not in skip_block_creation: with html_body.open('div', role='tabpanel', cls=classes.pop(), id='abc-view'): html_body.add(html_nav_abc.current()) if 'ist' not in skip_block_creation: with html_body.open('div', cls='col-md-{:d} input-reference'.format(max_cols)): if 'button-control' not in skip_block_creation: with html_body.open('div', id='button-control', cls='row'): with html_body.open('div', cls='col-md-12'): with html_body.open('div', id='btn-filter-one-wrapper'): single_filter = html_body.tag('input', '', attrib={ 'type': 'checkbox', 'class': 'btn btn-default', 'id': 'btn-filter-one', 'data-toggle': 'toggle', 'data-on': 'Single-item', 'data-off': 'Multi-item' }) if not max(multi_mode): single_filter.attrib['checked'] = 'checked' with html_body.open('div', cls='btn-group filter-btns'): btn_cls = dict() btn_cls['data-type'] = 'record' btn_cls['class'] = 'btn btn-warning btn-filter' btn_cls['class'] += ' active' if multi_mode.pop() else '' html_body.tag('a', 'Records', btn_cls.copy()) btn_cls['data-type'] = 'abstract-record' btn_cls['class'] = 'btn btn-success btn-filter' btn_cls['class'] += ' active' if multi_mode.pop() else '' html_body.tag('a', 'Abstract records', btn_cls.copy()) btn_cls['data-type'] = 'selection' btn_cls['class'] = 'btn btn-info btn-filter' btn_cls['class'] += ' active' if multi_mode.pop() else '' html_body.tag('a', 'Selections', btn_cls.copy()) with html_body.open('div', cls='row'): with html_body.open('a', id='top-link-block', title='Scroll to top', href='#top', cls='well well-sm'): html_body.span(cls='glyphicon glyphicon-menu-up') html_body.add(html_content.current()) html_head = htmltree('head') html_head.tag('title', 'Flow123d input reference') html_head.style('css/main.css') html_head.style('css/bootstrap.min.css') html_head.style('css/bootstrap-toggle.min.css') html_head.style('css/katex.min.css') html_body.script('js/jquery-2.1.3.min.js') html_body.script('js/bootstrap.min.js') html_body.script('js/bootstrap-toggle.min.js') html_body.script('js/katex.min.js') html_body.script('js/main.js') html = htmltree('html') html.add(html_head.current()) html.add(html_body.current()) # try: # Logger.instance().info('Trying module BeautifulSoup') # from BeautifulSoup import BeautifulSoup # # Logger.instance().info('Converting to html string') # html_string = html.dump() # Logger.instance().info('Parsing html string') # soup = BeautifulSoup(html_string) # Logger.instance().info('Prettifying html string') # html_pretty = soup.prettify() # # Logger.instance().info('Writing to file') # with open(output_file, 'w') as fp: # fp.write(r'<!DOCTYPE html>') # fp.write(html_pretty) # Logger.instance().info('File created') # except ImportError as e: # Logger.instance().warning('Import error', exc_info=e) Logger.instance().info('Using module ElementTree') import xml.etree.ElementTree as ET Logger.instance().info('Converting to html string') html_string = html.dump() Logger.instance().info('Writing to file') with open(output_file, 'w') as fp: fp.write(r'<!DOCTYPE html>') fp.write(ET.tostring(html.root, method='html')) Logger.instance().info('File created')
def main(): """ Run main program """ parser = create_parser() options, args = parse_args(parser) # create instance of formatter from ist.ist_formatter_module import ISTFormatter formatter = ISTFormatter() # read input json file with open(options.input, 'r') as fp: json_data = json.load(fp) ist_info = { 'version': json_data['version']['flow123d_version'] if 'version' in json_data else 'Input reference' } json_data = json_data[ 'ist_nodes'] if 'ist_nodes' in json_data else json_data # filter out unsupported types, they won't be formatted items = list() for json_item in json_data: input_type = json_item[ 'input_type'] if 'input_type' in json_item else None if input_type in registered_nodes: item = registered_nodes[input_type]() item.parse(json_item) items.append(item) else: Logger.instance().info(' - item type not supported: %s' % str(json_item)) # if we have all items parsed we create references for item in items: if getattr(item, 'input_type', InputType.UNKNOWN) == InputType.MAIN_TYPE: if item.input_type == InputType.RECORD: for key in getattr(item, 'keys', []): if key.type.get_reference().input_type == InputType.ARRAY: key.type.get_reference().subtype.get_reference( ).add_link(item) else: key.type.get_reference().get_generic_root().add_link( item) if item.input_type == InputType.ABSTRACT_RECORD: for imp in getattr(item, 'implementations', []): imp.get_reference().add_link(item) # disable sort for now (type and name) keep items order unchanged # items = sorted(items, key=lambda x: '{}{}'.format(x.input_type.value, x.name)) # convert to tex format if options.format.lower() in ('tex', 'latex'): Logger.instance().info('-' * 80) Logger.instance().info('Formatting ist to tex format') from ist.utils.texlist2 import TexList TexList.PRETTY_FORMAT = options.debug formatter.json2latex(items, options.output, info=ist_info) if os.path.isfile(options.output): print('Ok: File "{:s}" created'.format(options.output)) sys.exit(0) else: print('Error: File "{:s}" does not exists'.format(options.output)) sys.exit(1) # convert to HTML format if options.format.lower() in ('html', 'html5', 'www', 'htm'): Logger.instance().info('-' * 80) Logger.instance().info('Formatting ist to html format') formatter.json2html(items, options.output, info=ist_info) if os.path.isfile(options.output): print('Ok: File "{:s}" created'.format(options.output)) sys.exit(0) else: print('Error: File "{:s}" does not exists'.format(options.output)) sys.exit(1) if options.format.lower() in ('markdown', 'md'): Logger.instance().info('Testing markdown') text = ''' # Using markdown in description **Description field** supports markdown syntax (support is partial and some techniques may not work in Python markdown implementation). ## Links Link to record [[root]] selection [[DG_output_fields]] or abstract [[Transport]]. All links are in the same format. If `link_name` is specified in `attributes` (let say DG_output_fields has link_name of DG), we can use that [[DG]] Record and Selection types offer links to their keys/values, so you can write [[DG#porosity]], to specify link text use following syntax [[DG#porosity:poro]] or link to key in Root item [[root#flow123d_version]] Every name should be unique, if `link_name` is duplicate first occurrence will be used! To avoid conflict with `link_name` or `name` we can use type specification like this [[record#root]]. 3 types are registered: 1. type RECORD supporting prefixes: - r - record 2. type SELECTION supporting prefixes: - s - selection 3. type ABSTRACT supporting prefixes: - a - ar - abstract ## Basics We can write **bold** statements (or *italic* if needed). We can also ~~strkkethrg~~ strikethrough some text to express some change. Another usage can be in lists, we can write both unordered and ordered list. Important is to place one empty line before list starts. Unordered list: - important item - another important item Ordered list have same rules: 1. item number 1 2. and item number 2 To write code section with monospaced font, such as variable use `this` syntax. **Note** Use line breaks \\n chars sparely, and only break text-flow if necessarily. Full markdown specification can be found [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) but since Python is used to parse markdown, there may be slight differences. (($q_w$)) ''' o = htmltree() o.description(text) print(o.dump()) sys.exit(0) Logger.instance().error("Error: Unsupported format '{:s}'".format( options.format)) sys.exit(1)