mirror of https://gitlab.com/bashrc2/epicyon
Ensure that specification example numbers are sequential
parent
9bbba10e33
commit
0331311dd0
24
markdown.py
24
markdown.py
|
@ -312,6 +312,30 @@ def _markdown_replace_code(markdown: str) -> str:
|
|||
return markdown
|
||||
|
||||
|
||||
def markdown_example_numbers(markdown: str) -> str:
|
||||
"""Ensures that example numbers in the ActivityPub specification
|
||||
document are sequential
|
||||
"""
|
||||
lines = markdown.split('\n')
|
||||
example_number = 1
|
||||
line_ctr = 0
|
||||
for line in lines:
|
||||
if not line.strip():
|
||||
# skip blank lines
|
||||
line_ctr += 1
|
||||
continue
|
||||
if line.startswith('##') and '## Example ' in line:
|
||||
header_str = line.split(' Example ')[0]
|
||||
lines[line_ctr] = header_str + ' Example ' + str(example_number)
|
||||
example_number += 1
|
||||
line_ctr += 1
|
||||
|
||||
markdown = ''
|
||||
for line in lines:
|
||||
markdown += line + '\n'
|
||||
return markdown
|
||||
|
||||
|
||||
def markdown_to_html(markdown: str) -> str:
|
||||
"""Converts markdown formatted text to html
|
||||
"""
|
||||
|
|
|
@ -12,6 +12,7 @@ from shutil import copyfile
|
|||
from utils import get_config_param
|
||||
from webapp_utils import html_header_with_website_markup
|
||||
from webapp_utils import html_footer
|
||||
from markdown import markdown_example_numbers
|
||||
from markdown import markdown_to_html
|
||||
|
||||
|
||||
|
@ -34,7 +35,8 @@ def html_specification(css_cache: {}, base_dir: str, http_prefix: str,
|
|||
if os.path.isfile(base_dir + '/accounts/activitypub.md'):
|
||||
with open(base_dir + '/accounts/activitypub.md', 'r',
|
||||
encoding='utf-8') as fp_specification:
|
||||
specification_text = markdown_to_html(fp_specification.read())
|
||||
md_text = markdown_example_numbers(fp_specification.read())
|
||||
specification_text = markdown_to_html(md_text)
|
||||
|
||||
specification_form = ''
|
||||
css_filename = base_dir + '/epicyon-profile.css'
|
||||
|
|
Loading…
Reference in New Issue