-
Notifications
You must be signed in to change notification settings - Fork 133
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
Inline PUML #968
Inline PUML #968
Conversation
Thanks for working on this. I think the code block thing is a nice trick for us, but it does make the syntax less usable on the author side (to them it seems like an addition that is not intuitive at first look, since it is different from how they use components). Is it possible for us to do this "code block" thing behind the scenes, so that the author does not have to manually do it themselves, while still allowing us to escape it properly for later processing by markdown-it? |
Perhaps something like this?
|
Ok I just went back and read through the old puml PRs and realise the difficulty in doing the "behind the scene" method that I suggested, because of how HTML just generally behaves.
We can explore this way. The HTML tag seems to be rather redundant non-aesthetic wise, if we have to escape the content anyway (which makes it seem un-HTML). |
Checked that this PR resolves: #936 on top of #912. Refactored code to handle both file PUML and inline PUML. Currently inline PUML works well without any new lines. For example, the below inline PUML would render fine:
However, there would be issues when we add newlines in the PUML as codefences are not completely escaped when nested as an immediate children under any element as there would be This behavior is consistent for all codefences when nested under a tag. For example:
will not work properly as well. @yamgent @damithc is this a known issue? Currently I am thinking to improve the behavior by either:
The change here should be minimal in terms of the main logic, but I need to investigate further on how to pass in additional context (cwf, resultPath) and registering widgetHandlers to markdown-it renderer in a more generic way. |
Add an empty line between HTML tag and opening code fence. |
Yes, that workaround usually works, but I think it won't work when we rely on a syntax like below to inject user-input (as with this PR as well):
This is also discussed #473 (comment). Was wondering whether it is a design choice/known issue to use this workaround? I guess if so, do you think it might be better to inject context (user-input) through the markdown-it-attr? |
You mean the following doesn't work?
It is in the GitHub Flavored Markdown Spec: https://github.github.com/gfm/#example-157
|
Huge thanks for pointing that out. Leave a space does not work out of the box. I added a additional handler to make it work. static extractAndGenerateCodeBlock(element, codeLanguage = '') {
let codeBlockElement;
element.children.forEach((child) => {
if (child.name === 'pre') {
const nestedChild = child.children[0];
[codeBlockElement] = nestedChild.children;
codeBlockElement.data = `\`\`\`${codeLanguage}\n${codeBlockElement.data}\n\`\`\``;
}
});
return codeBlockElement;
} This is because when leaving a space, initial md.render has already rendered the code fence as This keeps the behavior consistent as described https://github.github.com/gfm/#example-157 and also allows us to add additional context as well. What do you think about this approach? If it is okay, I would proceed to refactor, add more edge case handling, additional tests and user guide for this. |
Can we try approach 2 instead? |
I'm on the fence for both approaches.
While approach 2 is less verbose, approach 1 is a more familiar way to add user-input rather than introducing markdown-it-attr for components (especially when comparing inline and src puml). |
48145c8
to
1e5d0b0
Compare
Ready for review. Keeping this PR simpler as it primarily aims to resolve #936 and #912. Future work: I explored adding |
Hi @crphang, It seems to be pretty feasible for both htmlParser2 and markdown-it. The essential idea is to treat these tags the same way these parsers treat Its in a very early stage though, so if this gives you some ideas on how to do so, do let me know if you want to do it instead! |
Hey @ang-zeyu, such an API would definitely help! One of the main problems I faced with plugins was that it introduced quite a bit of side effects, and we dont have as much control over the components as we do in parser. I don't exactly think that introducing new diagrams will require "polluting" preprocess going forward. Definitely like your work on componentParser and refactoring preprocess. For adding new widgets, im looking to abstract it more and adding preprocess/parse handlers to each widget (will be in the scope of another PR #984) Could you share the branch? I could take a further look. My current belief is that widgets as defined going forward are more easily maintained and beneficial for us developers to provide official supported components. Plugins offer extensibility in user defined components and functionality. |
Sure, i'll try to clean it up and push a functional one for htmlparser2 over tonight |
ang-zeyu@3f1e5dc These are the changes to htmlparser2 required roughly ( still very much a WIP, but it works for simple use cases like It should be much simpler for markdown-it due to its plugin system and use of regex patterns In addition to this, what needs to be added would be
Hmm, reason I mentioned this was because I saw changes were needed in your code to We can alleviate this with something like #1026, but I feel its better to provide a sufficiently robust and consistent api to plugins which should make plugin development easier. This would also consolidate all optional functionality in plugin files, rather having such optional functionality coupled to the internal processes of
Plugins certainly don't have as much control, but we can always add more to the api cautiously when really needed. ( such as "escaping" text inside the certain tags like this PR ) I'm not really aware of any side effects though 😮 I think this is one of the main benefits of a plugin system, where plugins may only interact with the provided Just my 2 cents though, might be good to get some more opinions in 😄 |
What I meant was that the manipulation of the DOM is rather orthogonal from the main parsing process with plugins.
Yes, certainly not a good idea to keep adding to the core logic. I just made a refactor to make it clearer what I was trying to achieve going forward. Looks really good if it properly escapes from htmlParser and we can go with:
Certainly something we could explore further. Any rough estimate how long it would take for that POC to be completed? I am thinking of decoupling the two PR. I believe that the user experience without using code blocks to escape content will be better, but would want to start adding the other components. Perhaps we could add this change without modifying the user guide (since the changes are not backward compatible), so that other components in #984 have something to build on since both are rather pluggable. And migrating back to plugins once it is tested should not be too difficult. |
Just looked at your refactor, I think I have a better idea now, thanks! I'm all for this as well, I think it'd be good to have plugins tie in directly to the per element Since its a major architectural addon for plugins, might be really good to have more opinions in first though @yamgent @acjh @openorclose @yash-chowdhary
Just to clarify this, would the user still be able to turn off widgets eventually ( site config )?
It should take about a week |
Resolves #912
Extremely raw implementation here. This also breaks existing PUML which will be addressed in later commits.
Here's a demo:
Problems with current implementation:
puml
tags.Going forward:
This fits in nicely considering fenced block already handling other special types of content like diffs: