Skip to content

Commit

Permalink
Fix: Correct heading style detection
Browse files Browse the repository at this point in the history
Fixes #625

Just count leading and trailing hash tags and compare the amount in
order to decide for style. This ignores SETEXT headings and fixes an
edge case caused by new syntax definition.
  • Loading branch information
deathaxe committed Sep 14, 2021
1 parent 2e49a2e commit 9bfbd62
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions plugins/headings/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,16 @@ def auto_detect_heading_style(self):
view.settings().set("mde.auto_match_heading_hashes", False)
return

num_leading = 0
num_trailing = 0

for h1, h2 in zip(
view.find_by_selector("markup.heading")[:10],
view.find_by_selector("markup.heading - punctuation.definition.heading")[:10],
):
num_leading += 1
if h1.end() > h2.end():
num_trailing += 1

num_leading = len(
view.find_by_selector("markup.heading punctuation.definition.heading.begin")
)
if num_leading:
num_trailing = len(
view.find_by_selector("markup.heading punctuation.definition.heading.end")
)
view.settings().set("mde.match_heading_hashes", num_trailing / num_leading > 0.5)
else:
view.settings().erase("mde.match_heading_hashes")

if view.settings().get("mde.auto_match_heading_hashes", False):
view.run_command("mde_match_heading_hashes")

0 comments on commit 9bfbd62

Please sign in to comment.