Add seemingly functional Markdown link support

- Issue MatterHackers/MCCentral#3726
This commit is contained in:
John Lewin 2018-06-23 10:24:09 -07:00
parent 847bdf73dd
commit 20b612f9e0
2 changed files with 37 additions and 7 deletions

@ -1 +1 @@
Subproject commit b22228763c87cb90dab2055a1f0a42b9f1597fc5
Subproject commit f38d68ae2c71343c909b43c7a497ed8bf1a7d23a

View file

@ -18,14 +18,43 @@ namespace Markdig.Renderers.Agg.Inlines
{
public class TextLinkX : FlowLayoutWidget
{
public TextLinkX()
private LinkInline linkInline;
public TextLinkX(LinkInline linkInline)
{
HAnchor = HAnchor.Fit;
VAnchor = VAnchor.Fit;
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit;
this.Cursor = Cursors.Hand;
this.linkInline = linkInline;
}
public override void OnClick(MouseEventArgs mouseEvent)
{
if (linkInline.Url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
ApplicationController.Instance.LaunchBrowser(linkInline.Url);
}
else
{
// Inline link?
Debugger.Break();
}
base.OnClick(mouseEvent);
}
public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
{
if (childToAdd is TextWidget textWidget)
{
// Mark with underline if any character data exists
textWidget.Underline = textWidget.Text.Trim().Length > 0;
}
// Allow link parent to own mouse events
childToAdd.Selectable = false;
base.AddChild(childToAdd, indexInChildrenList);
}
}
@ -36,8 +65,9 @@ namespace Markdig.Renderers.Agg.Inlines
public ImageLinkSimpleX(string url)
{
HAnchor = HAnchor.Fit;
VAnchor = VAnchor.Fit;
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit;
this.Selectable = false;
var imageBuffer = new ImageBuffer(icon);
var imageWidget = new ImageWidget(imageBuffer);
@ -154,7 +184,7 @@ namespace Markdig.Renderers.Agg.Inlines
}
else
{
renderer.Push(new TextLinkX()); // hyperlink);
renderer.Push(new TextLinkX(link)); // hyperlink);
renderer.WriteChildren(link);
renderer.Pop();
}