From 260e107f84a4724b185478aa36c8d0ee05095ecf Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sun, 14 Feb 2021 13:06:37 -0600 Subject: [PATCH] Fix live code highlighting; add tests --- src/js/notes.js | 4 ++++ src/python/notes_test.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/js/notes.js b/src/js/notes.js index 5db8ca7..ae4e0df 100644 --- a/src/js/notes.js +++ b/src/js/notes.js @@ -112,6 +112,10 @@ function retagContent() { window.MathJax.typeset(); } + // Reapply syntax highlight + hljs.initHighlighting.called = false; + hljs.initHighlighting(); + // Re-render Mermaid diagrams mermaid.init(); } diff --git a/src/python/notes_test.py b/src/python/notes_test.py index cc4ed90..a5ce9bd 100644 --- a/src/python/notes_test.py +++ b/src/python/notes_test.py @@ -91,3 +91,23 @@ def test_upload(browser): # Should create a link browser.find_element_by_link_text("readme.txt") + + +def test_code_highlight(browser): + browser.get(INDEX_URL) + assert_no_javascript_errors(browser) + + # Type some source code + user_input = browser.find_element_by_id("userInput") + user_input.clear() + user_input.send_keys( + "```python\n" + "def hello_world():\n" + " print('Hello')\n" + "```\n" + ) + sleep(1) + assert_no_javascript_errors(browser) + + # Should create highlighted elements + browser.find_element_by_css_selector(".hljs-title")