-
-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider allowing Nodes with a "fragment" type. #558
Comments
Okay, I just realised there is an |
So, even with
Not sure why. |
Okay, I found the problematic code: // ensure final newline
if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
cmark_strbuf_putc(renderer.buffer, '\n');
} I believe we should only invoke this if the top level node is a block. |
So there are probably two issues here:
|
The renderer is designed to ensure that the output produced by cmark ends with a newline. Unix text files are supposed to end with a newline. The Isn't it easy enough to strip off the newline in your application? |
As you said yourself, in some cases the newline is semantic, so I'm not sure stripping it off arbitrarily is a good idea. The goal of a fragment is to be able to inject it correctly into existing markdown, e.g. moving a title text into a list item: node = Markly.parse("# My Title")
# Extract a fragment:
children = node.extract_children
puts "- #{children.to_markdown}" Introducing an inline fragment type would probably be a straight forward and compatible way of making this possible, and has the correct semantics for "not a complete document". In other words, it would make sense for the |
Yes, that's true, you might e.g. have a line break element which would render as I'm pretty sympathetic to your request, but I'll need to dive into the details when I get time. |
If you tell me your preferred approach I can create a PR. |
I'm not sure about the details without looking at the code. But the rough idea I'd have prior to that would be:
If you want to fool around with it I'd definitely consider a PR (though no guarantees at this point that I'd merge it). |
I'm interested in manipulating markdown ASTs.
It's sometimes problematic to extract a fragment, e.g.
I'm having trouble with the output formatting.
Ideally, the fragment would just be the raw children, e.g.
This would make it a little easier to mash up the AST with different types of outputs.
I suppose the issue is the formatting of
custom
type nodes, but I'm not sure if there is a problem to change this.In other words, either (1) we could change the output to be "inline" or add an inline "fragment" node type which does minimal formatting. Thoughts?
The text was updated successfully, but these errors were encountered: