Skip to content

Commit

Permalink
Fix update relative paths in anchor links
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelDomingues committed Apr 3, 2024
1 parent a2acdbf commit 67e2b03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MarkdownLocalize.Markdown/MarkdownParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MarkdownParser

public static RendererOptions Options = new RendererOptions();
private static string REGEX_IMAGE = @"(!\[[^\]]*\]\()(.*?)\s*('(?:.*[^'])')?\s*(\))";
private static string REGEX_LINK = @"(\[.*?(?=\]\()\]\()(.*?)\s*('(?:.*[^'])')?\s*(\))";
private static string REGEX_LINK = @"(\[.*?(?=\]\()\]\()(?!#)(.*?)\s*('(?:.*[^'])')?\s*(\))";

public static void SetParserOptions(RendererOptions newOptions)
{
Expand Down
16 changes: 16 additions & 0 deletions test/MarkdownLocalize.Tests/TranslateMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,20 @@ public void AllRelativePath()
[http url](https://www.github.com)".ReplaceLineEndings(), md.ReplaceLineEndings());

}


[Fact]
public void AnchorLinksNoReplace()
{
MarkdownParser.SetParserOptions(new RendererOptions()
{
LinkRelativePath = "../",
});
var catalog = POT.Load(ReadPO("headings.pt-PT.po"));
TranslationInfo info;
string md = POT.Translate(catalog, @"[url](#anchor)", null, null, true, false, new string[] { """ }, out info);

Assert.Equal(@"[url](#anchor)".ReplaceLineEndings(), md.ReplaceLineEndings());
}

}

0 comments on commit 67e2b03

Please sign in to comment.