From 11f4a6a429dc836cca7752feb6556e3dc69ed1be Mon Sep 17 00:00:00 2001 From: ba067604 Date: Mon, 9 Jan 2023 19:21:02 +0100 Subject: [PATCH 1/4] Update lxml --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9d690da..bf9a0b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ pypandoc==1.4 -lxml==4.5.0 \ No newline at end of file +lxml==4.8.0 \ No newline at end of file From e23d66716d417aac01393fc1a4ba1de0220cebb2 Mon Sep 17 00:00:00 2001 From: ba067604 Date: Mon, 9 Jan 2023 19:33:37 +0100 Subject: [PATCH 2/4] Add pyyaml dependency --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bf9a0b3..c0165bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pypandoc==1.4 -lxml==4.8.0 \ No newline at end of file +lxml==4.8.0 +pyyaml==6.0 \ No newline at end of file From f0689888d41fd7e138a2b3487c73f7e72548e0c8 Mon Sep 17 00:00:00 2001 From: Florian Knoch Date: Tue, 10 Jan 2023 13:57:55 +0100 Subject: [PATCH 3/4] Fix encoding issues --- cache.py | 8 ++++---- chapters.py | 4 ++-- helper.py | 4 ++-- main.py | 4 ++-- slides.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cache.py b/cache.py index 950bec9..fa92ca0 100644 --- a/cache.py +++ b/cache.py @@ -47,12 +47,12 @@ def not_cached_before(root, lang, file): # Restore the cached chapter. def get_cached_chapter(root, lang, chapter): chapter_path = os.path.join(root, '.onpoint', lang, chapter + '.cache') - return open(chapter_path, 'r').read() + return open(chapter_path, 'r', encoding='utf8').read() # Store a cached version of a chapter. def store_cached_chapter(root, lang, chapter, content): chapter_path = os.path.join(root, '.onpoint', lang, chapter + '.cache') - chapter_file = open(chapter_path, 'w') + chapter_file = open(chapter_path, 'w', encoding='utf-8') chapter_file.write(content) chapter_file.close() @@ -66,12 +66,12 @@ def __init_cache_directory(root, lang): # Save the current time to the timestamp file. def save_compile_timestamp(root, lang, file_name=timestamp_file_name): timestamp_file_path = os.path.join(root, '.onpoint', lang, file_name) - timestamp_file = open(timestamp_file_path, 'w') + timestamp_file = open(timestamp_file_path, 'w', encoding='utf-8') timestamp_file.write(str(int(time.time()))) timestamp_file.close() # Retrieve the compile timestamp. def __get_last_compile_time(root, lang): timestamp_file_path = os.path.join(root, '.onpoint', lang, timestamp_file_name) - with open(timestamp_file_path) as f: + with open(timestamp_file_path, encoding='utf8') as f: return int(f.readline()) diff --git a/chapters.py b/chapters.py index f02f27e..4afed56 100644 --- a/chapters.py +++ b/chapters.py @@ -21,7 +21,7 @@ def compile_chapters(root_directory, language, force_recompile=False): chapters = "" for chapter in structure: - chapters += '
\n' + compile_chapter(chapter, no_cache) + '\n
' + chapters += '
' + os.linesep + compile_chapter(chapter, no_cache) + os.linesep + '
' cache.save_compile_timestamp(root, lang) return chapters # string @@ -47,7 +47,7 @@ def compile_chapter(chapter, no_cache): return cache.get_cached_chapter(root, lang, chapter) print("Recompiling chapter " + chapter + " (" + lang + ").") - chapter_file = open(chapter_path, 'r') + chapter_file = open(chapter_path, 'r', encoding='utf-8') delimiter = '\n@slide' chapter_input = ('\n' + chapter_file.read()).split(delimiter) slides = [delimiter + slide for slide in chapter_input][1:] diff --git a/helper.py b/helper.py index bf70e20..f0db7bf 100644 --- a/helper.py +++ b/helper.py @@ -6,7 +6,7 @@ import re # Calls a YAML parser for the given relative path inside the presentation root # directory. Returns a dictionary with the YAML content. def read_yaml(root, path): - with open(os.path.join(root, path), 'r') as stream: + with open(os.path.join(root, path), 'r', encoding='utf8') as stream: try: return yaml.safe_load(stream) except yaml.YAMLError as exc: @@ -47,7 +47,7 @@ def add_lazyload(source, lazyload_images): # per presentation. def add_help_menu(source, root): help_menu_code = open(os.path.join( - root, 'onpoint/help-menu.html'), "r").read() + root, 'onpoint/help-menu.html'), 'r', encoding='utf8').read() help_menu_code = re.sub('@imprint', read_yaml(root, 'legal.yml')['imprint'], help_menu_code) help_menu_code = re.sub('@privacy-policy', read_yaml(root, 'legal.yml')['privacy-policy'], help_menu_code) return re.sub('@help', help_menu_code, source) diff --git a/main.py b/main.py index 5b2389c..5524c04 100755 --- a/main.py +++ b/main.py @@ -13,14 +13,14 @@ import helper def compile(root, language='en', force_recompile=False, lazyload_images=False): - wrapper = open(os.path.join(root, 'layouts/root.html'), 'r').read() + wrapper = open(os.path.join(root, 'layouts/root.html'), 'r', encoding='utf8').read() compiled_chapters = chapters.compile_chapters(root, language, force_recompile) wrapper = wrapper.replace('@slides', compiled_chapters) wrapper = helper.insert_metadata(wrapper, root, language) wrapper = fragments.defragmentize(wrapper) wrapper = helper.add_lazyload(wrapper, lazyload_images) wrapper = helper.add_help_menu(wrapper, root) - with open(os.path.join(root, 'slides.' + language + '.html'), 'w+') as output: + with open(os.path.join(root, 'slides.' + language + '.html'), 'w+', encoding='utf8') as output: output.write(wrapper) print('done') diff --git a/slides.py b/slides.py index b031cf7..c735e89 100644 --- a/slides.py +++ b/slides.py @@ -53,7 +53,7 @@ def get_slide_data(slide): def get_slide_layout(layout_name): global root try: - return open(os.path.join(root, 'layouts/' + layout_name + '.html'), 'r').read() + return open(os.path.join(root, 'layouts/' + layout_name + '.html'), 'r', encoding='utf8').read() except FileNotFoundError: raise Exception('Layout ' + layout_name + ' not found!') From eb0aec2cd3f7e9d863e62db5379c7d3f6bc6a213 Mon Sep 17 00:00:00 2001 From: Florian Knoch Date: Tue, 10 Jan 2023 15:29:05 +0100 Subject: [PATCH 4/4] Make inline slide components work again --- fragments.py | 3 ++- slides.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/fragments.py b/fragments.py index f9b49e8..89e90ed 100644 --- a/fragments.py +++ b/fragments.py @@ -14,6 +14,7 @@ FRAGMENT_CLASS = "fragment" def defragmentize(html): dom = etree.fromstring(html) + query = "|".join([ # FRAGMENT_TAG between two spaces "//*[contains(text(), ' %s ')]" % FRAGMENT_TAG, @@ -33,7 +34,7 @@ def defragmentize(html): fragment.set('class', class_list) fragment.text = re.sub(r"\s*%s\s*" % - re.escape(FRAGMENT_TAG), '', fragment.text) + re.escape(FRAGMENT_TAG), '', fragment.text) return etree.tostring(dom, method='html', encoding='utf-8', pretty_print=True).decode('utf-8') diff --git a/slides.py b/slides.py index c735e89..f54cad8 100644 --- a/slides.py +++ b/slides.py @@ -14,17 +14,27 @@ def compile_slide(slide, root_directory): slide_metadata = get_slide_metadata(slide) slide_data = get_slide_data(slide) slide = get_slide_layout(slide_metadata['layout']) + if 'todo' in slide_data.keys(): # TODO: Move the css into a global onpoint.css file slide = '' + slide + for key, value in slide_data.items(): placeholder = '@' + key filler = convert_slide_content(value) - # print('replace', placeholder, 'with', filler) - if '@' + key in slide: + + # very unelegant attempt at inline elements + inline_key = '@' + key + '(inline)' + if inline_key in slide: + slide = slide.replace( + inline_key, + re.sub(r"

(.+)

", r"\1", filler) + ) + + elif '@' + key in slide: slide = slide.replace(placeholder, filler) - # very unelegant attempt at inline elements - slide = re.sub(r"

(.+?)

\n\(inline\)", r"\1", slide) + + return slide # Parses the metadata passage of a given slide and returns the metadata as a