Skip to content

Commit a07bca0

Browse files
committed
fix: Trim triple newlines instead of double newlines
Removing double newlines breaks formatting in e.g. the generated browser docs, and breaks doctests, since they expect the example code sections to be separated by the rest of the comments by double newlines. Instead, we should focus on collapsing triple newlines, which can occur for legitimate reasons, e.g. a section of the generated documentation doesn't return any text, but which shouldn't be showed in the resulting documentation. Fixes: #2433
1 parent 9c580b9 commit a07bca0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/ash/code_interface.ex

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ defmodule Ash.CodeInterface do
465465
466466
#{interface_options.docs()}
467467
"""
468-
|> Ash.CodeInterface.trim_double_newlines()
468+
|> Ash.CodeInterface.trim_triple_newlines()
469469
@doc spark_opts: [
470470
{opts_location, interface_options.schema()}
471471
]
@@ -531,7 +531,7 @@ defmodule Ash.CodeInterface do
531531
532532
#{interface_options.docs()}
533533
"""
534-
|> Ash.CodeInterface.trim_double_newlines()
534+
|> Ash.CodeInterface.trim_triple_newlines()
535535
@doc spark_opts: [
536536
{opts_location, interface_options.schema()}
537537
]
@@ -1651,7 +1651,7 @@ defmodule Ash.CodeInterface do
16511651
16521652
#{interface_options.docs()}
16531653
"""
1654-
|> Ash.CodeInterface.trim_double_newlines()
1654+
|> Ash.CodeInterface.trim_triple_newlines()
16551655

16561656
@doc spark_opts: [
16571657
{first_opts_location, interface_options.schema()},
@@ -1683,7 +1683,7 @@ defmodule Ash.CodeInterface do
16831683
16841684
#{interface_options.docs()}
16851685
"""
1686-
|> Ash.CodeInterface.trim_double_newlines()
1686+
|> Ash.CodeInterface.trim_triple_newlines()
16871687

16881688
@doc spark_opts: [
16891689
{first_opts_location, interface_options.schema()},
@@ -1728,7 +1728,7 @@ defmodule Ash.CodeInterface do
17281728
17291729
#{Spark.Options.docs(subject_opts)}
17301730
"""
1731-
|> Ash.CodeInterface.trim_double_newlines()
1731+
|> Ash.CodeInterface.trim_triple_newlines()
17321732
@doc spark_opts: [
17331733
{first_opts_location, subject_opts},
17341734
{first_opts_location + 1, subject_opts}
@@ -1754,7 +1754,7 @@ defmodule Ash.CodeInterface do
17541754
17551755
#{Ash.Resource.Interface.CanOpts.docs()}
17561756
"""
1757-
|> Ash.CodeInterface.trim_double_newlines()
1757+
|> Ash.CodeInterface.trim_triple_newlines()
17581758
@dialyzer {:nowarn_function, {:"can_#{interface.name}", length(common_args) + 3}}
17591759
@doc spark_opts: [
17601760
{first_opts_location + 1, Ash.Resource.Interface.CanOpts.schema()},
@@ -1842,7 +1842,7 @@ defmodule Ash.CodeInterface do
18421842
18431843
#{Ash.Resource.Interface.CanQuestionMarkOpts.docs()}
18441844
"""
1845-
|> Ash.CodeInterface.trim_double_newlines()
1845+
|> Ash.CodeInterface.trim_triple_newlines()
18461846
def unquote(:"can_#{interface.name}?")(
18471847
actor,
18481848
unquote_splicing(common_args),
@@ -2306,6 +2306,12 @@ defmodule Ash.CodeInterface do
23062306
|> String.trim_trailing()
23072307
end
23082308

2309+
def trim_triple_newlines(str) do
2310+
str
2311+
|> String.replace(~r/\n{3,}/, "\n\n")
2312+
|> String.trim_trailing()
2313+
end
2314+
23092315
@doc false
23102316
def bulk_query(resource, method, id) do
23112317
case method do

0 commit comments

Comments
 (0)