mirror of
https://github.com/shouptech/synthale.git
synced 2026-02-03 15:39:45 +00:00
Add setext heading
This commit is contained in:
parent
f71a2044d2
commit
843849e81a
4 changed files with 40 additions and 3 deletions
19
src/synthale/markdown.py
Normal file
19
src/synthale/markdown.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
"""This module contains functions to generate markdown elements."""
|
||||
|
||||
|
||||
def setext_heading(text, level):
|
||||
"""Return an setext heading.
|
||||
|
||||
`text` is the text to include in the heading. Leading and trailing
|
||||
whitespace is trimmed from `text`. If `level` is the number `1`, a first
|
||||
level (h1) heading is returned. If `level` is the number `2` (or anything
|
||||
else), a second level (h2) heading is returned.
|
||||
|
||||
See https://github.github.com/gfm/#setext-heading for more information.
|
||||
"""
|
||||
if level == 1:
|
||||
hchar = '='
|
||||
else:
|
||||
hchar = '-'
|
||||
|
||||
return '{}\n{}'.format(text.strip(), hchar * len(text.strip()))
|
||||
|
|
@ -6,6 +6,8 @@ import sys
|
|||
|
||||
import pybeerxml
|
||||
|
||||
from synthale import markdown
|
||||
|
||||
|
||||
class MarkdownRecipe:
|
||||
"""A recipe in markdown form."""
|
||||
|
|
@ -36,7 +38,7 @@ class MarkdownRecipe:
|
|||
@property
|
||||
def markdown(self):
|
||||
"""Return generated markdown for the recipe."""
|
||||
return ''
|
||||
return markdown.setext_heading(self.recipe.name, 1)
|
||||
|
||||
|
||||
def load_file(path):
|
||||
|
|
|
|||
14
tests/test_markdown.py
Normal file
14
tests/test_markdown.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
"""Contains tests for the synthale.markdown module."""
|
||||
import pytest
|
||||
|
||||
from synthale import markdown
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text,level,expected', [
|
||||
('test', 1, 'test\n===='),
|
||||
('foobar', 2, 'foobar\n------'),
|
||||
(' test ', None, 'test\n----')
|
||||
])
|
||||
def test_setext_heading(text, level, expected):
|
||||
"""Test for valid setext headings from setext_heading function."""
|
||||
assert markdown.setext_heading(text, level) == expected
|
||||
|
|
@ -36,5 +36,7 @@ def test_markdown_recipe_filename():
|
|||
|
||||
def test_markdown_recipe_markdown():
|
||||
"""Validate the generated markdown."""
|
||||
recipe = MarkdownRecipe(None)
|
||||
assert recipe.markdown == ''
|
||||
xml_recipe = pybeerxml.Recipe()
|
||||
xml_recipe.name = 'Foobar'
|
||||
recipe = MarkdownRecipe(xml_recipe)
|
||||
assert recipe.markdown == 'Foobar\n======'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue