예제 #1
0
 def __init__(self,markdown, directory, lang, is_translation):
     mdfile = open(markdown,'r')
     state = 'begin'
     self.file = markdown
     if is_translation:
         self.path = os.path.splitext(markdown[len(directory)+1: markdown.find('.markdown')].lower())[0] + '/'
     else:
         self.path = markdown[len(directory)+1: markdown.find('.markdown')].lower() + '/'
     self.date = ''
     self.title = ''
     self.summary = ''
     self.author = ''
     self.author_site = ''
     self.translator = ''
     self.translator_site = ''
     self.translated_from = ''
     self.body = ''
     self.type = 'markdown'
     self.lang = lang
     self.type = 'tutorial'
     self.modification_date = time.ctime(os.path.getmtime(markdown))
     self.translations = {}
     self.original = None
     self.original_newer = False
     for line in mdfile:
         #line = line.decode('utf-8','replace')
         if state=='begin' and stripFileLine(line).strip(' ') =='---':
             state='header'
             continue
         if state=='header' and line.find('date:')!=-1:
             self.date = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('title:')!=-1:
             self.title = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('summary:')!=-1:
             self.summary = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('author:')!=-1:
             self.author = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('author_site:')!=-1:
             self.author_site = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('translator:')!=-1:
             self.translator = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('translator_site:')!=-1:
             self.translator_site = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('translated_from:')!=-1:
             self.translated_from = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and line.find('type:')!=-1:
             self.type = stripFileLine(line[line.find(':')+1:]).strip(' ')
             continue
         if state=='header' and stripFileLine(line).strip(' ')=='---':
             return  
예제 #2
0
def process_latex_blocks_pdf(markdown):
    delim = "=+="
    start = markdown.find(delim)
    while (start >= 0):
        end = markdown.find(delim, start + 1)
        before = markdown[:start]
        within = markdown[start + 3:end]
        after = markdown[end + 3:]
        markdown = before + replace_latex_block(within) + after
        start = markdown.find(delim)

    return markdown
예제 #3
0
def process_add_blocks_pdf(markdown):
    delim = "=^="
    start = markdown.find(delim)
    while (start >= 0):
        end = markdown.find(delim, start + 1)
        before = markdown[:start]
        within = markdown[start + 3:end]
        after = markdown[end + 3:]
        markdown = before + after
        start = markdown.find(delim)

    return markdown
예제 #4
0
def process_chart_blocks(output_path, dir, markdown):
    delim = "=/="
    start = markdown.find(delim)
    while (start >= 0):
        end = markdown.find(delim, start + 1)
        before = markdown[:start]
        within = markdown[start + 3:end]
        after = markdown[end + 3:]
        markdown = before + \
            replace_chart_block(output_path, dir, within) + after
        start = markdown.find(delim)

    return markdown
예제 #5
0
def process_table_blocks_pdf(dir, markdown):
    delim = "=|="
    start = markdown.find(delim)
    while (start >= 0):
        end = markdown.find(delim, start + 1)
        before = markdown[:start]
        within = markdown[start + 3:end]
        after = markdown[end + 3:]
        markdown = before + \
            replace_table_block_pdf(dir, within) + after
        start = markdown.find(delim)

    return markdown
예제 #6
0
def process_chart_blocks_pdf(output_path, dir, markdown):
    global chart_count
    delim = "=/="
    start = markdown.find(delim)
    while (start >= 0):
        end = markdown.find(delim, start + 1)
        before = markdown[:start]
        within = markdown[start + 3:end]
        after = markdown[end + 3:]
        chart_html = replace_chart_block_pdf(output_path, dir, within)
        chart_template = env.get_template('chart-wrapper.jinja')
        html = chart_template.render(content=chart_html, units='us', key='n')

        chart_count += 1
        chart_file = os.path.join(OUTPUT_DIR, 'charts',
                                  f"chart{chart_count}.html")
        with io.open(chart_file, 'w', encoding='utf8') as f:
            f.write(html)

        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        browser = webdriver.Chrome(chrome_options=options)
        html_file = "file:///" + chart_file
        print(html_file)
        browser.get(html_file)

        img = browser.find_element_by_id('vue').screenshot_as_png
        browser.close()

        png_file = os.path.join(OUTPUT_DIR, 'charts',
                                f"chart{chart_count}.png")
        with open(png_file, 'wb') as out_file:
            out_file.write(img)

        markdown = before + \
            f"<img src='build/charts/chart{chart_count}.png'/>" + after
        start = markdown.find(delim)

    return markdown
예제 #7
0
 def __init__(self, markdown, directory, lang, is_translation):
     mdfile = open(markdown, 'r')
     state = 'begin'
     self.file = markdown
     if is_translation:
         self.path = os.path.splitext(
             markdown[len(directory) +
                      1:markdown.find('.markdown')].lower())[0] + '/'
     else:
         self.path = markdown[len(directory) +
                              1:markdown.find('.markdown')].lower() + '/'
     self.date = ''
     self.title = ''
     self.summary = ''
     self.author = ''
     self.author_site = ''
     self.translator = ''
     self.translator_site = ''
     self.translated_from = ''
     self.body = ''
     self.type = 'markdown'
     self.lang = lang
     self.type = 'tutorial'
     self.modification_date = time.ctime(os.path.getmtime(markdown))
     self.translations = {}
     self.original = None
     self.original_newer = False
     for line in mdfile:
         #line = line.decode('utf-8','replace')
         if state == 'begin' and stripFileLine(line).strip(' ') == '---':
             state = 'header'
             continue
         if state == 'header' and line.find('date:') != -1:
             self.date = stripFileLine(line[line.find(':') + 1:]).strip(' ')
             continue
         if state == 'header' and line.find('title:') != -1:
             self.title = stripFileLine(line[line.find(':') +
                                             1:]).strip(' ')
             continue
         if state == 'header' and line.find('summary:') != -1:
             self.summary = stripFileLine(line[line.find(':') +
                                               1:]).strip(' ')
             continue
         if state == 'header' and line.find('author:') != -1:
             self.author = stripFileLine(line[line.find(':') +
                                              1:]).strip(' ')
             continue
         if state == 'header' and line.find('author_site:') != -1:
             self.author_site = stripFileLine(line[line.find(':') +
                                                   1:]).strip(' ')
             continue
         if state == 'header' and line.find('translator:') != -1:
             self.translator = stripFileLine(line[line.find(':') +
                                                  1:]).strip(' ')
             continue
         if state == 'header' and line.find('translator_site:') != -1:
             self.translator_site = stripFileLine(line[line.find(':') +
                                                       1:]).strip(' ')
             continue
         if state == 'header' and line.find('translated_from:') != -1:
             self.translated_from = stripFileLine(line[line.find(':') +
                                                       1:]).strip(' ')
             continue
         if state == 'header' and line.find('type:') != -1:
             self.type = stripFileLine(line[line.find(':') + 1:]).strip(' ')
             continue
         if state == 'header' and stripFileLine(line).strip(' ') == '---':
             return