mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
[Question] Syntax re-arrangement #178
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tthiery on GitHub (Jan 2, 2018).
I stumble over an exception in the following process:
The following example:
I had the expectation that I can re-arrange the syntax in step (3) without any issues. Similar what I would do with
Newtonsoft.JsonorSystem.Xml.Linq.Actually the
ContainerInline.AppendChildhas explicit guard preventing adding a child which already has a parent.Is there a reason for this behavior? Is there something we can do here (Cloning? Removing Guards? New Syntax concept? Alternatively, are there utilities to help me utilizing the Span information to retrieve the original text?).
@tthiery commented on GitHub (Jan 2, 2018):
I found a workaround by removing the child from the original tree. Kind of works for now (for me).
Is there any improvements vision on that part of the API? Working with the syntax tree is something quite interesting for me ;)
@xoofx commented on GitHub (Jan 3, 2018):
Yes. It is mainly to make sure that a node cannot be attached multiple times (or even recursively) and also to force an explicit management where you can't move accidentally a node by adding it as a new child of another parent (and implicitly removing it from the previous parent). I had quite a few bugs directly related to this when building markdig and I was happy to have these safeguards.
So the access pattern as you figured out is to remove the node, and add it to somewhere else. To mitigate usage, adding a method like
Movethat does a remove and an append would be fine, PR welcome if you want!