-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown output #439
Closed
Closed
Markdown output #439
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f2588e
Output to markdown compatible format when configured filename extensi…
SmileyChris 3e6b620
Add test for different configured underlines/title_prefixes defaults …
SmileyChris 7f6e545
Test markdown options against both draft and build modes
SmileyChris 8116d90
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a0dcb22
Add newsfragment and docs
SmileyChris e6277d5
Fix docs formatting typo
SmileyChris 729f925
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 70f9364
Python's standard markdown implementation needs indentation and an em…
SmileyChris 7bacdcf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 904d266
Fix test for windows
SmileyChris ea7d1a6
Try to fix windows test again
SmileyChris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -45,9 +45,12 @@ class Config: | |||||
title_format: str | Literal[False] | ||||||
issue_format: str | None | ||||||
underlines: list[str] | ||||||
title_prefixes: list[str] | ||||||
wrap: bool | ||||||
all_bullets: bool | ||||||
orphan_prefix: str | ||||||
bullet: str | ||||||
issues_spaced: bool | ||||||
|
||||||
|
||||||
class ConfigError(Exception): | ||||||
|
@@ -60,6 +63,21 @@ def __init__(self, *args: str, **kwargs: str): | |||||
_title_format = None | ||||||
_template_fname = "towncrier:default" | ||||||
_underlines = ["=", "-", "~"] | ||||||
_md_underlines = ["", "", ""] | ||||||
_prefixes = ["", "", ""] | ||||||
_md_prefixes = ["# ", "## ", "### "] | ||||||
_bullet = "- " | ||||||
_md_bullet = " - " | ||||||
|
||||||
|
||||||
# The default options differ when using a filename that has an extension of ``.md``: | ||||||
|
||||||
# Firstly, no underlines are used, but instead markdown h1, h2 and h3 prefixes are used | ||||||
# for the title, categories, and sections respectively. | ||||||
|
||||||
# Secondly, Python's standard markdown implementation needs indentation and an empty | ||||||
# line between bullets to render multi-line bullets correctly, so the bullet | ||||||
# representation is ``" - "`` and the ``issues_spaced`` defaults to True. | ||||||
|
||||||
|
||||||
def load_config_from_options( | ||||||
|
@@ -164,11 +182,13 @@ def parse_toml(base_path: str, config: Mapping[str, Any]) -> Config: | |||||
failing_option="template", | ||||||
) | ||||||
|
||||||
filename = config.get("filename", "NEWS.rst") | ||||||
is_md = filename.endswith(".md") | ||||||
return Config( | ||||||
package=config.get("package", ""), | ||||||
package_dir=config.get("package_dir", "."), | ||||||
single_file=single_file, | ||||||
filename=config.get("filename", "NEWS.rst"), | ||||||
filename=filename, | ||||||
directory=config.get("directory"), | ||||||
version=config.get("version"), | ||||||
name=config.get("name"), | ||||||
|
@@ -178,8 +198,13 @@ def parse_toml(base_path: str, config: Mapping[str, Any]) -> Config: | |||||
start_string=config.get("start_string", _start_string), | ||||||
title_format=config.get("title_format", _title_format), | ||||||
issue_format=config.get("issue_format"), | ||||||
underlines=config.get("underlines", _underlines), | ||||||
underlines=config.get("underlines", _md_underlines if is_md else _underlines), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it easier to read.
Suggested change
|
||||||
title_prefixes=config.get( | ||||||
"title_prefixes", _md_prefixes if is_md else _prefixes | ||||||
), | ||||||
wrap=wrap, | ||||||
bullet=_md_bullet if is_md else _bullet, | ||||||
issues_spaced=is_md, | ||||||
all_bullets=all_bullets, | ||||||
orphan_prefix=config.get("orphan_prefix", "+"), | ||||||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
We now have easy markdown-compatible rendering! | ||
|
||
When the configured filename has a ``.md`` extension: the title, sections, and | ||
newsfragment categories are output respectively with #, ## and ### markdown | ||
headings prefixed (and without any underlines). Bulleted issues are also | ||
indented, with multi-line spaces between to rendered correctly with Python's | ||
standard markdown implementation. | ||
|
||
The default template no longer renders an empty newline for empty underlines | ||
configurations, and templates are rendered with extra context for ``bullet``, | ||
``title_prefix``, ``section_prefix``, and ``category_prefix``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have all the
if_md
values and default selection in a common block.Is ok to even move this to a separate function like `defaults = _get_missing_defaults(config)"
And I hope we don't need md_prefixes and md_bullet, as we can handle all this in the custom
tempalates/default.md
What do you think?