Skip to content
Snippets Groups Projects
Commit 34439a1b authored by I. Nüske's avatar I. Nüske
Browse files

MNT: Fix pandoc_header_tools.get_header() name collision

parent 3c4042a4
No related branches found
No related tags found
2 merge requests!128MNT: Added a warning when column metadata is not configured, and a better...,!126Fix pylint errors
Pipeline #59029 failed
...@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `h5` instead of `h5-crawler` - `h5` instead of `h5-crawler`
- `dev`, `doc`, `test` and `all` are new, they install the dependencies for developing, testing, - `dev`, `doc`, `test` and `all` are new, they install the dependencies for developing, testing,
documentation and everything. documentation and everything.
- The `pandoc_header_tools.get_header()` parameter `add_header` has been renamed to `add_header_to_file`
to resolve a name collision.
### Deprecated ### ### Deprecated ###
......
...@@ -68,31 +68,30 @@ description: ...@@ -68,31 +68,30 @@ description:
""" """
def get_header(filename, add_header=False): def get_header(filename, add_header_to_file=False):
"""Open an md file identified by filename and read out the yaml """Open an md file identified by filename and read out the yaml header.
header.
filename can also be a folder. In this case folder/README.md will be used for filename can also be a folder. In this case folder/README.md will be used
getting the header. for getting the header.
If a header is found a tuple is returned: (first yaml header line index, last+1 If a header is found a tuple is returned: (first yaml header line index,
yaml header line index, header) last+1 yaml header line index, header)
Otherwise, if `add_header` is True, a header is added and the function is called Otherwise, if `add_header_to_file` is True, a header is added and the
again. function is called again.
The header is normalized in the following way: 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 - If the value to a key is a string, a list with that string as only
returned. element is returned.
From https://pandoc.org/MANUAL.html: From https://pandoc.org/MANUAL.html:
A YAML metadata block is a valid YAML object, delimited by a line of three 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 (...) hyphens (---) at the top and a line of three hyphens (---) or three
at the bottom. A YAML metadata block may occur anywhere in the document, but if dots (...) at the bottom. A YAML metadata block may occur anywhere in the
it is not at the beginning, it must be preceded by a blank line. document, but if it is not at the beginning, it must be preceded by a blank
line.
""" """
if os.path.isdir(filename): if os.path.isdir(filename):
...@@ -146,7 +145,7 @@ it is not at the beginning, it must be preceded by a blank line. ...@@ -146,7 +145,7 @@ it is not at the beginning, it must be preceded by a blank line.
raise NoValidHeader(filename) raise NoValidHeader(filename)
return (found_1, found_2, clean_header(yaml_part)) return (found_1, found_2, clean_header(yaml_part))
if not add_header: if not add_header_to_file:
raise NoValidHeader(filename) raise NoValidHeader(filename)
else: else:
print("Adding header in: {fn}".format(fn=filename)) print("Adding header in: {fn}".format(fn=filename))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment