Skip to content
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

Add markdown extension #92

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Add markdown extension #92

merged 1 commit into from
Jul 8, 2024

Conversation

mcruzdev
Copy link
Member

@mcruzdev mcruzdev commented Jun 25, 2024

Fixes #91

@mcruzdev
Copy link
Member Author

Hi @ia3andy, this is the first draft, to see if I am on the right path

@ia3andy
Copy link
Contributor

ia3andy commented Jun 26, 2024

This looks good right @mkouba ?

@ia3andy
Copy link
Contributor

ia3andy commented Jun 26, 2024

Could you add this test:

<h1>some html</h2>

{#md}
# Hello markdown

Here is a list:
{#for item in items}
* an {item} as a list
{/for}

<a href="/path">some {html} in the markdown</a>
{/md}

Copy link
Contributor

@mkouba mkouba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's a great start!

pom.xml Outdated
@@ -15,6 +15,7 @@
<module>deployment</module>
<module>runtime</module>
<module>docs</module>
<module>qute-web-markdown</module>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call the module just markdown.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qute-markdown?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for markdown as the module directory name and the current quarkus-qute-web-markdown as the artifact id.

I will send a PR with the core dir where the runtime and deployment modules will be moved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it
+1

qute-web-markdown/deployment/pom.xml Outdated Show resolved Hide resolved
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.22.0</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commonmark is a dependency of quarkus-qute-web-markdown so there's no need to add it here. BTW this version should be in the <properties> of the quarkus-qute-web-parent's pom.xml.

import io.quarkus.qute.SectionHelper;
import io.quarkus.qute.SectionHelperFactory;

@EngineConfiguration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you place this annotation on the Factory class then the QuteMarkdownConfigurator is superfluous.

If you do that, then the Factory class has to declare a no-args constructor (passing the CommonMarkConverter?).

qute-web-markdown/runtime/pom.xml Outdated Show resolved Hide resolved
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute-deployment</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this extension will be used without qute-web. Technically, it can be used standalone but it might make more sense to depend on quarkus-qute-web instead?

Copy link
Contributor

@ia3andy ia3andy Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the lowest working dependency (if that make sense) so it's alright

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that:
(1) it's not very consitent because this extension lives in quarkus-qute-web but does not depend on the core module (which is not moved yet -> runtime and deployment modules in the root dir should go in the core dir; will send PR later today)
(2) in many cases you will have to declare both quarkus-qute-web and quarkus-qute-web-markdown 🤷

@mcruzdev
Copy link
Member Author

Could you add this test:

<h1>some html</h2>

{#md}
# Hello markdown

Here is a list:
{#for item in items}
* an {item} as a list
{/for}

<a href="/path">some {html} in the markdown</a>
{/md}

Probably this one will fail 😆

@mcruzdev
Copy link
Member Author

Thank you for all your comments, I will take a look here

@mcruzdev
Copy link
Member Author

mcruzdev commented Jun 26, 2024

Hi @mkouba and @ia3andy, actually when we are using this one:

  <h1>Quarkus and Qute</h1>
  {#md}
  # Qute and Roq
  Here is a list:
  {#for item in items}
  - an {item} as a list item
  {/for}
  {/md}

We are getting:

<h1>Quarkus and Qute</h1>
<h1>Qute and Roq</h1>
<p>Here is a list:</p>
<ul>
<li>an</li>
</ul>
<p>apple</p>
<p>as a list item</p>
<ul>
<li>an</li>
</ul>
<p>banana</p>
<p>as a list item</p>
<ul>
<li>an</li>
</ul>
<p>cherry</p>
<p>as a list item</p>

I think that the expected behavior is:

  1. Resolve{#for} (more specific section);
  2. Resolve {#md} with {#for} result;

In other words, resolve all sections inside the markdown first. I am new to qute API, do you know how to solve this one?

@mkouba
Copy link
Contributor

mkouba commented Jun 27, 2024

In other words, resolve all sections inside the markdown first. I am new to qute API, do you know how to solve this one?

@mcruzdev Your code looks good. I think there's some problem with line separators or something like that. What does the content passed to the MarkdownConverter look like?

@mkouba
Copy link
Contributor

mkouba commented Jun 27, 2024

Ah, I see where the problem is. You need to first collect all the results and then apply the converter:

    public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
        return context.execute().thenCompose(rn -> {
            StringBuilder sb = new StringBuilder();
            rn.process(sb::append);
            return CompletedStage.of(new SingleResultNode(markdownConverter.convert(sb.toString())));
        });
    }

@mkouba
Copy link
Contributor

mkouba commented Jun 27, 2024

By the way, you don't need a QuarkusUnitTest to test the functionality of the section itself. A simple unit test would be enough:

public class MdTest {
    @Test
    public void testMd() {
        Engine engine = Engine.builder().addDefaults()
                .addSectionHelper(new MarkdownSectionHelper.Factory(new CommonMarkConverter())).build();
        assertEquals("...", engine.parse("{#md}...{/md}").data("items", List.of("apple", "pie")).render());
    }
}

@mcruzdev mcruzdev force-pushed the markdown branch 2 times, most recently from 3501818 to ebd375d Compare June 27, 2024 16:53
@mcruzdev mcruzdev requested review from mkouba and ia3andy June 27, 2024 16:55
@mcruzdev mcruzdev mentioned this pull request Jun 27, 2024
@@ -0,0 +1,5 @@
package io.quarkiverse.qute.web.markdown.runtime;

public interface MarkdownConverter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this interface is not used anymore, or?


== Usage

This extension can be combined with the `quarkus-qute-web` extension to render Markdown templates in a web application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? quarkus-qute-web-markdown should be enough?

@ia3andy
Copy link
Contributor

ia3andy commented Jul 2, 2024

@mkouba good?

@mkouba
Copy link
Contributor

mkouba commented Jul 3, 2024

@mcruzdev Could you pls squash the commits? I'll merge the PR afterwards...

@mkouba mkouba merged commit 05a10fa into quarkiverse:main Jul 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{#markdown} for Qute
3 participants