Skip to content

Commit da90aa5

Browse files
authored
Remove UseSoftlineBreakAsHardlineBreak from MarkdownParser (#510)
* Remove UseSoftlineBreakAsHardlineBreak from MarkdownParser This change ensures that soft line breaks are no longer treated as hard line breaks during markdown parsing. It enhances compatibility with standard markdown behavior . * update tests * Add support for soft line endings in Markdown parser Introduces a new `soft_line_endings` configuration option to control line break behavior in Markdown parsing. When enabled, soft line endings are converted to hard HTML breaks (`<br />`). Updated relevant parser logic and documentation to reflect this addition. * dotnet format * Fix tests post merging
1 parent e1164c4 commit da90aa5

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

docs/configure/content-set/navigation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Example:
88

99
```yaml
1010
project: 'PROJECT_NAME'
11+
soft_line_endings: true
1112

1213
external_hosts:
1314
- EXTERNAL_LINKS_HERE
@@ -41,6 +42,11 @@ Example:
4142
project: 'APM Java agent reference'
4243
```
4344

45+
### `soft_line_endings`
46+
47+
Optional key. Defaults to `false`. When enabled turns soft line endings in the markdown to hard HTML breaks `<br />`.
48+
49+
4450
### `external_hosts`
4551

4652
All links to external hosts must be declared in this section of `docset.yml`.

src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public record ConfigurationFile : DocumentationFile
1919
private readonly int _depth;
2020
public string? Project { get; }
2121
public Glob[] Exclude { get; } = [];
22+
public bool SoftLineEndings { get; }
2223

2324
public string[] CrossLinkRepositories { get; } = [];
2425

@@ -68,6 +69,9 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon
6869
case "project":
6970
Project = reader.ReadString(entry.Entry);
7071
break;
72+
case "soft_line_endings":
73+
SoftLineEndings = bool.TryParse(reader.ReadString(entry.Entry), out var softLineEndings) && softLineEndings;
74+
break;
7175
case "exclude":
7276
Exclude = [.. YamlStreamReader.ReadStringArray(entry.Entry).Select(Glob.Parse)];
7377
break;

src/Elastic.Markdown/Myst/MarkdownParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public MarkdownPipeline Pipeline
144144
.UseDiagnosticLinks()
145145
.UseHeadingsWithSlugs()
146146
.UseEmphasisExtras(EmphasisExtraOptions.Default)
147-
.UseSoftlineBreakAsHardlineBreak()
148147
.UseSubstitution()
149148
.UseComments()
150149
.UseYamlFrontMatter()

tests/Elastic.Markdown.Tests/Inline/SubstitutionTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ not a comment
2323
[Fact]
2424
public void ReplacesSubsFromFrontMatter() =>
2525
Html.Should().Contain(
26-
"""Hello World!<br />"""
26+
"""Hello World!"""
2727
).And.Contain(
2828
"""not a comment"""
2929
)
@@ -52,7 +52,7 @@ not a {substitution}
5252
[Fact]
5353
public void PreservesSingleBracket() =>
5454
Html.Should().Contain(
55-
"""Hello World!<br />"""
55+
"""Hello World!"""
5656
).And.Contain(
5757
"""not a comment"""
5858
)
@@ -108,7 +108,7 @@ public class SupportsSubstitutionsFromDocSet(ITestOutputHelper output) : InlineT
108108

109109
[Fact]
110110
public void EmitsGlobalVariable() =>
111-
Html.Should().Contain("Hello World!<br />")
111+
Html.Should().Contain("Hello World!")
112112
.And.NotContain("{{hello-world}}")
113113
.And.Contain("A variable from docset.yml")
114114
.And.NotContain("{{global-var}}");

tests/authoring/Container/DefinitionLists.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ This is my `definition`
4242
"""
4343

4444
[<Fact>]
45-
let ``validate HTML 2`` () =
45+
let ``validate HTML`` () =
4646
markdown |> convertsToHtml """
4747
<dl>
4848
<dt>This is my
@@ -51,7 +51,6 @@ This is my `definition`
5151
<dd>
5252
<p>And this is the definition
5353
<strong>body</strong>
54-
<br>
5554
Which may contain multiple lines
5655
</p>
5756
<div class="admonition note">

tests/authoring/Inline/CrossLinksRedirects.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type ``Scenario 2: Splitting a page into multiple smaller pages`` () =
9090
[<Fact>]
9191
let ``validate HTML`` () =
9292
markdown |> convertsToHtml $"""
93-
<p><a href="{urlPrefix}/testing/redirects/second-page#zz">Scenario 2</a><br/>
93+
<p><a href="{urlPrefix}/testing/redirects/second-page#zz">Scenario 2</a>
9494
<a href="{urlPrefix}/testing/redirects/third-page#bb">Scenario 2</a></p>
9595
"""
9696

tests/authoring/Inline/Substitutions.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ not a comment
1919
[<Fact>]
2020
let ``validate HTML: replace substitution`` () =
2121
markdown |> convertsToHtml """
22-
<p>The following should be subbed: Hello World!<br>
22+
<p>The following should be subbed: Hello World!
2323
not a comment</p>
2424
"""
2525

@@ -44,8 +44,8 @@ not a {substitution}
4444
[<Fact>]
4545
let ``validate HTML: leaves non subs alone`` () =
4646
markdown |> convertsToHtml """
47-
<p>The following should be subbed: Hello World!<br>
48-
not a comment</br>
49-
not a {{valid-key}}<br>
47+
<p>The following should be subbed: Hello World!
48+
not a comment
49+
not a {{valid-key}}
5050
not a {substitution}</p>
5151
"""

0 commit comments

Comments
 (0)