Beispiel #1
0
def main():
    # sys.tracebacklimit = 0 # Disable traceback messages
    par = argparse.ArgumentParser(
        description="Batch-convert Markdown and HTML files.",
        formatter_class=argparse.RawTextHelpFormatter)
    par.add_argument("-v",
                     "--version",
                     action="version",
                     version=f"%(prog)s {__version__}")
    par.add_argument(
        "input",
        type=str,
        help=
        "provide a filepath to a file or a folder with files that you want to convert"
    )
    par.add_argument("convert",
                     type=str,
                     help="""set the conversion type:
    * md_dita - convert Markdown to DITA
    * html_dita - convert HTML to DITA
    * md_html - convert Markdown to HTML
    * html_md - convert HTML to Markdown""")
    par.add_argument(
        "-out",
        "--output",
        metavar="folder_path",
        default="",
        help=
        "manually specify the output folder (defaults to the input DITA file folder)"
    )
    args = par.parse_args()

    source = Source(args.input, args.convert, args.output)
    Source.output_files = source.convert()
Beispiel #2
0
    def test_log_creation(self):

        source = Source(html_a_filepath, "html_dita")

        with mock.patch('builtins.input', return_value="y"):
            output_filepath = source.convert()[0]

        self.assertTrue(os.path.isfile("MarkUP.log"))
        os.remove("MarkUP.log")
Beispiel #3
0
    def test_html_to_dita(self):
        try:
            shutil.rmtree(output_dir)
        except:
            pass

        source = Source(html_a_filepath, "html_dita", output_dir)
        with mock.patch('builtins.input', return_value="y"):
            output_filepath = source.convert()[0]
        self.assertTrue(os.path.isfile(output_filepath))
Beispiel #4
0
    def test_html_to_md(self):
        try:
            os.remove(html_a_filepath.replace(".html", ".md"))
        except:
            pass

        source = Source(html_a_filepath, "html_md")
        with mock.patch('builtins.input', return_value="y"):
            output_filepath = source.convert()[0]
        self.assertTrue(os.path.isfile(output_filepath))
        self.assertEqual(output_filepath, html_a_md_filepath)
Beispiel #5
0
    def test_md_to_dita(self):
        try:
            os.remove(md_a_filepath.replace(".md", ".dita"))
        except:
            pass

        source = Source(md_a_filepath, "md_dita")
        with mock.patch('builtins.input', return_value="y"):
            output_filepath = source.convert()[0]
        self.assertTrue(os.path.isfile(output_filepath))
        self.assertEqual(output_filepath, md_a_dita_filepath)
Beispiel #6
0
    def test_html_to_md(self):

        output_files = files_list(output_dir, "md")
        for i in output_files:
            os.remove(i)

        source = Source(html_dir, "html_md", output_dir)
        with mock.patch('builtins.input', return_value="a"):
            output_filepath = source.convert()

        for i in output_filepath:
            self.assertTrue(os.path.isfile(i))
Beispiel #7
0
    def test_md_to_dita(self):

        output_files = files_list(md_dir, "dita")
        for i in output_files:
            os.remove(i)

        source = Source(md_dir, "md_dita")
        with mock.patch('builtins.input', return_value="a"):
            output_filepath = source.convert()

        for i in output_filepath:
            self.assertTrue(os.path.isfile(i))
Beispiel #8
0
    def test_abort(self):
        source = Source(html_dir, "html_dita", output_dir)

        with mock.patch('builtins.input', return_value=""):
            output_filepath = source.convert()
        self.assertEqual(output_filepath, [])

        with mock.patch('builtins.input', return_value="Aa"):
            output_filepath = source.convert()
        self.assertEqual(output_filepath, [])

        with mock.patch('builtins.input', return_value="na"):
            output_filepath = source.convert()
        self.assertEqual(output_filepath, [])

        with mock.patch('builtins.input', return_value="na"):
            output_filepath = source.convert()
        self.assertEqual(output_filepath, [])