From f6c9f6687ad88ea7269da0caa06603b640b0681b Mon Sep 17 00:00:00 2001 From: jackdewinter Date: Sat, 7 Dec 2024 19:33:13 -0800 Subject: [PATCH] https://github.com/jackdewinter/pymarkdown/issues/1267 (#1279) * https://github.com/jackdewinter/pymarkdown/issues/1258 --- Pipfile | 2 +- newdocs/src/changelog.md | 5 +++- publish/coverage.json | 4 +-- publish/test-results.json | 2 +- pymarkdown/plugins/rule_md_018.py | 1 + pymarkdown/tokens/markdown_token.py | 23 ++++++++++----- test/rules/test_md018.py | 43 +++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 12 deletions(-) diff --git a/Pipfile b/Pipfile index 2f7b31b96..b87556396 100644 --- a/Pipfile +++ b/Pipfile @@ -32,12 +32,12 @@ setuptools = "==75.3.0" snakeviz = "==2.2.0" sourcery = "==1.24.0" types-pyyaml = "*" +twine = "<5.1" [packages] columnar = ">=1.4.0" application-properties = ">=0.8.2" typing-extensions = ">=4.7.0" -twine = "<5.1" [requires] python_version = "3.8" diff --git a/newdocs/src/changelog.md b/newdocs/src/changelog.md index 5a85b3bf9..5075ada96 100644 --- a/newdocs/src/changelog.md +++ b/newdocs/src/changelog.md @@ -27,11 +27,14 @@ - [Issue 1274](https://github.com/jackdewinter/pymarkdown/issues/1274) - Fixed remaining assert issues, leaving fixes that produce valid Markdown, but not the intended Markdown. +- [Issue 1267](https://github.com/jackdewinter/pymarkdown/issues/1267) + - Fixed reported issue with task lists creating an error in Md018. ### Changed -None +- [Issue 1258](https://github.com/jackdewinter/pymarkdown/issues/1258) + - Moved twine package into dev section ## Version 0.9.25 - Date: 2024-11-07 diff --git a/publish/coverage.json b/publish/coverage.json index 50ee32f7f..4341ec369 100644 --- a/publish/coverage.json +++ b/publish/coverage.json @@ -6,8 +6,8 @@ "totalCovered": 5503 }, "lineLevel": { - "totalMeasured": 21389, - "totalCovered": 21389 + "totalMeasured": 21393, + "totalCovered": 21393 } } diff --git a/publish/test-results.json b/publish/test-results.json index cedcb0ad3..7aceab9ca 100644 --- a/publish/test-results.json +++ b/publish/test-results.json @@ -1228,7 +1228,7 @@ }, { "name": "test.rules.test_md018", - "totalTests": 29, + "totalTests": 30, "failedTests": 0, "errorTests": 0, "skippedTests": 0, diff --git a/pymarkdown/plugins/rule_md_018.py b/pymarkdown/plugins/rule_md_018.py index 2748249bf..12e53dd21 100644 --- a/pymarkdown/plugins/rule_md_018.py +++ b/pymarkdown/plugins/rule_md_018.py @@ -144,6 +144,7 @@ def __next_token_paragraph_non_text_inline(self, token: MarkdownToken) -> None: token.is_inline_emphasis or token.is_inline_emphasis_end or token.is_inline_autolink + or token.is_task_list ) self.__delayed_line = None diff --git a/pymarkdown/tokens/markdown_token.py b/pymarkdown/tokens/markdown_token.py index 5e3a3618f..a38d6e573 100644 --- a/pymarkdown/tokens/markdown_token.py +++ b/pymarkdown/tokens/markdown_token.py @@ -33,10 +33,18 @@ class MarkdownToken: extra_data_separator = ":" _end_token_prefix = "end-" + _token_pragma = "pragma" - _token_task_list = "task-list" _token_end_of_stream = "end-of-stream" + _token_task_list = "task-list" + _token_front_matter = "front-matter" + + _token_block_quote = "block-quote" + _token_unordered_list_start = "ulist" + _token_ordered_list_start = "olist" + _token_new_list_item = "li" + _token_paragraph = "para" _token_blank_line = "BLANK" _token_atx_heading = "atx" @@ -46,13 +54,7 @@ class MarkdownToken: _token_html_block = "html-block" _token_fenced_code_block = "fcode-block" _token_indented_code_block = "icode-block" - _token_block_quote = "block-quote" _token_text = "text" - _token_front_matter = "front-matter" - - _token_unordered_list_start = "ulist" - _token_ordered_list_start = "olist" - _token_new_list_item = "li" _token_inline_code_span = "icode-span" _token_inline_hard_break = "hard-break" @@ -380,6 +382,13 @@ def is_front_matter(self) -> bool: """ return self.token_name == MarkdownToken._token_front_matter + @property + def is_task_list(self) -> bool: + """ + Returns whether the current token is the task list element. + """ + return self.token_name == MarkdownToken._token_task_list + @property def is_text(self) -> bool: """ diff --git a/test/rules/test_md018.py b/test/rules/test_md018.py index 7dc6717a7..4f0ace534 100644 --- a/test/rules/test_md018.py +++ b/test/rules/test_md018.py @@ -5,6 +5,7 @@ import os from test.markdown_scanner import MarkdownScanner from test.rules.utils import execute_query_configuration_test, pluginQueryConfigTest +from test.utils import create_temporary_configuration_file import pytest @@ -1044,6 +1045,48 @@ def test_md018_bad_single_paragraph_with_whitespace(): ) +@pytest.mark.rules +def test_md018_issue_1267(): + """ + Test to make sure this rule handles having a task list as part of the document. + Reported as Issue 1267, ran up against guard code. + """ + + # Arrange + scanner = MarkdownScanner() + source_file_contents = """--- +title: abc +--- + +- [ ] abc +""" + + with create_temporary_configuration_file( + source_file_contents, file_name_suffix=".md" + ) as source_path: + supplied_arguments = [ + "--disable-rules", + "md022", + "--set", + "extensions.markdown-task-list-items.enabled=$!True", + "--stack-trace", + "scan", + source_path, + ] + + expected_return_code = 0 + expected_output = "" + expected_error = "" + + # Act + execute_results = scanner.invoke_main(arguments=supplied_arguments) + + # Assert + execute_results.assert_results( + expected_output, expected_error, expected_return_code + ) + + def test_md018_query_config(): config_test = pluginQueryConfigTest( "md018",