Skip to content

Commit 8382ed9

Browse files
authored
Fix issue with de-duplicating MamlLinks (#282)
1 parent 6dec7bb commit 8382ed9

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

build.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
param(
44
[ValidateSet('Debug', 'Release')]
5-
$Configuration = "Debug"
5+
$Configuration = "Debug",
6+
[switch]$SkipDocs
67
)
78

89
# build .dll
@@ -46,7 +47,9 @@ if ($env:APPVEYOR_REPO_TAG_NAME)
4647
# dogfooding: generate help for the module
4748
Remove-Module platyPS -ErrorAction SilentlyContinue
4849
Import-Module $pwd\out\platyPS
49-
New-ExternalHelp docs -OutputPath out\platyPS\en-US -Force
5050

51-
# reload module, to apply generated help
52-
Import-Module $pwd\out\platyPS -Force
51+
if (-not $SkipDocs) {
52+
New-ExternalHelp docs -OutputPath out\platyPS\en-US -Force
53+
# reload module, to apply generated help
54+
Import-Module $pwd\out\platyPS -Force
55+
}

src/Markdown.MAML/Transformer/MamlMultiModelMerger.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,55 @@ public MamlCommand Merge(Dictionary<string, MamlCommand> applicableTag2Model)
8585
Extent = referenceModel.Extent
8686
};
8787

88-
// post all links, exclude dups
89-
result.Links.AddRange(MergeEntityList(tagsModel.ToDictionary(pair => pair.Key, pair => pair.Value.Links)));
88+
result.Links.AddRange(MergeSimplifiedLinks(tagsModel.Select(pair => pair.Value.Links)));
9089

9190
MergeExamples(result, applicableTag2Model);
9291

93-
result.Inputs.AddRange(MergeEntityList(tagsModel.ToDictionary(pair => pair.Key, pair => pair.Value.Inputs)));
94-
result.Outputs.AddRange(MergeEntityList(tagsModel.ToDictionary(pair => pair.Key, pair => pair.Value.Outputs)));
92+
result.Inputs.AddRange(MergeEntityList(tagsModel.Select(pair => pair.Value.Inputs)));
93+
result.Outputs.AddRange(MergeEntityList(tagsModel.Select(pair => pair.Value.Outputs)));
9594

9695
MergeParameters(result, applicableTag2Model);
9796
return result;
9897
}
9998

99+
private IEnumerable<MamlLink> MergeSimplifiedLinks(IEnumerable<List<MamlLink>> linksList)
100+
{
101+
// In theory we could simply use MergeEntityList, but we have this SimplifiedLinks hack:
102+
// we just put whole paragraphs of text into LinkName.
103+
104+
// To acoount for it we should
105+
// split any simplified link into separate ones.
106+
// Then we can combine them and return in the form of simplified links.
107+
108+
List<List<MamlLink>> candidates = new List<List<MamlLink>>();
109+
foreach (var links in linksList)
110+
{
111+
foreach (var link in links)
112+
{
113+
if (!link.IsSimplifiedTextLink)
114+
{
115+
throw new ArgumentException("All links are expected in simplified form");
116+
}
117+
string[] segments = link.LinkName.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
118+
candidates.Add(segments.Select(s => new MamlLink(isSimplifiedTextLink: true) { LinkName = s.Trim() + "\r\n\r\n" }).ToList());
119+
}
120+
}
121+
122+
return MergeEntityList(candidates);
123+
}
124+
100125
/// <summary>
101126
/// Merge entities, exclude duplicates and preserve the order.
102127
/// </summary>
103128
/// <param name="links"></param>
104129
/// <returns></returns>
105-
private List<TEntity> MergeEntityList<TEntity>(Dictionary<string, List<TEntity>> applicableTag2Model)
130+
private List<TEntity> MergeEntityList<TEntity>(IEnumerable<List<TEntity>> entities)
106131
where TEntity : IEquatable<TEntity>
107132
{
108133
List<TEntity> result = new List<TEntity>();
109-
foreach(var pair in applicableTag2Model)
134+
foreach(var entity in entities)
110135
{
111-
foreach (var candidate in pair.Value)
136+
foreach (var candidate in entity)
112137
{
113138
// this cycle can be optimized but that's fine
114139
bool found = false;

test/Markdown.MAML.Test/Transformer/MamlMultiModelMergerTests.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void Merge3SimpleModels()
1818
input["Second"] = GetModel2();
1919
input["Third"] = GetModel3();
2020

21-
var result = merger.Merge(input);
21+
var result = merger.Merge(input);
2222

2323
Assert.Equal(result.Synopsis, @"! First, Second
2424
@@ -54,8 +54,8 @@ Third Command
5454

5555
// Links
5656
Assert.Equal(2, result.Links.Count);
57-
Assert.Equal("", result.Links.ElementAt(0).LinkName);
58-
Assert.Equal("foo", result.Links.ElementAt(1).LinkName);
57+
Assert.Equal("[foo]()\r\n\r\n", result.Links.ElementAt(0).LinkName);
58+
Assert.Equal("[bar]()\r\n\r\n", result.Links.ElementAt(1).LinkName);
5959

6060
// Examples
6161
Assert.Equal(2, result.Examples.Count);
@@ -103,10 +103,9 @@ private MamlCommand GetModel1()
103103
Notes = "This is a multiline note.\r\nSecond line.\r\nFirst Command"
104104
};
105105

106-
command.Links.Add(new MamlLink()
106+
command.Links.Add(new MamlLink(true)
107107
{
108-
LinkName = "", // if name is empty, it would be populated with uri
109-
LinkUri = "http://foo.com"
108+
LinkName = "[foo]()\r\n",
110109
});
111110

112111
command.Inputs.Add(new MamlInputOutput()
@@ -160,16 +159,9 @@ private MamlCommand GetModel2()
160159
Notes = "This is a multiline note.\r\nSecond line.\r\nSecond Command"
161160
};
162161

163-
command.Links.Add(new MamlLink()
164-
{
165-
LinkName = "", // if name is empty, it would be populated with uri
166-
LinkUri = "http://foo.com"
167-
});
168-
169-
command.Links.Add(new MamlLink()
162+
command.Links.Add(new MamlLink(true)
170163
{
171-
LinkName = "foo",
172-
LinkUri = ""
164+
LinkName = "[foo]()\r\n[bar]()",
173165
});
174166

175167
command.Examples.Add(new MamlExample()
@@ -224,10 +216,9 @@ private MamlCommand GetModel3()
224216
Notes = "This is a multiline note.\r\nSecond line.\r\nThird Command"
225217
};
226218

227-
command.Links.Add(new MamlLink()
219+
command.Links.Add(new MamlLink(true)
228220
{
229-
LinkName = "foo",
230-
LinkUri = ""
221+
LinkName = "[bar]()",
231222
});
232223

233224
command.Examples.Add(new MamlExample()

0 commit comments

Comments
 (0)