Comments (6)
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.
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.
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.
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.
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.
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)
- Translate position from rendered HTML to markdown HOT 1
- Question: Having code blocks show in blocks HOT 4
- Roman Numeral V (5) is not computing correctly HOT 1
- Add support for GitHub Markdown Alerts HOT 3
- PipeTableParser strip opening and ending characters HOT 1
- Using context for extensions HOT 4
- Can I somehow customise math processing? HOT 3
- AlertBlock content not rending properly HOT 3
- Feature-request: Use bootstrap alerts for alert blocks HOT 1
- [Bug?] Possible incorrect parsing in markdig HOT 2
- Support YouTube Shorts embedding
- block certain components?
- How to remove things like CodeBlocks from ToPlainText rendering HOT 2
- Incorrect span calculation for math inline HOT 1
- Single `+` in superscript or subscript
- Conversion to HTML does not convert some hyperlinks HOT 2
- Comparing MarkdownDocuments when one has been appended to
- Style rendering is incomplete HOT 1
- Is
- Is there any way to get AutoIdentifiers list? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdig.