Skip to content

Commit

Permalink
Merge pull request #61 from lijunle/space-after-inline-code
Browse files Browse the repository at this point in the history
Fix the space after inline code block
  • Loading branch information
lijunle authored Jan 26, 2019
2 parents 13bb2a3 + c2af877 commit 4a0a291
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"command": "dotnet",
"type": "process",
"args": ["build", "${workspaceFolder}/Vsxmd/Vsxmd.csproj"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$msCompile"
}
]
Expand Down
11 changes: 11 additions & 0 deletions Vsxmd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ internal string TestGenericParameter<T1, T2>(
/// <returns>Nothing.</returns>
internal string TestBacktickInSummary() => null;

/// <summary>
/// Test space after inline elements.
/// <para>See <c>code block</c> should follow a space.</para>
/// <para>See a value at the end of a <value>sentence</value>.</para>
/// <para>See <see cref="TestSpaceAfterInlineElements"/> as a link.</para>
/// <para>See <paramref name="space" /> after a param ref.</para>
/// <para>See <typeparamref name="T" /> after a type param ref.</para>
/// </summary>
/// <returns>Nothing.</returns>
internal bool TestSpaceAfterInlineElements<T>(bool space) => space;

/// <summary>
/// Test see tag with langword attribute. See <see langword="true"/>.
/// </summary>
Expand Down
19 changes: 15 additions & 4 deletions Vsxmd/Units/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal static string Escape(this string content) =>
/// <param name="href">The href.</param>
/// <returns>The anchor for the <paramref name="href"/>.</returns>
internal static string ToAnchor(this string href) =>
$"<a name='{href}'></a>\n";
$"<a name='{href}'></a>\n";

/// <summary>
/// Generate "to here" link for the <paramref name="href"/>.
Expand Down Expand Up @@ -160,13 +160,13 @@ private static string ToMarkdownSpan(XNode node)
switch (child.Name.ToString())
{
case "see":
return $"{child.ToSeeTagMarkdownSpan()}";
return $"{child.ToSeeTagMarkdownSpan()}{child.NextNode.AsSpanMargin()}";
case "paramref":
case "typeparamref":
return $"{child.Attribute("name")?.Value.AsCode()}";
return $"{child.Attribute("name")?.Value?.AsCode()}{child.NextNode.AsSpanMargin()}";
case "c":
case "value":
return $"{child.Value.AsCode()}";
return $"{child.Value.AsCode()}{child.NextNode.AsSpanMargin()}";
case "code":
var lang = child.Attribute("lang")?.Value ?? string.Empty;

Expand Down Expand Up @@ -223,5 +223,16 @@ private static string JoinMarkdownSpan(string x, string y) =>
private static string ToSeeTagMarkdownSpan(this XElement seeTag) =>
seeTag.Attribute("cref")?.Value?.ToReferenceLink(useShortName: true) ??
seeTag.Attribute("langword")?.Value?.AsCode();

private static string AsSpanMargin(this XNode node)
{
var text = node as XText;
if (text != null && text.Value.StartsWith(" ", StringComparison.Ordinal))
{
return " ";
}

return string.Empty;
}
}
}
Loading

0 comments on commit 4a0a291

Please sign in to comment.