Skip to content

fix(jira): stop a blank line before ---- becoming an empty h2. - #1590

Merged
sooperset merged 1 commit into
sooperset:mainfrom
amitvijapur:fix/jira-setext-empty-heading
Aug 17, 2026
Merged

sooperset merged 1 commit into
sooperset:mainfrom
amitvijapur:fix/jira-setext-empty-heading

Conversation

@amitvijapur

Copy link
Copy Markdown
Contributor

Description

markdown_to_jira turned a horizontal rule that follows a blank line into an
empty h2., losing the rule:

"before\n\n----\n\nafter"  ->  "before\nh2. \n\nafter"

The setext heading rule matched ^(.*?)\n([=-])+$. Because (.*?) also matches
the empty string, the blank line above ---- was consumed as the heading's text.

A setext underline needs actual text on the line above it, so a lookahead now
requires at least one non-whitespace character there. ---- on its own line is
then left untouched, which is already the Jira markup for a horizontal rule, so
no separate rule handling is needed.

Fixes: #1587

Changes

  • preprocessing/jira.py: added a (?=[^\n]*\S) lookahead to the setext heading
    pattern so a blank or whitespace-only line cannot be treated as heading text.
  • Added a TestSetextHeadings class covering both the bug and the behaviour that
    must not regress.

Legitimate setext headings are unaffected, including a rule placed directly under
a text line with no blank line between them — CommonMark treats that as a setext
underline rather than a thematic break, and it still converts to h2..

Testing

  • Unit tests added/updated
  • Integration tests passed
  • Manual checks performed: reproduced the reported conversion before the
    change and confirmed it is correct after.

Six new tests in tests/unit/preprocessing/test_preprocessing.py:

Case Expected
before\n\n----\n\nafter unchanged, rule preserved
----\n\nafter (leading rule) unchanged
whitespace-only line before ---- unchanged
My Heading\n---\nbody h2. My Heading
My Heading\n===\nbody h1. My Heading
Some text\n----\nbody h2. Some text

Full unit suite: 3817 passed, 5 skipped. pre-commit run passes on the
changed files, including ruff-format, ruff and mypy.

Checklist

  • Code follows project style guidelines (linting passes).
  • Tests added/updated for changes.
  • All tests pass locally.
  • Documentation updated (if needed) — no user-facing docs describe this.

Note

While here I noticed ([=-])+ also accepts a mixed run, so Title\n=-=- is
treated as a heading and match.group(2)[0] reads the last character rather than
the first. Left alone to keep this focused on the reported bug — happy to send a
follow-up if you would like that tightened to (=+|-+).

The setext heading rule matched `^(.*?)\n([=-])+$`, and `(.*?)` matches the
empty string, so a horizontal rule preceded by a blank line consumed that
blank line as its heading text:

    "before\n\n----\n\nafter"  ->  "before\nh2. \n\nafter"

The rule was destroyed and an empty `h2.` appeared in its place. A setext
underline requires actual text on the line above it, so a lookahead now
demands at least one non-whitespace character there. `----` on its own line
is then left alone, which is already the Jira markup for a horizontal rule.

Legitimate setext headings are unaffected, including a rule directly under a
text line with no blank between them, which CommonMark defines as a setext
underline rather than a thematic break.

Closes sooperset#1587
@sooperset
sooperset merged commit 9185946 into sooperset:main Aug 17, 2026
8 checks passed
@mcp-atlassian-maintainer

Copy link
Copy Markdown
Contributor

@amitvijapur, the focused regression coverage here is excellent: it protects the blank-line horizontal-rule case while confirming both setext heading levels still convert correctly. Thanks for keeping the regex change narrow and documenting the mixed-underline edge case separately.

sanderma pushed a commit to sanderma/mcp-atlassian that referenced this pull request Aug 18, 2026
Conflict resolution keeps the mistletoe/jira2markdown conversion
pipeline and reconciles the upstream fixes that patched the removed
regex engine:

- sooperset#1361 (intraword underscores italicized): adopted as policy in the
  renderer's escaper - * and _ are escaped whenever they touch
  non-whitespace because Jira applies emphasis intraword; the
  boundary-only effects (- + ^ ~) keep the lenient rule so dates and
  hyphenated words stay readable.
- sooperset#1587/sooperset#1590 (blank line before ---- became an empty h2.): subsumed
  by the CommonMark parser; a thematic break now also keeps a blank
  line after the rule.
- sooperset#1379 (markdown table parsing): subsumed by mistletoe's table
  support.
- sooperset#1476 (segmented issue keys): ported _ISSUE_KEY_PATTERN into
  _process_smart_links.

The tool-description conflicts merge both sides (Markdown contract
wording plus upstream's Cloud expand hint and body/comment alias).
types-cachetools returns to upstream's constraint now that the
TTLCache annotation this branch patched was removed upstream.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0111CE62sJaCyTPbdqGEMpMG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Jira Server / Data Center: \n\n----\n\n becomes an empty h2. rather than the intended horizontal rule

2 participants