Skip to content

Commit

Permalink
improve adjust_headings
Browse files Browse the repository at this point in the history
do not match links with anchor as headings
do not match escaped `#`
  • Loading branch information
lukaszsamson committed Jan 27, 2024
1 parent d10ce2c commit 1ab3110
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/language_server/lib/language_server/markdown_utils.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule ElixirLS.LanguageServer.MarkdownUtils do
@hash_match ~r/(?<!\\)(?<!\w)(#+)(?=\s)/u
# Find the lowest heading level in the fragment
defp lowest_heading_level(fragment) do
case Regex.scan(~r/(#+)/u, fragment) do
case Regex.scan(@hash_match, fragment) do
[] ->
nil

Expand All @@ -19,7 +20,7 @@ defmodule ElixirLS.LanguageServer.MarkdownUtils do
if min_level do
level_difference = base_level + 1 - min_level

Regex.replace(~r/(#+)/u, fragment, fn _, capture ->
Regex.replace(@hash_match, fragment, fn _, capture ->
adjusted_level = String.length(capture) + level_difference
String.duplicate("#", adjusted_level)
end)
Expand Down

0 comments on commit 1ab3110

Please sign in to comment.