question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Assistance Request] AutoLinks and Images Not Working

See original GitHub issue

Issue

First off, let me start by saying that from what I can see in the sample app, this control is amazing - literally exactly what I need.

I am having some issues with getting my markdown to render correctly - I am using databindings to display the information, so I don’t know if that is the culprit or not. The markdown itself displays, and some of the extensions work (e.g. pipe tables), but not all of them. Specifically:

  • AutoLinks: the text is underlined, but is not rendered as a clickable link
  • Images: I am getting an error: Exception = Invalid URI: the format of the URI could not be determined. I have a feeling that this may be related to #9
  • Super/Sub Script: Text is rendered at normal height

For posterity, my code snippets are below:

View

The Markdown property is bound to the Contents value (typeof string) of the SelectedItem of a list in another control; Pipeline is bound to a MarkdownPipeline that is created in the ViewModel. As stated above, the Contents renders in the MarkdownViewer, just without some extensions working properly.

<wpf:MarkdownViewer 
      Markdown="{Binding ElementName=userGuidePagesListView, Path=SelectedItem.Contents}"
      Pipeline="{Binding MarkdownPipeline}" />

ViewModel

The Contents property is set by extracting the data from embedded resources files to a string

public class UserGuideViewModel : ViewModelBase
{
  public MarkdownPipeline MarkdownPipeline = new MarkdownPipelineBuilder()
      .UseAdvancedExtensions()
      .UseEmphasisExtras()
      .UseAutoLinks()
      .UseEmojiAndSmiley()
      .Build();

  private List<UserGuidePage> _userGuidePages = new List<UserGuidePage>();
  public List<UserGuidePage> UserGuidePages
  {
    get { return _userGuidePages; }
    set
    {
      if (_userGuidePages != value)
      {
        _userGuidePages = value;
        RaisePropertyChanged("UserGuidePages");
      }
    }
  }

  public UserGuideViewModel()
  { RenderUserGuidePages(); }

  private void RenderUserGuidePages()
  {
    UserGuidePages = new List<UserGuidePage>();
    string[] delimiter = new string[] { "UserGuide." };
    string[] markdownFiles = assembly.GetManifestResourceNames();
    foreach (string resource in markdownFiles)
      {
        if (resource.Contains("UserGuide") && resource.Contains(".md"))
        {
          UserGuidePage userGuidePage = new UserGuidePage();
          userGuidePage.Title = resource.Split(delimiter, StringSplitOptions.None)[1].Split('.')[0].Replace("-", " ");
          userGuidePage.Contents = GetPageContent(resource);
          UserGuidePages.Add(userGuidePage);
        }
      }
    }
  }

  private string GetPageContent(string resource)
  {
    using (Stream stream = assembly.GetManifestResourceStream(resource))
    {
      using (StreamReader streamReader = new StreamReader(stream))
      { return streamReader.ReadToEnd(); }
    }
  }

Screenshots (Annotated)

Screenshots below; I am also using the same markdown files for the Wiki on GitHub, and have included the links to those pages so that proper rendering can be viewed

Home

Using the Software

Change Log

Thank you in advance for the help!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amkuchtacommented, Oct 18, 2017

@Kryptos-FR I found all of them yesterday afternoon and ended up overriding them all (h1-h6, code blocks, etc.). This truly is an amazing control, thank you again for creating it and sharing it out with the world.

As a side thought, have you considered “partnering” with another control library to get the word out about the MarkdownViewer? I use MahApps.Metro for all of my styling, and one of the maintainers (@thoemmi) pointed me your way. If he and @punker76 agree, I think that the community at large would benefit from having your control mentioned in their readme file. On your end, it may help get some visibility, which means more contributors and a product that grows to full maturity a bit faster.

@punker76, @thoemmi, MarkdownViewer seems to be MA.M compatible - I was able to override all of the styles using MA.M keys (even going so far as to style the Checkboxes in the task list to match MA.M styles). How would you feel about providing a shoutout, similar to what you have done with LoadingIndicators.WPF and Dragablz?

0reactions
Kryptos-FRcommented, Jan 24, 2018

@amkuchta Which version of the package are you using? The issues with images have been fixed already. For example the sample app Markdig.Wpf.SampleApp already benefits from it. Check the location where the images get copied and verify that the relative path to the executable is correct.

The support for superscript and subscript has been added thanks to a contribution by @thoemmi (see #11 ). You need to activate the corresponding extension (which is already the case by default):

new MarkdownPipelineBuilder().UseEmphasisExtras().Build();

<sup> and <sub> have nothing to do with Markdown. It is pure HTML, which is why it works in GitHub flavored markdown. The proper syntax for to use ^ and ~ instead. Pure HTML should be considered deprecated in any markdown flavor because it does not work if the document needs to be rendered to something else than HTML (which is the case here). I don’t want to parse any HTML tag after Markdig library has done its job as it could get messy. Maybe it is a suggestion to do for Markdig itself. Ask @xoofx what he thinks about that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TinyMCE 4 imagetools not working for remotely stored ...
My application is an HTTPS webapp, but I was loading an external image in the editor via HTTP which was throwing a warning...
Read more >
Autolinked references and URLs
References to URLs, issues, pull requests, and commits are automatically shortened and converted into links.
Read more >
Why don't PDF links work. This is a serious problem
Solved: We develop output with URL links in PDF's that work great (as advertised) on desktops, but don't work on mobile (ios &...
Read more >
How to disable the autolink feature throughout a course?
I work at a small university and run several moodle sites for my classes. I would like to disable the auto link feature...
Read more >
Why are Hyperlinks not Working in PDF? Fix it!
Do you want to know why the hyperlinks did not work in PDF? This article explains the reasons and also provides you with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found