-
Notifications
You must be signed in to change notification settings - Fork 275
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
pegdown markdownToHtml and LinkRenderer class replacement in flexmark java #105
Comments
@rkanumola, the first part is here: static final MutableDataHolder OPTIONS = PegdownOptionsAdapter.flexmarkOptions(
Extensions.ALL - (headerLinks ? 0 : Extensions.ANCHORLINKS)
- (hardwrap ? 0 : Extensions.HARDWRAPS) + (allowHtml ? 0 : Extensions.SUPPRESS_ALL_HTML)
).toMutable()
// set additional options here:
//.set(HtmlRenderer.FENCED_CODE_LANGUAGE_CLASS_PREFIX,"")
;
static ArrayList<Extension> extensions = new ArrayList<Extension>();
static {
// add your extra extensions here
//extensions.add(ConfluenceWikiLinkExtension.create());
for (Extension ext : OPTIONS.get(Parser.EXTENSIONS)) {
extensions.add(ext);
}
OPTIONS.set(Parser.EXTENSIONS, extensions);
}
static final Parser PARSER = Parser.builder(OPTIONS).build();
static final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
// use the PARSER to parse and RENDERER to render with pegdown compatibility
static {
Node document = PARSER.parse(data);
processed = RENDERER.render(document);
} What does your ConfluenceWikiLinkRenderer do that is different from GitHub Wiki links? You can use the code above which will have wiki links enabled and will convert To have custom link resolving logic added you need a custom link resolver. For example see: PegdownCustomLinkResolverOptions An overview of parsing and rendering phases with available extension points can be found in the wiki: https://github.com/vsch/flexmark-java/wiki/Writing-Extensions |
@rkanumola, sorry forgot I added parameters for extra pegdown options adapter extensions. Shorter version of above: static final MutableDataHolder OPTIONS = PegdownOptionsAdapter.flexmarkOptions(
Extensions.ALL - (headerLinks ? 0 : Extensions.ANCHORLINKS)
- (hardwrap ? 0 : Extensions.HARDWRAPS) + (allowHtml ? 0 : Extensions.SUPPRESS_ALL_HTML)
// add your extra extensions here
//, new ConfluenceWikiLinkExtension()
).toMutable()
// set additional options here:
//.set(HtmlRenderer.FENCED_CODE_LANGUAGE_CLASS_PREFIX,"")
;
static final Parser PARSER = Parser.builder(OPTIONS).build();
static final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
// use the PARSER to parse and RENDERER to render with pegdown compatibility
static {
Node document = PARSER.parse(data);
processed = RENDERER.render(document);
}
|
@vsch , thank you so much for the response,with your suggestion I was able to resolve my issue. I have one more doubt. Currently I am using the following classes in my implementation. in pom.xml if I use flexmark or flexmark-all artifact my total plugin artifact size has been increased from 13.2 MB from 1.6 MB, because of this installing the add-on also taking much time than earlier. am I using the right dependency ? Please suggest.
Update: I am not sure what happen, wiki links are stopped working all of a sudden it used to work with the above shared code till today morning. Can you have any pointers on that? The following code which I have integrated in my implementation.
|
@vsch , can we have your response on the above issues please ? |
@rkanumola, the size increase is caused by a dependency on |
@vsch , thanks for the response on the artifact size related query. |
@rkanumola, I tested a wiki link in sample code and it is parsing and rendering as expected. Can you provide a sample of Markdown with Wiki links that is not working? Best if you output the value of the |
@vsch , I have consolidated my rendering problems which are identified the reason for migrating from pegdown to flexwork. pegdown-flexmark-migration-issues.docx Please let me know if anything is not clear or need any other details for your analysis. |
@vsch , can you please provide your suggestion to move forward with our migration from pegdown to flexmark. We are one of the vendors of Atlassian's Confluence add-ons. Need to deliver the migrated artifact at the earliest as possible. Let me know if you need any other details. |
@rkanumola, thank you for the discrepancy document. I am going through the document and will open separate issues for each one I encounter. As a general comment it would be easier to address the issues if the differences were isolated in a relevant sample. For example, image title tag missing bug in image link reference. The only significant part is: ![alt text][id]
[id]: /images/icons/up_16.gif "Title" Actual: <p><img src="/images/icons/up_16.gif" alt="alt text" /></p></div></p> Expected: <p><img src="/images/icons/up_16.gif" alt="alt text" title="Title" /></p> Much easier to understand without all the noise of unrelated markdown and HTML that is in the document. Also the summary of "Missing title tag" to direct attention would help. ### Images ###
Image syntax is very much like link syntax.
Inline (titles are optional):
![alt text](/images/icons/up_16.gif "Title")
Reference-style:
![alt text][id]
[id]: /images/icons/up_16.gif "Title" Actual: <p><div class="markdown-macro conf-macro output-inline" data-hasbody="true" data-macro-name="markdown" id="markdown-macro-1"><h3 id="Images">Images</h3>
<p>Image syntax is very much like link syntax.</p>
<p>Inline (titles are optional):</p>
<p><img src="/images/icons/up_16.gif" alt="alt text" title="Title" /></p>
<p>Reference-style:</p>
<p><img src="/images/icons/up_16.gif" alt="alt text" /></p></div></p> Expected: <p>
<div id="markdown-macro-1" class="markdown-macro conf-macro output-inline" data-hasbody="true" data-macro-name="markdown">
<h3 id="Images">Images</h3>
<p>Image syntax is very much like link syntax.</p>
<p>Inline (titles are optional):</p>
<p><img src="/images/icons/up_16.gif" alt="alt text" title="Title" /></p>
<p>Reference-style:</p>
<p><img src="/images/icons/up_16.gif" alt="alt text" title="Title" /></p>
</div>
</p> |
@rkanumola, my bad on the image ref. Just found that the simple case works but the complex one does not. Debugging it now to see what is causing it. |
@rkanumola, #109 updated. Bug confirmed and fixed for next release. As for Wiki Links the Wiki links extension requires that you add a LinkResolver to handle your link resolution for Wiki links which are implementation dependent. I will add the link and information to the extension docs. See: PegdownCustomLinkResolverOptions You will need to proved code that handles Confluence handling of the wiki link content. |
@rkanumola, repo updated. Maven released, may take time for central to update. |
@vsch , thanks for your responses. as request I am here with attached our Confluence Wiki links implementation by using pegdown for your reference. The following class used to call as mentioned in the first message. I will use the latest artifact and give you an update after using it. Thanks again for the work done so far.
|
@vsch , Thanks for #109 fix, I have verified the fix and found it is working as expected now. Regarding the Wiki links and other headerLink issues can I have your pointers please ?. I have shared the required data for wiki link for your debug analysis information in the last comment. Do we have any existing samples which meets our requirement by using LinkResolver ? |
@rkanumola, pegdown does not resolve wiki links as you have shown. This is probably done in the You need to take the logic from it and convert it to a flexmark-java link renderer for Wiki link nodes. Sample given above PegdownCustomLinkResolverOptions you should add your logic in the |
Thanks @vsch for your suggestion, I trying to change as much as possible but still not able to get there. Any smart way of converting our custom class to flexmark link render format? Your help is much appreciated in this regard. |
@rkanumola, where did you get the confluence renderer and why can't you convert the renderer to flexmark? Original pegdown library does not come with a confluence renderer so I am assuming it is your custom code. You can almost copy/paste logic from the custom renderer into the flexmark with the change that in flexmark there is a single method to map URL text to resolved link with the node type used to distinguish the source node while in Pegdown renderer there is a method per node element. The sample has the Which part is giving you difficulty in the conversion? |
@vsch , Thanks for responding. I am herewith attaching the difficulties I am having in converting our custom class to get the wikilinks work. Please help me in this regard. Let me know if anything is not clear in the document. Thanks |
@rkanumola, screenshots of the code for your custom confluence renderer is impossible to see in the doc. The compilation errors are caused by pegdown API references. When you migrate the logic of the class to a flexmark custom node resolver then the issue will be resolved.
In the future could you please copy/paste the valid information into the issue directly, rather than include a separate document. That way it will be easier to follow. You can paste images directly into comments or drop them as files. |
@vsch , thank you so much for the response. I am applying your suggestions, will keep you updated. |
@vsch, I am getting few issue while replacing my customwiki link logic to our flexmark LinkResolver. Problem is that in my customwikilink implementation I was able to pass XhtmlContent and MacroInfo as an arguments with the render override method of LinkRenderer Pegdown API, but in our case I am not able to instantiate, which are most important parameters in my custom implementation where I will pass those two parameters to my utility method(ScriptUtil) which will return me the rendered href wiki link. i.e converting storage format hyper link ac:link<ri:page ri:content-title="home" /></ac:link> to actual anchor tag to use i.e a href="/display/markdown/Home">home [Removed < tag intentionall so that it will not render as a link] I am trying to give you the existing implementation and current implementation as per your suggestion. Please take a look into it and give your inputs on it. Please let me know if anything is not clear. Existing Custom Wiki Link Implementation: `public class ConfluenceWikiLinkRenderer extends LinkRenderer {
}` Current Implementation As per your suggestion - Yet to finish And its implementation so far as ..
I am also attaching sample outputs from pegdown to flexmark migration as of now for wikilink for your reference. |
Hi @vsch, I work with @rkanumola. Thanks much for your help so far! |
@sunitapatro, you can pass any information you want through options If you re-use the parser and html renderer instances and need to change options for each invokation of html renderer, you can pass it using the Define your own
Then pass it in the
In your link resolver or anywhere in the rendering process you can get this data through the document node:
A sample source of this is available at CustomContextDataSample |
@vsch , we are almost done with the migration with the continuous support from you. For the below input we are observing the different output when compare to pegdown and flexmark. Attached the resultant values for your reference, we would like to know is there anything missing from end which is resulting in the different anchor tag text? Another query is that when we give the input for the special characters We always see that single quote always converting Single Quote as an Apostrophe. Please check this issue as well. Thanks in advance. |
@rkanumola, it appears that you need to change the link text for wiki links. You need to add a custom link renderer for wiki links. You can make a copy of the renderer from WikiLink extension and modify it to handle wiki link text changes. As for the single quote to apostrophe change, this is done by the pegdown |
@vsch , regarding custom link renderer for wiki links we have implemented as per your suggestions followed in CustomContextDataSample, looking for whether equivalent pegdown output is available in flexmark as mentioned above or this is how the flexmark will return the output ,would like to clarify. I will try out Extensions.SMARTS option and update you on that. |
@rkanumola, actually more thought about the typographic extension and wiki links leads me to think that converting single quote to apostrophe is a bug wiki link renderer should convert the wiki link text to non-typographic original characters before using the text to derive the page reference text. Wiki link text is both a page reference and link text. In this case the typographic extension converted text should be used for the link text but the original should be used for the page reference to make the rendering make sense. I will make a fix for this. The rest of the behaviour is as expected. I don't understand why under pegdown |
@rkanumola, I double checked and the current implementation already handles the typographic conversion only for the link text part, not the page ref part. To disable this conversion for the link text you should remove the |
Hi,
I am looking for the replacement for the following logic in flexmark java, can you please suggest?
And also for one of our other requirement we are extending LinkRenderer.java of pegdown for Confluence WikiLink Renderer implementation. Can we have a replacement for this one as well?
Currently we are getting compilation errors for
Rendering, WikiLinkNode
classes if we migrate from pegdown to flexmark java.Please help us resolve these issue would be greatly appreciated. Let me know if anything is not clear.
Thanks
RK
The text was updated successfully, but these errors were encountered: