Giter VIP home page Giter VIP logo

Comments (6)

NetTecture avatar NetTecture commented on June 3, 2024

ok, this seems not to work at all - and the little documentation that there is is never high level.

I try to isolate links and put them back using references..

My current code:

    foreach (var node in document.Descendants())
    {
        if (node is LinkInline link)
        {
            //var linkText = link.FirstChild.ToString();
            var referenceKey = Guid.NewGuid(); // Generate a unique reference key



            LinkReferenceDefinition ldr = new LinkReferenceDefinition(referenceKey.ToString(), link.Url, link.Title);
            document.SetLinkReferenceDefinition(referenceKey.ToString(), ldr, true);

            var newlink = new LinkInline()
            {
                Title = link.Title,
                Reference = ldr,
                LinkRefDefLabel = link.Label,
            };
            // Copy the text (children) from the original link to the new link
            var children = link.ToArray();
            foreach (var child in children)
            {
                child.Remove();
                newlink.AppendChild(child);
            }
            link.ReplaceBy(newlink);
        }
    }

results in links being replaced with [] - no url inside, no reference group being written to the end. What am I doing wrong? To my understanding creating a new link and putting it in place of the old one is the way to go, and as I re-hook the content (child) - that should also work?

I tried the documentation, but there is only it seems a property by property without any higher-level explanation or examples, so one is left to - not even sure what. I do not even understand why the LinkRefrerenceDefinition is not rendered at the end - it IS in the document.

from markdig.

xoofx avatar xoofx commented on June 3, 2024

I need to import a markdown document (thousands actually) and extract all the links so they can be maintained separately.
probem is- what do I replace them with if I then add the references? I have the key - i Just have no idea what to put there.

Both statements are confusing. What is the link between the two? Extracting links in the document is one problem. But you are also saying that you are rewriting the document. Is it for generating HTML or to generate back Markdown? This is not clear.

from markdig.

NetTecture avatar NetTecture commented on June 3, 2024

I am generating markdown back - the issue is that I am extracing the links because it is easier to then replace them.

This is for moving documents into a complex autonomous storage system. THe document (in markdown) comes in with a link. By taking the link OUT and putting them into a reference, WHILE doing that I can as well write it into a database , then, when actually writing the document into the database, write it without the link references. Upon generating for output, the then CURRENT links (the URL's they point to may change) are easily reconsstructed. The business problem here is that the input markdown is in one language, but the otuput system must handle references to translated langauges - which all have their own URL, hence the target URL is put in when presenting.
All that, though, is imho quite irrelevant to the problem. The problem is taking inline links and moving them so that they are link references in the output which are then - when the final HTML is generated - has the reference part reconstructed by the database.

from markdig.

xoofx avatar xoofx commented on June 3, 2024

Looking at the code, LinkReferenceDefinition (and its group) are not well supported for roundtrip. It would require quite some work to support them. Workaround is to generate the reference definition by yourself at the end, as you collect the links, you can generate this to Markdown. It should not be much work.

from markdig.

NetTecture avatar NetTecture commented on June 3, 2024

Well, I have no problem dumping the reference definitions myself - but my problem is that I have no idea how to get the LINKS to show them. Remember, Links that refer to references are in [], not in () - and I totally fail to genrate a link that does emit the proper reference code.

from markdig.

xoofx avatar xoofx commented on June 3, 2024

This is the renderer used for generating back top Markdown.

You have to look at this file to see what you should modify on a LinkInline. For example, the Title or the url and most of other properties that you are using were only meant for HTML processing. Later a bunch of other properties were added to cover the case of exact roundtrip.

So, yeah, it's messy but there is no other way than to sneak around in the codebase to see how to use this. It was not designed in the first place to support this scenario. I never had a personal incentive to do it, so the person that brought it did his best for his use case, but it's far from perfect. Doing it properly would require a major refactoring/redesign of Markdig, and who wants to do that? It is multiple weeks of fulltime work, and as this project is OSS, you know, that's what you get for free.

from markdig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.