Exemple #1
0
    def output_item(self, el, full_name, full_link):
        tag_to_mark = {
            'const': '(const)',
            'function': '(function)',
            'constructor': '(function)',
            'destructor': '(function)',
            'class': '(class)',
            'enum': '(enum)',
            'variable': '(variable)',
            'typedef': '(typedef)',
            'specialization': '(class)',
            'overload': '(function)',
        }
        mark = ''
        if el.tag in tag_to_mark:
            mark = tag_to_mark[el.tag]

        res = u''
        res += '<tt><b>{0}</b></tt> [<span class="link">'.format(
            xml_escape(full_name))
        res += '<a href="http://en.cppreference.com/w/{0}">'.format(
            xml_escape(full_link))
        res += '{0}</a></span>] <span class="mark">{1}</span>\n'.format(
            full_link, mark)

        return res
Exemple #2
0
    def output_item(self, el, full_name, full_link):
        tag_to_mark = {
            'const': '(const)',
            'function': '(function)',
            'constructor': '(function)',
            'destructor': '(function)',
            'class': '(class)',
            'enum': '(enum)',
            'variable': '(variable)',
            'typedef': '(typedef)',
            'specialization': '(class)',
            'overload': '(function)',
        }
        mark = ''
        if el.tag in tag_to_mark:
            mark = tag_to_mark[el.tag]

        res = u''
        res += '<tt><b>{0}</b></tt> [<span class="link">'.format(
            xml_escape(full_name))
        res += '<a href="https://ja.cppreference.com/w/{0}">'.format(
            xml_escape(full_link))
        res += '{0}</a></span>] <span class="mark">{1}</span>\n'.format(
            full_link, mark)

        return res
def main():
    parser = argparse.ArgumentParser(prog='index2devhelp')
    parser.add_argument('book_base',
                        type=str,
                        help='url to the location of the book')
    parser.add_argument('chapters_path',
                        type=str,
                        help='path to the chapters file to include')
    parser.add_argument('book_title', type=str, help='the title of the book')
    parser.add_argument('book_name', type=str, help='the name of the package')
    parser.add_argument(
        'rel_link',
        type=str,
        help='the link relative to the root of the documentation')
    parser.add_argument('in_fn', type=str, help='the path of the source file')
    parser.add_argument('dest_fn',
                        type=str,
                        help='the path of the destination file')
    args = parser.parse_args()

    book_base = args.book_base
    chapters_fn = args.chapters_path
    book_title = args.book_title
    book_name = args.book_name
    rel_link = args.rel_link
    in_fn = args.in_fn
    dest_fn = args.dest_fn

    out_f = open(dest_fn, 'w', encoding='utf-8')

    out_f.write('<?xml version="1.0"?>\n' + '<book title="' +
                xml_escape(book_title) +
                '" xmlns="http://www.devhelp.net/book' + '" name="' +
                xml_escape(book_name) + '" base="' + xml_escape(book_base) +
                '" link="' + xml_escape(rel_link) +
                '" version="2" language="c++">\n')

    chapters_f = open(chapters_fn, encoding='utf-8')
    out_f.write(chapters_f.read() + '\n')
    out_f.write('<functions>')

    tr = Index2Devhelp(out_f)
    tr.transform_file(in_fn)

    out_f.write('''
  </functions>
</book>
''')
def print_map_item(out_f, curr_item):
    item_kind_to_attr = { ItemKind.NAMESPACE : 'namespace',
                          ItemKind.CLASS : 'class' }
    if curr_item.kind not in item_kind_to_attr:
        print('ERROR: only namespaces and classes can have members')
        return

    out_f.write('  <compound kind="' + item_kind_to_attr[curr_item.kind] + '">\n' +
                '    <name>' + xml_escape(curr_item.full_name) + '</name>\n' +
                '    <filename>' + xml_escape(curr_item.link) + '</filename>\n')
    print_members(out_f, curr_item)
    out_f.write('  </compound>\n')

    for item in curr_item.members.values():
        if item.kind in [ ItemKind.NAMESPACE, ItemKind.CLASS ]:
            print_map_item(out_f, item)
    def output_item(self, el, full_name, full_link):
        mark = ''
        if el.tag == 'const': mark = '(const)'
        elif el.tag == 'function': mark = '(function)'
        elif el.tag == 'constructor': mark = '(function)'
        elif el.tag == 'destructor': mark = '(function)'
        elif el.tag == 'class': mark = '(class)'
        elif el.tag == 'enum': mark = '(enum)'
        elif el.tag == 'typedef': mark = '(typedef)'
        elif el.tag == 'specialization': mark = '(class)'
        elif el.tag == 'overload': mark = '(function)'

        res = u''
        res += '<tt><b>' + xml_escape(full_name) + '</b></tt> [<span class="link">'
        res += '<a href="http://en.cppreference.com/w/' + xml_escape(full_link) + '">'
        res += full_link + '</a></span>] <span class="mark">' + mark + '</span>\n'
        return res
Exemple #6
0
def print_map_item(out_f, link_map, curr_item):
    item_kind_to_attr = {
        ItemKind.NAMESPACE: 'namespace',
        ItemKind.CLASS: 'class'
    }
    if curr_item.kind not in item_kind_to_attr:
        print('ERROR: only namespaces and classes can have members')
        return

    out_f.write('  <compound kind="' + item_kind_to_attr[curr_item.kind] +
                '">\n' + '    <name>' + xml_escape(curr_item.full_name) +
                '</name>\n' + '    <filename>' + xml_escape(curr_item.link) +
                '</filename>\n')
    print_members(out_f, link_map, curr_item)
    out_f.write('  </compound>\n')

    for item in sorted(curr_item.members.values()):
        if item.kind in [ItemKind.NAMESPACE, ItemKind.CLASS]:
            print_map_item(out_f, link_map, item)
Exemple #7
0
def print_members(out_f, link_map, curr_item):
    for item in sorted(curr_item.members.values()):
        if link_map:
            link = link_map.get_dest(item.link)
            if link is None and item.kind != ItemKind.NAMESPACE:
                print("WARN: " + item.full_name + " contains invalid link")
                link = '404'
        else:
            link = item.link

        if item.kind == ItemKind.VARIABLE:
            out_f.write('    <member kind="variable">\n' +
                        '      <type>T</type>\n' + '      <name>' +
                        xml_escape(item.name) + '</name>\n' +
                        '      <anchorfile>' + xml_escape(link) +
                        '</anchorfile>\n' + '      <anchor></anchor>\n' +
                        '      <arglist></arglist>\n' + '    </member>\n')
        elif item.kind == ItemKind.FUNCTION:
            out_f.write('    <member kind="function">\n' +
                        '      <type>T</type>\n' + '      <name>' +
                        xml_escape(item.name) + '</name>\n' +
                        '      <anchorfile>' + xml_escape(link) +
                        '</anchorfile>\n' + '      <anchor></anchor>\n' +
                        '      <arglist>(T... args)</arglist>\n' +
                        '    </member>\n')
        elif item.kind == ItemKind.CLASS:
            out_f.write('    <class kind="class">' +
                        xml_escape(item.full_name) + '</class>\n')
        elif item.kind == ItemKind.NAMESPACE:
            out_f.write('    <namespace>' + xml_escape(item.full_name) +
                        '</namespace>\n')
def print_members(out_f, curr_item):
    global link_map
    for item in curr_item.members.values():
        if link_map:
            link = link_map.get_dest(item.link)
            if link == None and item.kind != ItemKind.NAMESPACE:
                print("WARN: " + item.full_name + " contains invalid link")
                link = '404'
        else:
            link = item.link

        if item.kind == ItemKind.VARIABLE:
            out_f.write('    <member kind="variable">\n' +
                        '      <type>T</type>\n' +
                        '      <name>' + xml_escape(item.name) + '</name>\n' +
                        '      <anchorfile>' + xml_escape(link) + '</anchorfile>\n' +
                        '      <anchor></anchor>\n' +
                        '      <arglist></arglist>\n' +
                        '    </member>\n')
        elif item.kind == ItemKind.FUNCTION:
            out_f.write('    <member kind="function">\n' +
                        '      <type>T</type>\n' +
                        '      <name>' + xml_escape(item.name) + '</name>\n' +
                        '      <anchorfile>' + xml_escape(link) + '</anchorfile>\n' +
                        '      <anchor></anchor>\n' +
                        '      <arglist>(T... args)</arglist>\n' +
                        '    </member>\n')
        elif item.kind == ItemKind.CLASS:
            out_f.write('    <class kind="class">' + xml_escape(item.full_name) + '</class>\n')
        elif item.kind == ItemKind.NAMESPACE:
            out_f.write('    <namespace>' + xml_escape(item.full_name) + '</namespace>\n')
def print_map_item(out_f, curr_item):
    item_kind_to_attr = {ItemKind.NAMESPACE: "namespace", ItemKind.CLASS: "class"}
    if curr_item.kind not in item_kind_to_attr:
        print("ERROR: only namespaces and classes can have members")
        return

    out_f.write(
        '  <compound kind="'
        + item_kind_to_attr[curr_item.kind]
        + '">\n'
        + "    <name>"
        + xml_escape(curr_item.full_name)
        + "</name>\n"
        + "    <filename>"
        + xml_escape(curr_item.link)
        + "</filename>\n"
    )
    print_members(out_f, curr_item)
    out_f.write("  </compound>\n")

    for item in sorted(curr_item.members.values()):
        if item.kind in [ItemKind.NAMESPACE, ItemKind.CLASS]:
            print_map_item(out_f, item)
def rlink_fix(match):
    pre = match.group(1)
    target = match.group(2)
    post = match.group(3)

    target = xml_unescape(target)
    target = urllib.parse.unquote(target)
    for fn,new_fn in rename_map:
        target = target.replace(fn, new_fn)
    target = target.replace('../../upload.cppreference.com/mwiki/','../common/')
    target = target.replace('../mwiki/','../common/')
    target = re.sub('(\.php|\.css)\?.*', '\\1', target)
    target = urllib.parse.quote(target)
    target = xml_escape(target)
    return pre + target + post
def rlink_fix(match):
    pre = match.group(1)
    target = match.group(2)
    post = match.group(3)

    target = xml_unescape(target)
    target = urllib.parse.unquote(target)
    for fn,new_fn in rename_map:
        target = target.replace(fn, new_fn)
    target = target.replace('../../upload.cppreference.com/mwiki/','../common/')
    target = target.replace('../mwiki/','../common/')
    target = re.sub('(\.php|\.css)\?.*', '\\1', target)
    target = urllib.parse.quote(target)
    target = xml_escape(target)
    target = target.replace('%23', '#');
    return pre + target + post
 def process_item_hook(self, el, full_name, full_link):
     global out_f
     out_f.write('<keyword type="' + xml_escape(self.get_mark(el))
                 + '" name="' + xml_escape(full_name)
                 + '" link="' + xml_escape(full_link) + '"/>\n')
     IndexTransform.process_item_hook(self, el, full_name, full_link)
        elif el.tag == 'class': return 'class'
        elif el.tag == 'enum': return 'enum'
        elif el.tag == 'typedef': return 'typedef'
        elif el.tag == 'specialization': return 'class'
        elif el.tag == 'overload': return 'function'
        return ''

    def process_item_hook(self, el, full_name, full_link):
        global out_f
        out_f.write('<keyword type="' + xml_escape(self.get_mark(el))
                    + '" name="' + xml_escape(full_name)
                    + '" link="' + xml_escape(full_link) + '"/>\n')
        IndexTransform.process_item_hook(self, el, full_name, full_link)

out_f.write('<?xml version="1.0"?>\n'
           + '<book title="' + xml_escape(book_title)
           + '" xmlns="http://www.devhelp.net/book'
           + '" name="' + xml_escape(book_name)
           + '" base="' + xml_escape(book_base)
           + '" link="' + xml_escape(rel_link)
           + '" version="2" language="c++">\n')

chapters_f = open(chapters_fn)
out_f.write(chapters_f.read() + '\n')
out_f.write('<functions>')

tr = Index2Devhelp()
tr.transform(in_fn)

out_f.write('''
  </functions>
Exemple #14
0
 def process_item_hook(self, el, full_name, full_link):
     global out_f
     out_f.write('<keyword type="' + xml_escape(self.get_mark(el)) +
                 '" name="' + xml_escape(full_name) + '" link="' +
                 xml_escape(full_link) + '"/>\n')
     IndexTransform.process_item_hook(self, el, full_name, full_link)
Exemple #15
0
        elif el.tag == 'enum': return 'enum'
        elif el.tag == 'typedef': return 'typedef'
        elif el.tag == 'specialization': return 'class'
        elif el.tag == 'overload': return 'function'
        return ''

    def process_item_hook(self, el, full_name, full_link):
        global out_f
        out_f.write('<keyword type="' + xml_escape(self.get_mark(el)) +
                    '" name="' + xml_escape(full_name) + '" link="' +
                    xml_escape(full_link) + '"/>\n')
        IndexTransform.process_item_hook(self, el, full_name, full_link)


out_f.write('<?xml version="1.0"?>\n' + '<book title="' +
            xml_escape(book_title) + '" xmlns="http://www.devhelp.net/book' +
            '" name="' + xml_escape(book_name) + '" base="' +
            xml_escape(book_base) + '" link="' + xml_escape(rel_link) +
            '" version="2" language="c++">\n')

chapters_f = open(chapters_fn)
out_f.write(chapters_f.read() + '\n')
out_f.write('<functions>')

tr = Index2Devhelp()
tr.transform(in_fn)

out_f.write('''
  </functions>
</book>
''')
            return 'function'
            # devhelp does not support variables in its format
        elif el.tag == 'variable':
            return ''
        return ''

    def process_item_hook(self, el, full_name, full_link):
        global out_f
        out_f.write('<keyword type="' + xml_escape(self.get_mark(el)) +
                    '" name="' + xml_escape(full_name) + '" link="' +
                    xml_escape(full_link) + '"/>\n')
        IndexTransform.process_item_hook(self, el, full_name, full_link)


out_f.write('<?xml version="1.0"?>\n' + '<book title="' +
            xml_escape(book_title) + '" xmlns="http://www.devhelp.net/book' +
            '" name="' + xml_escape(book_name) + '" base="' +
            xml_escape(book_base) + '" link="' + xml_escape(rel_link) +
            '" version="2" language="c++">\n')

chapters_f = open(chapters_fn)
out_f.write(chapters_f.read() + '\n')
out_f.write('<functions>')

tr = Index2Devhelp()
tr.transform(in_fn)

out_f.write('''
  </functions>
</book>
''')