caosadvancedtools.pandoc_header_tools module#
- exception caosadvancedtools.pandoc_header_tools.MetadataFileMissing(filename, *args, **kwargs)#
Bases:
Exception
- exception caosadvancedtools.pandoc_header_tools.NoValidHeader(filename, *args, **kwargs)#
Bases:
Exception
- exception caosadvancedtools.pandoc_header_tools.ParseErrorsInHeader(filename, reason, *args, **kwargs)#
Bases:
Exception
- caosadvancedtools.pandoc_header_tools.add_header(filename, header_dict=None)#
Add a header to an md file.
If the file does not exist it will be created.
If header_dict is a dictionary and not None the header will be created based on the keys and values of that dictionary.
- caosadvancedtools.pandoc_header_tools.clean_header(header)#
- caosadvancedtools.pandoc_header_tools.get_header(filename, add_header_to_file=False)#
Open an md file identified by filename and read out the yaml header.
filename can also be a folder. In this case folder/README.md will be used for getting the header.
If a header is found a tuple is returned: (first yaml header line index, last+1 yaml header line index, header)
Otherwise, if add_header_to_file is True, a header is added and the function is called again.
The header is normalized in the following way:
If the value to a key is a string, a list with that string as only element is returned.
From https://pandoc.org/MANUAL.html:
A YAML metadata block is a valid YAML object, delimited by a line of three hyphens (—) at the top and a line of three hyphens (—) or three dots (…) at the bottom. A YAML metadata block may occur anywhere in the document, but if it is not at the beginning, it must be preceded by a blank line.
- caosadvancedtools.pandoc_header_tools.kw_present(header, kw)#
Check whether keywords are present in the header.
- caosadvancedtools.pandoc_header_tools.save_header(filename, header_data)#
Save a header identified by the tuple header_data to the file identified by filename.
filename can also be a folder. In this case folder/README.md will be used for getting the header.