Skip to content

Commit

Permalink
Allow hash sign in header
Browse files Browse the repository at this point in the history
  • Loading branch information
martosaur committed Jan 25, 2023
1 parent 5169717 commit 48546b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/earmark_parser/line_scanner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule EarmarkParser.LineScanner do
lt_four? && Regex.run(~r/\A (?:_\s?){3,} \z/x, content) ->
%Line.Ruler{type: "_", indent: indent, line: line}

match = Regex.run(~R/^(#{1,6})\s+(?|([^#]+)#*\s*$|(.*))/u, stripped_line) ->
match = Regex.run(~R/^(#{1,6})\s+(?|(.*?)\s*#*\s*$|(.*))/u, stripped_line) ->
[_, level, heading] = match

%Line.Heading{
Expand Down
23 changes: 23 additions & 0 deletions test/acceptance/ast/atx_headers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ defmodule Acceptance.Ast.AtxHeadersTest do
assert as_ast(markdown) == {:ok, [ast], messages}
end

test "closing headers can get creative" do
markdown = "### foo######\n"
ast = tag("h3", "foo")
messages = []

assert as_ast(markdown) == {:ok, [ast], messages}
end

test "hash can still be used in a header" do
markdown = "# C# #\n"
ast = tag("h1", "C#")
messages = []

assert as_ast(markdown) == {:ok, [ast], messages}
end

test "closing header with hash" do
markdown = "# C# (language)#\n"
ast = tag("h1", "C# (language)")
messages = []

assert as_ast(markdown) == {:ok, [ast], messages}
end
end
end

Expand Down

0 comments on commit 48546b8

Please sign in to comment.