Replies: 3 comments 1 reply
-
I've discovered that I need to add a Text child node to get an actual heading to show up:
So it seems that the answer to my first question is -> I just don't understand the AST model completely. That will come with time I suppose (unless the model is documented somewhere that I don't know about). I would still love to see an example, even a partial or less-than-perfect example of building a Document with paragraphs, lists, headings, and bold text. Something with embedded HTML would be really awesome. (I'll try to develop this myself and post it when I get something working) For now:
will produce
|
Beta Was this translation helpful? Give feedback.
-
@dstovall, I don't think creating the AST to then create markdown is an efficient approach. The AST tracks the source position, so it is geared towards creating it from a single character sequence. It has a lot of intricacies in terms of child nodes, which the parser creates. Doing it by bit-banging on the classes is error prone and frankly too painful. Why not just output your markdown to a You can always take your generated markdown text and parse it, then render it using the As an alternative, you can use |
Beta Was this translation helpful? Give feedback.
-
@dstovall, thank you for the clarification. You are doing it the easiest way. Letting the parser handle the heavy lifting of creating the AST. You can parse the original document, then use the AST to find the offset(s) to insert/replace text, but keep in mind, the text may need to be properly indented before insertion, to make sure it will parse properly. This is a lot more complicated that would seem at first glance. If inserting AST from one document into another works, then it is the easiest and most reliable way to do it. Formatting it to a string, should take care of all the indentations, bugs not withstanding. If you have specific use cases, which I can use to test code, please let me know. The ability to swap AST sections is an interesting use case and once I have brought the library up to functional again, I will take a look at that. However, the only way to get a clean AST after swapping is to format to string and reparse the result, so all nodes are based on the same source text. What do I mean by functional? Travis CI is now a paid service. With my old account gone, I have to set up GitHub workflows for CI builds. I also want to migrate the builds to Gradle from Maven, go through the PRs and merge ones that still apply, update to more recent CommonMark spec. |
Beta Was this translation helpful? Give feedback.
-
I've got a data set that I would to render as Markdown.
My naive approach is to use Parser to get a Document instance, append some new Nodes to it, then use Formatter to render it as Markdown:
expecting something like:
Instead, I get an exception. :/
After adding various permutations of
setCharsFromContent
, I can get formatted to render like this:So, three questions really:
Beta Was this translation helpful? Give feedback.
All reactions