def test_load_config_local_and_style(): """ Test `load_config()` with local and style configuration files. Local file should always override style, which should override template. """ with TemporaryDirectory() as tmpdir: tmpdir = Path(tmpdir) # Change home directory for testing os.environ['MARKDOWNREVEAL_HOME'] = str(tmpdir) # Create local configuration file config_file = tmpdir / 'config.yaml' config_file.write_text('footer: "local footer"') # Create style configuration file style_path = tmpdir / '.markdownreveal' / 'out' / 'markdownrevealstyle' style_path.mkdir(parents=True) config_file = style_path / 'config.yaml' config_file.write_text('footer: "style footer"\n' 'header: "style header"') # Load configuration old = Path.cwd() os.chdir(str(tmpdir)) config = load_config() os.chdir(str(old)) assert config['local_path'] == tmpdir / '.markdownreveal' assert config['output_path'] == config['local_path'] / 'out' assert config['footer'] == 'local footer' assert config['header'] == 'style header' assert 'markdownreveal/style-default' in config['style']
def test_markdown_to_reveal_emoji_codes(): """ Emoji codes. """ text = ':smile:' config = load_config() # Emoji codes config['emoji_codes'] = True html = markdown_to_reveal(text=text, config=config) assert '😄' in html assert text not in html # No emoji codes config['emoji_codes'] = False html = markdown_to_reveal(text=text, config=config) assert '😄' not in html assert text in html
def test_load_config_default(): """ Test `load_config()` with default configuration template. """ with TemporaryDirectory() as tmpdir: tmpdir = Path(tmpdir) # Change home directory for testing os.environ['MARKDOWNREVEAL_HOME'] = str(tmpdir) # Load configuration config = load_config() assert config['local_path'] == tmpdir / '.markdownreveal' assert config['output_path'] == config['local_path'] / 'out' assert config['footer'] == '' assert config['header'] == '' assert 'markdownreveal/style-default' in config['style']
def test_markdown_to_reveal_katex(): """ Katex math rendering. """ text = '$$ a^2 = \sqrt{b^2 + c^2} $$' config = load_config() # Katex rendering config['katex'] = True html = markdown_to_reveal(text=text, config=config) assert 'katex/katex.min.js' in html assert text not in html assert text.split('$$')[1].strip() in html # No Katex rendering config['katex'] = False html = markdown_to_reveal(text=text, config=config) assert 'katex/katex.min.js' not in html assert text in html
def test_markdown_to_reveal(): """ Test `markdown_to_reveal()` function. """ text = '''% Title % Author % Date # Section ## Subsection Once upon a time... - there were - some small worms ''' config = load_config() html = markdown_to_reveal(text=text, config=config) assert '<h1 class="title">Title</h1>' in html assert '<p>Once upon a time...</p>' in html assert '<li>there were</li>' in html
def test_load_config_local(): """ Test `load_config()` with local configuration file. """ with TemporaryDirectory() as tmpdir: tmpdir = Path(tmpdir) # Change home directory for testing os.environ['MARKDOWNREVEAL_HOME'] = str(tmpdir) # Create local configuration file config_file = tmpdir / 'config.yaml' config_file.write_text('footer: "local footer"\n' 'header: "local header"\n' 'style: "https://other/style/file.tar.gz"') # Load configuration old = Path.cwd() os.chdir(str(tmpdir)) config = load_config() os.chdir(str(old)) assert config['local_path'] == tmpdir / '.markdownreveal' assert config['output_path'] == config['local_path'] / 'out' assert config['footer'] == 'local footer' assert config['header'] == 'local header' assert 'other/style' in config['style']