コード例 #1
0
def main(tn_class, extra_resources=None):
    if extra_resources:
        resource_names = extra_resources + list(
            set(DEFAULT_RESOURCES) - set(extra_resources))
    else:
        resource_names = DEFAULT_RESOURCES
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('--ust-id',
                        dest='ust_id',
                        default=DEFAULT_UST_ID,
                        required=False,
                        help="UST ID")
    parser.add_argument('--ult-id',
                        dest='ult_id',
                        default=DEFAULT_ULT_ID,
                        required=False,
                        help="ULT ID")
    run_converter(resource_names,
                  tn_class,
                  project_ids_map={
                      '': BOOK_NUMBERS.keys(),
                      'all': BOOK_NUMBERS.keys()
                  },
                  parser=parser,
                  extra_resource_ids=['ult_id', 'ust_id'])
def main(tn_class, resource_names=None):
    if not resource_names:
        resource_names = ['tn', 'ult', 'ust', 'ta', 'tw', 'ugnt', 'uhb']
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('--ust-id',
                        dest='ust_id',
                        default=DEFAULT_UST_ID,
                        required=False,
                        help="UST ID")
    parser.add_argument('--ult-id',
                        dest='ult_id',
                        default=DEFAULT_ULT_ID,
                        required=False,
                        help="ULT ID")
    run_converter(resource_names,
                  tn_class,
                  project_ids_map={
                      '': BOOK_NUMBERS.keys(),
                      'all': BOOK_NUMBERS.keys()
                  },
                  parser=parser)
コード例 #3
0
    def fix_links(self, html):
        # Changes references to chapter/frame in links
        # <a href="1/10">Text</a> => <a href="rc://obs-sn/help/obs/01/10">Text</a>
        # <a href="10-1">Text</a> => <a href="rc://obs-sn/help/obs/10/01">Text</a>
        html = re.sub(r'href="(\d)/(\d+)"', r'href="0\1/\2"',
                      html)  # prefix 0 on single-digit chapters
        html = re.sub(r'href="(\d+)/(\d)"', r'href="\1/0\2"',
                      html)  # prefix 0 on single-digit frames
        html = re.sub(r'href="(\d\d)/(\d\d)"',
                      fr'href="rc://{self.lang_code}/obs/book/obs/\1/\2"',
                      html)

        # Changes references to chapter/frame that are just chapter/frame prefixed with a #
        # #1:10 => <a href="rc://en/obs/book/obs/01/10">01:10</a>
        # #10/1 => <a href="rc://en/obs/book/obs/10/01">10:01</a>
        # #10/12 => <a href="rc://en/obs/book/obs/10/12">10:12</a>
        html = re.sub(r'#(\d)[:/-](\d+)', r'#0\1-\2',
                      html)  # prefix 0 on single-digit chapters
        html = re.sub(r'#(\d+)[:/-](\d)\b', r'#\1-0\2',
                      html)  # prefix 0 on single-digit frames
        html = re.sub(
            r'#(\d\d)[:/-](\d\d)',
            rf'<a href="rc://{self.lang_code}/obs/book/obs/\1/\2">\1:\2</a>',
            html)

        return html


if __name__ == '__main__':
    run_converter(['obs-sn', 'obs-sq', 'obs'], ObsSnSqPdfConverter)
コード例 #4
0
                tq_html += f'''
    <section id="{self.lang_code}-{self.name}-{project_id}-{self.pad(chapter)}" class="tq-chapter">
        <h3 class="section-header{' no-toc' if len(projects) > 1 else ''}">{book_title} {chapter}</h3>
'''
                verse_files = sorted(glob(os.path.join(chapter_dir, '*.md')))
                for verse_file in verse_files:
                    verse = os.path.splitext(os.path.basename(verse_file))[0].lstrip('0')
                    tq_article = markdown2.markdown_path(verse_file)
                    tq_article = increment_headers(tq_article, 3)
                    tq_title = f'{book_title} {chapter}:{verse}'
                    tq_rc_link = f'rc://{self.lang_code}/tq/help/{project_id}/{self.pad(chapter, project_id)}/{verse.zfill(3)}'
                    tq_rc = self.add_rc(tq_rc_link, tq_article, tq_title)
                    tq_html += f'''
        <article id="{tq_rc.article_id}" class="tq-verse">
            <h3>{tq_rc.title}</h3>
            {tq_article}
        </article>
'''
                tq_html += '''
    </section>
'''
            tq_html += '''
</section>
'''
        self.logger.info('Done generating TQ HTML.')
        return tq_html


if __name__ == '__main__':
    run_converter(['tq'], TqPdfConverter, project_ids_map={'': BOOK_NUMBERS.keys(), 'all': [None]})
コード例 #5
0
                    'https://git.door43.org/api/v1/repos/unfoldingword/en_obs/raw/content/front/intro.md'
                ))
        license_html = f'''
<article id="front" class="no-footer">
  {front_html}
  <p>
</article>
'''
        return license_html

    def get_contributors_html(self):
        back_path = os.path.join(self.main_resource.repo_dir, 'content',
                                 'back', 'intro.md')
        if os.path.exists(back_path):
            back_html = markdown2.markdown_path(back_path)
        else:
            back_html = markdown2.markdown(
                get_url(
                    'https://git.door43.org/api/v1/repos/unfoldingword/en_obs/raw/content/back/intro.md'
                ))
        back_html = f'''
<article id="back" class="obs-page">
  {back_html}
</article>
'''
        return back_html


if __name__ == '__main__':
    run_converter(['obs'], ObsPdfConverter)
コード例 #6
0
    def fix_links(self, html):
        # Changes references to chapter/frame in links
        # <a href="1/10">Text</a> => <a href="rc://obs-sn/help/obs/01/10">Text</a>
        # <a href="10-1">Text</a> => <a href="rc://obs-sn/help/obs/10/01">Text</a>
        html = re.sub(r'href="(\d)/(\d+)"', r'href="0\1/\2"',
                      html)  # prefix 0 on single-digit chapters
        html = re.sub(r'href="(\d+)/(\d)"', r'href="\1/0\2"',
                      html)  # prefix 0 on single-digit frames
        html = re.sub(r'href="(\d\d)/(\d\d)"',
                      fr'href="rc://{self.lang_code}/obs-tn/help/\1/\2"', html)

        # Changes references to chapter/frame that are just chapter/frame prefixed with a #
        # #1:10 => <a href="rc://en/obs/book/obs/01/10">01:10</a>
        # #10/1 => <a href="rc://en/obs/book/obs/10/01">10:01</a>
        # #10/12 => <a href="rc://en/obs/book/obs/10/12">10:12</a>
        html = re.sub(r'#(\d)[:/-](\d+)', r'#0\1-\2',
                      html)  # prefix 0 on single-digit chapters
        html = re.sub(r'#(\d+)[:/-](\d)\b', r'#\1-0\2',
                      html)  # prefix 0 on single-digit frames
        html = re.sub(
            r'#(\d\d)[:/-](\d\d)',
            rf'<a href="rc://{self.lang_code}/obs-tn/help/\1/\2">\1:\2</a>',
            html)

        return html


if __name__ == '__main__':
    run_converter(['obs-tn', 'obs', 'ta', 'tw'], ObsTnPdfConverter)