Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions scripts/reformat_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def is_block_valid(self, block):
def convert_sections(self, block):
return [self.format_module(block)]

def needs_new_header(self, file_contents):
return (re.search(r'^\/\/\/ \\file$', file_contents, flags=re.MULTILINE)
is None)


class FunctionFormatter(GenericFormatter):
def __init__(self, doc_width):
Expand Down Expand Up @@ -188,6 +192,7 @@ def convert_sections(self, block):

def replace_block(
block_contents,
file_contents,
file,
header_formatter,
class_formatter,
Expand All @@ -199,9 +204,10 @@ def replace_block(
{f.name: f.contents for f in parse_fields(block_contents.group(1))})

if header_formatter.is_block_valid(block):
return '%s%s\n' % (
block_contents.group(0),
header_formatter.convert(header_from_block(block)))
converted = header_formatter.convert(header_from_block(block))
if header_formatter.needs_new_header(file_contents) and converted:
return block_contents.group(0) + converted + '\n'
return block_contents.group(0)

if class_formatter.is_block_valid(block):
return class_formatter.convert(class_from_block(block))
Expand Down Expand Up @@ -231,6 +237,7 @@ def convert_file(file, inplace):
new_contents = block_re.sub(
lambda match: replace_block(
match,
contents,
file,
header_formatter,
class_formatter,
Expand Down