Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  mm-converter.py   Sprache: Python

 
#!/usr/bin/env python3

# set correct links (pandoc did not deal with github links properly)

import os
import re
import subprocess

regex_pdf_links1 = re.compile(r'`(.*)\`__'
                            re.M | re.X) # Multiline and Verbose
regex_md_links = re.compile(r'`(.*)\`__'
                            re.M | re.X) # Multiline and Verbose
regex_md_links2 = re.compile(r'`(.*)\n(.*)\`__'
                            re.M | re.X) # Multiline and Verbose
regex_pdf_links2 = re.compile(r'`(.*)\n\s+(.*)\`__'
                            re.M | re.X) # Multiline and Verbose

def remove_links_to_index2(data):
    # remove liks to the index, they are useless in py4web docs
    data = data
    print(re.search(regex_pdf_links2, data))
    return re.sub(regex_pdf_links2, 
                  r':download:`\1 \2`',
                  data)

def remove_links_to_index(data):
    # remove liks to the index, they are useless in py4web docs
    data = data
    print(re.search(regex_pdf_links1, data))
    return re.sub(regex_pdf_links1, 
                  r':download:`\1`',
                  data)

def rewrite_md_links(data):
    # remove liks to the index, they are useless in py4web docs
    data = data
    print(re.search(regex_md_links, data))
    data = re.sub(regex_md_links, 
                  r'`\1<\2.html>`__',
                  data)
    data = re.sub(regex_md_links2, 
                  r'`\1 \2<\3.html>`__',
                  data)
    return data


docs_on_pages = [
    'README.md',
    'quick_reference.md',
    'design_philosophy.md',
    'impl_details.md',
    'faq.md',
    'release_testing_process.md'
]

def convert2md(file):
    print(f" Working on file {file}")
    file = os.path.join('g3doc', file)
    data = open(file, 'r').read()
    write_files(file, data)
    
def write_files(file, data):
    for extension in ['rst']:
        ext_dir = os.getcwd()
        md_dir = os.path.join(os.getcwd(), 'g3doc')
        if not os.path.isdir(ext_dir):
            os.mkdir(ext_dir)
        ext_file = os.path.join(ext_dir , os.path.splitext(os.path.basename(file))[0] + "." + extension)
        md_file = os.path.join(md_dir , os.path.splitext(os.path.basename(file))[0] + ".md")
        print(f'writing {ext_file}')
        if os.path.exists(ext_file):
            os.unlink(ext_file)
        with open(ext_file, 'w'as handler:
            write_format(extension, ext_file, handler, md_file, data)


def write_format(extension, ext_file, handler, md_file, data):
    if extension =='md':
            handler.write(data)
    elif extension =='rst':
        try:
            subprocess.call(['pandoc''-s', md_file, '-f''markdown''-t''rst''-o', ext_file])
            data = open(ext_file, 'r').read() 
            data = remove_links_to_index(data)
            data = remove_links_to_index2(data)
            data = rewrite_md_links(data)
            handler.write(data)
            # Open a file for writing
            # with open('tmp.txt', 'w') as f:
                # Call the subprocess and redirect the output to the file
                # subprocess.call(['awk', '{ gsub(/<g3doc\//, "<"); print }', ext_file], stdout=f)
                # os.system('mv tmp.txt ' + ext_file)
 
        except FileNotFoundError:
            print("\n **** ERROR ****: you need the Pandoc module installed!")
            exit(0)
    elif extension =='html':
        try:
            subprocess.call(['pandoc''-s', md_file, '-f''markdown''-t''html''-o', ext_file,  '--highlight-style=kate'])
        except FileNotFoundError:
            print("\n **** ERROR ****: you need the Pandoc module installed!")
            exit(0)


if __name__ == "__main__":
    for doc in docs_on_pages:
        print(doc)
        convert2md(doc)

Messung V0.5
C=88 H=87 G=87

¤ Dauer der Verarbeitung: 0.9 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge