Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions asciidoc_linter/rules/whitespace_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def check_line(
# Check for blank line before section title (except for first line)
if line_number > 0:
prev_content = self.get_line_content(context[line_number - 1])
if prev_content.strip():
if prev_content.strip() and not prev_content.strip().startswith(("[.", "[[")):
findings.append(
Finding(
rule_id=self.id,
Expand All @@ -135,7 +135,7 @@ def check_line(
# Check for blank line after section title (except for last line)
if line_number < len(context) - 1:
next_content = self.get_line_content(context[line_number + 1])
if next_content.strip():
if next_content.strip() and not next_content.strip().startswith(":"):
findings.append(
Finding(
rule_id=self.id,
Expand Down
56 changes: 56 additions & 0 deletions tests/rules/test_heading_rules.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,61 @@ def test_multiple_top_level(self):
)


class TestHeadingAttributesAndRoles(unittest.TestCase):
"""Tests for headings with attributes and roles.
This rule ensures that headings with attributes and roles are properly handled.
"""

def setUp(self):
"""
Given a HeadingFormatRule instance
"""
self.rule = HeadingFormatRule()

def test_heading_with_attributes(self):
"""
Given a document with headings followed by attributes
When the heading format rule is checked
Then no findings should be reported
"""
# Given: A document with headings followed by attributes
content = """
= Level 1
:attribute: value

== Level 2
:another-attribute: value
"""
# When: We check the heading format
findings = self.rule.check(content)

# Then: No findings should be reported
self.assertEqual(
len(findings), 0, "Headings followed by attributes should not produce findings"
)

def test_heading_with_roles(self):
"""
Given a document with headings preceded by roles
When the heading format rule is checked
Then no findings should be reported
"""
# Given: A document with headings preceded by roles
content = """
[.role]
= Level 1

[[target]]
== Level 2
"""
# When: We check the heading format
findings = self.rule.check(content)

# Then: No findings should be reported
self.assertEqual(
len(findings), 0, "Headings preceded by roles should not produce findings"
)


if __name__ == "__main__":
unittest.main()
Loading