Ensure that specification example numbers are sequential

main
Bob Mottram 2022-06-28 10:03:34 +01:00
parent 9bbba10e33
commit 0331311dd0
2 changed files with 27 additions and 1 deletions

View File

@ -312,6 +312,30 @@ def _markdown_replace_code(markdown: str) -> str:
return markdown 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: def markdown_to_html(markdown: str) -> str:
"""Converts markdown formatted text to html """Converts markdown formatted text to html
""" """

View File

@ -12,6 +12,7 @@ from shutil import copyfile
from utils import get_config_param from utils import get_config_param
from webapp_utils import html_header_with_website_markup from webapp_utils import html_header_with_website_markup
from webapp_utils import html_footer from webapp_utils import html_footer
from markdown import markdown_example_numbers
from markdown import markdown_to_html 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'): if os.path.isfile(base_dir + '/accounts/activitypub.md'):
with open(base_dir + '/accounts/activitypub.md', 'r', with open(base_dir + '/accounts/activitypub.md', 'r',
encoding='utf-8') as fp_specification: 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 = '' specification_form = ''
css_filename = base_dir + '/epicyon-profile.css' css_filename = base_dir + '/epicyon-profile.css'