You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Daniel Klco <dk...@apache.org> on 2018/08/09 14:59:25 UTC

Re: [DISCUSSION] markdown support for Sling CMS

Hey Eugen,

Now that Sling CMS 0.9.0 is out I was thinking adding markdown support to
Sling CMS would be a great addition (in part because I have a use case for
it for filtered user generated content)

I've created an issue for it:

https://issues.apache.org/jira/browse/SLING-7819

Do you want to create a PR for integrating this? How can I help?

Thanks,
Dan

On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org> wrote:

>
>
> On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org> wrote:
>
>> Hello Daniel and all,
>>
>> I've been working to deliver a piece of functionality that leverages
>> Markdown support and I think it can be a great addition for managing
>> content inside a Sling, more specifically Sling CMS.
>>
>> My work is by no means ready to be released into the open but I would
>> like to share some ideas and get some feedback. I think it could make a
>> great adition to Sling CMS.
>>
>> I've started from commonsmark-java [1] and I have made some PR's to add
>> proper osgi support and Karaf features. Until they are upstreamed, I've
>> published them to my public repository on bintray so you can test it out
>> [2].
>>
>> I'm currenlty using this functionality to manage terms of use and
>> privacy policy files for our web platform. We have a requirement that
>> they need to be translated and I believe that a text based format has
>> many advantages in this situation than an office document. Most of them
>> are related to the that:
>>
>> - content can be easily version controlled
>>
>> - content can be transformed easily into multiple output formats: html,
>> text, pdf
>>
>> - content is easy to view/edit
>>
>> - rich text editors exist for markdown that can be added
>>
>>
>> The way I am using it in my application is to register a Sling Model
>> that allows me to convert from Markdown content to html on the fly
>> (caching can be added).
>
>
>> I've also defined a script "page/markdown" via sling:resourceType so I
>> can leverage that functionality. My implementation is based on fling
>> sample and uses thymeleaf.
>>
>> Bellow are some code snippets that I use. My implementation needs to
>> handle content into multiple languages and we use a fallback mechanism:
>> If requested language is not available, then we fallback to the default
>> version - which is English version for most cases.
>>
>> ----
>>
>> @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
>> @FieldDefaults(level = AccessLevel.PROTECTED)
>> public class Page {
>>
>>   @SlingObject Resource resource;
>>
>>   @SlingObject(injectionStrategy = OPTIONAL)
>>   SlingHttpServletRequest request;
>>
>>   @OSGiService HtmlRenderer htmlRenderer;
>>   @OSGiService Parser parser;
>>
>>   List<PageTranslation> translations;
>>
>>   PageTranslation requestedTranslation;
>>
>>   @PostConstruct
>>   protected void resolveContent() {
>>     Locale lang = requestedLanguage();
>>     translations = getPageTranslations();
>>
>>     log.warn("Parsing translation for resources {}", translations);
>>     try {
>>       requestedTranslation = findRequestedTranslationOrUseDefault();
>>     } catch (Exception e) {
>>       log.warn("Exception getting content ", e);
>>     }
>>   }
>>
>>   private List<PageTranslation> getPageTranslations() {
>>     List<PageTranslation> translations = new ArrayList<>();
>>
>>     resource
>>         .getChild("lang")
>>         .getChildren()
>>         .forEach(
>>             resource1 -> {
>>               PageTranslation translation =
>> resource1.adaptTo(PageTranslation.class);
>>               if (translation != null) {
>>                 translations.add(translation);
>>               }
>>             });
>>     return translations;
>>   }
>>
>>   public String getTitle() {
>>     return requestedTranslation.getTitle();
>>   }
>>
>>   public String getLanguage() {
>>     return requestedTranslation.getLanguage();
>>   }
>>
>>   public String getContent() {
>>     String content = requestedTranslation.getContent();
>>     Node doc = parser.parse(content);
>>     return htmlRenderer.render(doc);
>>   }
>>
>> ----
>>
>> I'm hoping this can be added to Sling CMS, pending the markdown changes
>> are upstreamed.
>>
>> I believe text based formats are cool and they solve some problems in an
>> interesting way.
>>
>
> I've used markdown a fair bit and agree for text heavy use cases.
>
>
>> What do you think? Daniel, would you help me shape this so it can be
>> included in Sling CMS ?
>
>
> Totally. It'd seem like we'd need to include a markdown editor, script and
> model to render the markdown content. That way we could show a HTML editor
> and a markdown editor which might be nice from anyone coming from a
> markdown too such as Jekyll.
>
> Not related: I haven't seen a Sling CMS feature
>> in Sling Karaf features. I would like to add one in the near future.
>>
>
> That'd be great!
>
>
>>
>> Other notes: I've targeted asciidoc via asciidoctor but there are issues
>> with running asciidoctorj in osgi.
>>
>> Regards,
>>
>> Eugen
>>
>> [1] https://github.com/atlassian/commonmark-java/pulls
>>
>> [2] https://bintray.com/netdava/maven/commonmark-java
>>
>>

Re: [DISCUSSION] markdown support for Sling CMS

Posted by Daniel Klco <dk...@apache.org>.
The Flexmark OSGi Bundle has now been released:

https://search.maven.org/search?q=a:flexmark-osgi

On Sat, Aug 25, 2018 at 8:26 AM Daniel Klco <dk...@apache.org> wrote:

> I just provided a PR against Flexmark to add OSGi support. Assuming that
> gets merged and released, adding markdown support to Sling will be pretty
> easy as it's just installing the flexmark-osgi and jsoup bundles and then
> whatever code we want to wrap around it:
>
> https://github.com/vsch/flexmark-java/pull/261
>
> On Mon, Aug 13, 2018 at 11:07 AM Robert Munteanu <ro...@apache.org>
> wrote:
>
>> Hi Dan,
>>
>> On Thu, 2018-08-09 at 14:06 -0400, Daniel Klco wrote:
>> > Unfortunately, I'm not going to be at adapt.to :-( wrong side of the
>> > pond.
>> >
>> > So for commonmark, I'm assuming you're referring to this one here:
>> >
>> > https://github.com/atlassian/commonmark-java
>> >
>> > We could embed the JAR into a bundle to provide markdown support and
>> > the
>> > implementation of the Sling Models and any other services. Let me
>> > take a
>> > look at it in my copious free time ;-)
>>
>> Have you seen [1]? It's definitely buggy and missing features, but it
>> might work for your use case. In that scenario, we could graduate it
>> from the whiteboard.
>>
>> I'm still waiting for a little time to also allow usage as a
>> ResourceDecorator, and that would allow a lot more flexibility in
>> usage.
>>
>> Robert
>>
>> [1]:
>> https://github.com/apache/sling-whiteboard/tree/master/mdresourceprovider
>> >
>> > On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <
>> > stan.ieugen@gmail.com>
>> > wrote:
>> >
>> > > Hello Daniel,
>> > >
>> > > I'm very happy to hear you have a use case for it and I hope we can
>> > > get it
>> > > included soon.
>> > >
>> > > Are you coming to Adapt.to? We might do some work there.
>> > >
>> > > I'm swamped with other work and can't work on this until then. If
>> > > you need
>> > > it sooner, I can't help you much.
>> > >
>> > > Regarding markdown support, I failed to convince commonmark
>> > > developer to
>> > > merge my osgi PR's. Maybe you can push a bit and make it happen. If
>> > > not we
>> > > could try to push for flexmark. The developer might be more open to
>> > > contributions. This is for longer term.
>> > >
>> > > Short term you can use the versions I published.
>> > >
>> > > I saw another discussion about sling and markdown and I saw nice
>> > > features
>> > > being eiscussed (copy front matter properties to jcr properties,
>> > > caching,
>> > > etc) .
>> > >
>> > > https://github.com/vsch/flexmark-java
>> > >
>> > >
>> > > *De la:* dklco@apache.org
>> > > *Trimis:* 9 august 2018 17:59
>> > > *Către:* ieugen@apache.org
>> > > *Cc:* users@sling.apache.org
>> > > *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
>> > >
>> > > Hey Eugen,
>> > >
>> > > Now that Sling CMS 0.9.0 is out I was thinking adding markdown
>> > > support to
>> > > Sling CMS would be a great addition (in part because I have a use
>> > > case for
>> > > it for filtered user generated content)
>> > >
>> > > I've created an issue for it:
>> > >
>> > > https://issues.apache.org/jira/browse/SLING-7819
>> > >
>> > > Do you want to create a PR for integrating this? How can I help?
>> > >
>> > > Thanks,
>> > > Dan
>> > >
>> > > On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org>
>> > > wrote:
>> > >
>> > > >
>> > > >
>> > > > On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org>
>> > > > wrote:
>> > > >
>> > > > > Hello Daniel and all,
>> > > > >
>> > > > > I've been working to deliver a piece of functionality that
>> > > > > leverages
>> > > > > Markdown support and I think it can be a great addition for
>> > > > > managing
>> > > > > content inside a Sling, more specifically Sling CMS.
>> > > > >
>> > > > > My work is by no means ready to be released into the open but I
>> > > > > would
>> > > > > like to share some ideas and get some feedback. I think it
>> > > > > could make a
>> > > > > great adition to Sling CMS.
>> > > > >
>> > > > > I've started from commonsmark-java [1] and I have made some
>> > > > > PR's to add
>> > > > > proper osgi support and Karaf features. Until they are
>> > > > > upstreamed, I've
>> > > > > published them to my public repository on bintray so you can
>> > > > > test it out
>> > > > > [2].
>> > > > >
>> > > > > I'm currenlty using this functionality to manage terms of use
>> > > > > and
>> > > > > privacy policy files for our web platform. We have a
>> > > > > requirement that
>> > > > > they need to be translated and I believe that a text based
>> > > > > format has
>> > > > > many advantages in this situation than an office document. Most
>> > > > > of them
>> > > > > are related to the that:
>> > > > >
>> > > > > - content can be easily version controlled
>> > > > >
>> > > > > - content can be transformed easily into multiple output
>> > > > > formats: html,
>> > > > > text, pdf
>> > > > >
>> > > > > - content is easy to view/edit
>> > > > >
>> > > > > - rich text editors exist for markdown that can be added
>> > > > >
>> > > > >
>> > > > > The way I am using it in my application is to register a Sling
>> > > > > Model
>> > > > > that allows me to convert from Markdown content to html on the
>> > > > > fly
>> > > > > (caching can be added).
>> > > >
>> > > >
>> > > > > I've also defined a script "page/markdown" via
>> > > > > sling:resourceType so I
>> > > > > can leverage that functionality. My implementation is based on
>> > > > > fling
>> > > > > sample and uses thymeleaf.
>> > > > >
>> > > > > Bellow are some code snippets that I use. My implementation
>> > > > > needs to
>> > > > > handle content into multiple languages and we use a fallback
>> > > > > mechanism:
>> > > > > If requested language is not available, then we fallback to the
>> > > > > default
>> > > > > version - which is English version for most cases.
>> > > > >
>> > > > > ----
>> > > > >
>> > > > > @Model(adaptables = {Resource.class,
>> > > > > SlingHttpServletRequest.class})
>> > > > > @FieldDefaults(level = AccessLevel.PROTECTED)
>> > > > > public class Page {
>> > > > >
>> > > > >   @SlingObject Resource resource;
>> > > > >
>> > > > >   @SlingObject(injectionStrategy = OPTIONAL)
>> > > > >   SlingHttpServletRequest request;
>> > > > >
>> > > > >   @OSGiService HtmlRenderer htmlRenderer;
>> > > > >   @OSGiService Parser parser;
>> > > > >
>> > > > >   List<PageTranslation> translations;
>> > > > >
>> > > > >   PageTranslation requestedTranslation;
>> > > > >
>> > > > >   @PostConstruct
>> > > > >   protected void resolveContent() {
>> > > > >     Locale lang = requestedLanguage();
>> > > > >     translations = getPageTranslations();
>> > > > >
>> > > > >     log.warn("Parsing translation for resources {}",
>> > > > > translations);
>> > > > >     try {
>> > > > >       requestedTranslation =
>> > > > > findRequestedTranslationOrUseDefault();
>> > > > >     } catch (Exception e) {
>> > > > >       log.warn("Exception getting content ", e);
>> > > > >     }
>> > > > >   }
>> > > > >
>> > > > >   private List<PageTranslation> getPageTranslations() {
>> > > > >     List<PageTranslation> translations = new ArrayList<>();
>> > > > >
>> > > > >     resource
>> > > > >         .getChild("lang")
>> > > > >         .getChildren()
>> > > > >         .forEach(
>> > > > >             resource1 -> {
>> > > > >               PageTranslation translation =
>> > > > > resource1.adaptTo(PageTranslation.class);
>> > > > >               if (translation != null) {
>> > > > >                 translations.add(translation);
>> > > > >               }
>> > > > >             });
>> > > > >     return translations;
>> > > > >   }
>> > > > >
>> > > > >   public String getTitle() {
>> > > > >     return requestedTranslation.getTitle();
>> > > > >   }
>> > > > >
>> > > > >   public String getLanguage() {
>> > > > >     return requestedTranslation.getLanguage();
>> > > > >   }
>> > > > >
>> > > > >   public String getContent() {
>> > > > >     String content = requestedTranslation.getContent();
>> > > > >     Node doc = parser.parse(content);
>> > > > >     return htmlRenderer.render(doc);
>> > > > >   }
>> > > > >
>> > > > > ----
>> > > > >
>> > > > > I'm hoping this can be added to Sling CMS, pending the markdown
>> > > > > changes
>> > > > > are upstreamed.
>> > > > >
>> > > > > I believe text based formats are cool and they solve some
>> > > > > problems in an
>> > > > > interesting way.
>> > > > >
>> > > >
>> > > > I've used markdown a fair bit and agree for text heavy use cases.
>> > > >
>> > > >
>> > > > > What do you think? Daniel, would you help me shape this so it
>> > > > > can be
>> > > > > included in Sling CMS ?
>> > > >
>> > > >
>> > > > Totally. It'd seem like we'd need to include a markdown editor,
>> > > > script
>> > > > and model to render the markdown content. That way we could show
>> > > > a HTML
>> > > > editor and a markdown editor which might be nice from anyone
>> > > > coming from a
>> > > > markdown too such as Jekyll.
>> > > >
>> > > > Not related: I haven't seen a Sling CMS feature
>> > > > > in Sling Karaf features. I would like to add one in the near
>> > > > > future.
>> > > > >
>> > > >
>> > > > That'd be great!
>> > > >
>> > > >
>> > > > >
>> > > > > Other notes: I've targeted asciidoc via asciidoctor but there
>> > > > > are issues
>> > > > > with running asciidoctorj in osgi.
>> > > > >
>> > > > > Regards,
>> > > > >
>> > > > > Eugen
>> > > > >
>> > > > > [1] https://github.com/atlassian/commonmark-java/pulls
>> > > > >
>> > > > > [2] https://bintray.com/netdava/maven/commonmark-java
>> > > > >
>> > > > >
>>
>>
>>

Re: [DISCUSSION] markdown support for Sling CMS

Posted by Daniel Klco <dk...@apache.org>.
The Flexmark OSGi Bundle has now been released:

https://search.maven.org/search?q=a:flexmark-osgi

On Sat, Aug 25, 2018 at 8:26 AM Daniel Klco <dk...@apache.org> wrote:

> I just provided a PR against Flexmark to add OSGi support. Assuming that
> gets merged and released, adding markdown support to Sling will be pretty
> easy as it's just installing the flexmark-osgi and jsoup bundles and then
> whatever code we want to wrap around it:
>
> https://github.com/vsch/flexmark-java/pull/261
>
> On Mon, Aug 13, 2018 at 11:07 AM Robert Munteanu <ro...@apache.org>
> wrote:
>
>> Hi Dan,
>>
>> On Thu, 2018-08-09 at 14:06 -0400, Daniel Klco wrote:
>> > Unfortunately, I'm not going to be at adapt.to :-( wrong side of the
>> > pond.
>> >
>> > So for commonmark, I'm assuming you're referring to this one here:
>> >
>> > https://github.com/atlassian/commonmark-java
>> >
>> > We could embed the JAR into a bundle to provide markdown support and
>> > the
>> > implementation of the Sling Models and any other services. Let me
>> > take a
>> > look at it in my copious free time ;-)
>>
>> Have you seen [1]? It's definitely buggy and missing features, but it
>> might work for your use case. In that scenario, we could graduate it
>> from the whiteboard.
>>
>> I'm still waiting for a little time to also allow usage as a
>> ResourceDecorator, and that would allow a lot more flexibility in
>> usage.
>>
>> Robert
>>
>> [1]:
>> https://github.com/apache/sling-whiteboard/tree/master/mdresourceprovider
>> >
>> > On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <
>> > stan.ieugen@gmail.com>
>> > wrote:
>> >
>> > > Hello Daniel,
>> > >
>> > > I'm very happy to hear you have a use case for it and I hope we can
>> > > get it
>> > > included soon.
>> > >
>> > > Are you coming to Adapt.to? We might do some work there.
>> > >
>> > > I'm swamped with other work and can't work on this until then. If
>> > > you need
>> > > it sooner, I can't help you much.
>> > >
>> > > Regarding markdown support, I failed to convince commonmark
>> > > developer to
>> > > merge my osgi PR's. Maybe you can push a bit and make it happen. If
>> > > not we
>> > > could try to push for flexmark. The developer might be more open to
>> > > contributions. This is for longer term.
>> > >
>> > > Short term you can use the versions I published.
>> > >
>> > > I saw another discussion about sling and markdown and I saw nice
>> > > features
>> > > being eiscussed (copy front matter properties to jcr properties,
>> > > caching,
>> > > etc) .
>> > >
>> > > https://github.com/vsch/flexmark-java
>> > >
>> > >
>> > > *De la:* dklco@apache.org
>> > > *Trimis:* 9 august 2018 17:59
>> > > *Către:* ieugen@apache.org
>> > > *Cc:* users@sling.apache.org
>> > > *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
>> > >
>> > > Hey Eugen,
>> > >
>> > > Now that Sling CMS 0.9.0 is out I was thinking adding markdown
>> > > support to
>> > > Sling CMS would be a great addition (in part because I have a use
>> > > case for
>> > > it for filtered user generated content)
>> > >
>> > > I've created an issue for it:
>> > >
>> > > https://issues.apache.org/jira/browse/SLING-7819
>> > >
>> > > Do you want to create a PR for integrating this? How can I help?
>> > >
>> > > Thanks,
>> > > Dan
>> > >
>> > > On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org>
>> > > wrote:
>> > >
>> > > >
>> > > >
>> > > > On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org>
>> > > > wrote:
>> > > >
>> > > > > Hello Daniel and all,
>> > > > >
>> > > > > I've been working to deliver a piece of functionality that
>> > > > > leverages
>> > > > > Markdown support and I think it can be a great addition for
>> > > > > managing
>> > > > > content inside a Sling, more specifically Sling CMS.
>> > > > >
>> > > > > My work is by no means ready to be released into the open but I
>> > > > > would
>> > > > > like to share some ideas and get some feedback. I think it
>> > > > > could make a
>> > > > > great adition to Sling CMS.
>> > > > >
>> > > > > I've started from commonsmark-java [1] and I have made some
>> > > > > PR's to add
>> > > > > proper osgi support and Karaf features. Until they are
>> > > > > upstreamed, I've
>> > > > > published them to my public repository on bintray so you can
>> > > > > test it out
>> > > > > [2].
>> > > > >
>> > > > > I'm currenlty using this functionality to manage terms of use
>> > > > > and
>> > > > > privacy policy files for our web platform. We have a
>> > > > > requirement that
>> > > > > they need to be translated and I believe that a text based
>> > > > > format has
>> > > > > many advantages in this situation than an office document. Most
>> > > > > of them
>> > > > > are related to the that:
>> > > > >
>> > > > > - content can be easily version controlled
>> > > > >
>> > > > > - content can be transformed easily into multiple output
>> > > > > formats: html,
>> > > > > text, pdf
>> > > > >
>> > > > > - content is easy to view/edit
>> > > > >
>> > > > > - rich text editors exist for markdown that can be added
>> > > > >
>> > > > >
>> > > > > The way I am using it in my application is to register a Sling
>> > > > > Model
>> > > > > that allows me to convert from Markdown content to html on the
>> > > > > fly
>> > > > > (caching can be added).
>> > > >
>> > > >
>> > > > > I've also defined a script "page/markdown" via
>> > > > > sling:resourceType so I
>> > > > > can leverage that functionality. My implementation is based on
>> > > > > fling
>> > > > > sample and uses thymeleaf.
>> > > > >
>> > > > > Bellow are some code snippets that I use. My implementation
>> > > > > needs to
>> > > > > handle content into multiple languages and we use a fallback
>> > > > > mechanism:
>> > > > > If requested language is not available, then we fallback to the
>> > > > > default
>> > > > > version - which is English version for most cases.
>> > > > >
>> > > > > ----
>> > > > >
>> > > > > @Model(adaptables = {Resource.class,
>> > > > > SlingHttpServletRequest.class})
>> > > > > @FieldDefaults(level = AccessLevel.PROTECTED)
>> > > > > public class Page {
>> > > > >
>> > > > >   @SlingObject Resource resource;
>> > > > >
>> > > > >   @SlingObject(injectionStrategy = OPTIONAL)
>> > > > >   SlingHttpServletRequest request;
>> > > > >
>> > > > >   @OSGiService HtmlRenderer htmlRenderer;
>> > > > >   @OSGiService Parser parser;
>> > > > >
>> > > > >   List<PageTranslation> translations;
>> > > > >
>> > > > >   PageTranslation requestedTranslation;
>> > > > >
>> > > > >   @PostConstruct
>> > > > >   protected void resolveContent() {
>> > > > >     Locale lang = requestedLanguage();
>> > > > >     translations = getPageTranslations();
>> > > > >
>> > > > >     log.warn("Parsing translation for resources {}",
>> > > > > translations);
>> > > > >     try {
>> > > > >       requestedTranslation =
>> > > > > findRequestedTranslationOrUseDefault();
>> > > > >     } catch (Exception e) {
>> > > > >       log.warn("Exception getting content ", e);
>> > > > >     }
>> > > > >   }
>> > > > >
>> > > > >   private List<PageTranslation> getPageTranslations() {
>> > > > >     List<PageTranslation> translations = new ArrayList<>();
>> > > > >
>> > > > >     resource
>> > > > >         .getChild("lang")
>> > > > >         .getChildren()
>> > > > >         .forEach(
>> > > > >             resource1 -> {
>> > > > >               PageTranslation translation =
>> > > > > resource1.adaptTo(PageTranslation.class);
>> > > > >               if (translation != null) {
>> > > > >                 translations.add(translation);
>> > > > >               }
>> > > > >             });
>> > > > >     return translations;
>> > > > >   }
>> > > > >
>> > > > >   public String getTitle() {
>> > > > >     return requestedTranslation.getTitle();
>> > > > >   }
>> > > > >
>> > > > >   public String getLanguage() {
>> > > > >     return requestedTranslation.getLanguage();
>> > > > >   }
>> > > > >
>> > > > >   public String getContent() {
>> > > > >     String content = requestedTranslation.getContent();
>> > > > >     Node doc = parser.parse(content);
>> > > > >     return htmlRenderer.render(doc);
>> > > > >   }
>> > > > >
>> > > > > ----
>> > > > >
>> > > > > I'm hoping this can be added to Sling CMS, pending the markdown
>> > > > > changes
>> > > > > are upstreamed.
>> > > > >
>> > > > > I believe text based formats are cool and they solve some
>> > > > > problems in an
>> > > > > interesting way.
>> > > > >
>> > > >
>> > > > I've used markdown a fair bit and agree for text heavy use cases.
>> > > >
>> > > >
>> > > > > What do you think? Daniel, would you help me shape this so it
>> > > > > can be
>> > > > > included in Sling CMS ?
>> > > >
>> > > >
>> > > > Totally. It'd seem like we'd need to include a markdown editor,
>> > > > script
>> > > > and model to render the markdown content. That way we could show
>> > > > a HTML
>> > > > editor and a markdown editor which might be nice from anyone
>> > > > coming from a
>> > > > markdown too such as Jekyll.
>> > > >
>> > > > Not related: I haven't seen a Sling CMS feature
>> > > > > in Sling Karaf features. I would like to add one in the near
>> > > > > future.
>> > > > >
>> > > >
>> > > > That'd be great!
>> > > >
>> > > >
>> > > > >
>> > > > > Other notes: I've targeted asciidoc via asciidoctor but there
>> > > > > are issues
>> > > > > with running asciidoctorj in osgi.
>> > > > >
>> > > > > Regards,
>> > > > >
>> > > > > Eugen
>> > > > >
>> > > > > [1] https://github.com/atlassian/commonmark-java/pulls
>> > > > >
>> > > > > [2] https://bintray.com/netdava/maven/commonmark-java
>> > > > >
>> > > > >
>>
>>
>>

Re: [DISCUSSION] markdown support for Sling CMS

Posted by Daniel Klco <dk...@apache.org>.
I just provided a PR against Flexmark to add OSGi support. Assuming that
gets merged and released, adding markdown support to Sling will be pretty
easy as it's just installing the flexmark-osgi and jsoup bundles and then
whatever code we want to wrap around it:

https://github.com/vsch/flexmark-java/pull/261

On Mon, Aug 13, 2018 at 11:07 AM Robert Munteanu <ro...@apache.org> wrote:

> Hi Dan,
>
> On Thu, 2018-08-09 at 14:06 -0400, Daniel Klco wrote:
> > Unfortunately, I'm not going to be at adapt.to :-( wrong side of the
> > pond.
> >
> > So for commonmark, I'm assuming you're referring to this one here:
> >
> > https://github.com/atlassian/commonmark-java
> >
> > We could embed the JAR into a bundle to provide markdown support and
> > the
> > implementation of the Sling Models and any other services. Let me
> > take a
> > look at it in my copious free time ;-)
>
> Have you seen [1]? It's definitely buggy and missing features, but it
> might work for your use case. In that scenario, we could graduate it
> from the whiteboard.
>
> I'm still waiting for a little time to also allow usage as a
> ResourceDecorator, and that would allow a lot more flexibility in
> usage.
>
> Robert
>
> [1]:
> https://github.com/apache/sling-whiteboard/tree/master/mdresourceprovider
> >
> > On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <
> > stan.ieugen@gmail.com>
> > wrote:
> >
> > > Hello Daniel,
> > >
> > > I'm very happy to hear you have a use case for it and I hope we can
> > > get it
> > > included soon.
> > >
> > > Are you coming to Adapt.to? We might do some work there.
> > >
> > > I'm swamped with other work and can't work on this until then. If
> > > you need
> > > it sooner, I can't help you much.
> > >
> > > Regarding markdown support, I failed to convince commonmark
> > > developer to
> > > merge my osgi PR's. Maybe you can push a bit and make it happen. If
> > > not we
> > > could try to push for flexmark. The developer might be more open to
> > > contributions. This is for longer term.
> > >
> > > Short term you can use the versions I published.
> > >
> > > I saw another discussion about sling and markdown and I saw nice
> > > features
> > > being eiscussed (copy front matter properties to jcr properties,
> > > caching,
> > > etc) .
> > >
> > > https://github.com/vsch/flexmark-java
> > >
> > >
> > > *De la:* dklco@apache.org
> > > *Trimis:* 9 august 2018 17:59
> > > *Către:* ieugen@apache.org
> > > *Cc:* users@sling.apache.org
> > > *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
> > >
> > > Hey Eugen,
> > >
> > > Now that Sling CMS 0.9.0 is out I was thinking adding markdown
> > > support to
> > > Sling CMS would be a great addition (in part because I have a use
> > > case for
> > > it for filtered user generated content)
> > >
> > > I've created an issue for it:
> > >
> > > https://issues.apache.org/jira/browse/SLING-7819
> > >
> > > Do you want to create a PR for integrating this? How can I help?
> > >
> > > Thanks,
> > > Dan
> > >
> > > On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org>
> > > wrote:
> > >
> > > >
> > > >
> > > > On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org>
> > > > wrote:
> > > >
> > > > > Hello Daniel and all,
> > > > >
> > > > > I've been working to deliver a piece of functionality that
> > > > > leverages
> > > > > Markdown support and I think it can be a great addition for
> > > > > managing
> > > > > content inside a Sling, more specifically Sling CMS.
> > > > >
> > > > > My work is by no means ready to be released into the open but I
> > > > > would
> > > > > like to share some ideas and get some feedback. I think it
> > > > > could make a
> > > > > great adition to Sling CMS.
> > > > >
> > > > > I've started from commonsmark-java [1] and I have made some
> > > > > PR's to add
> > > > > proper osgi support and Karaf features. Until they are
> > > > > upstreamed, I've
> > > > > published them to my public repository on bintray so you can
> > > > > test it out
> > > > > [2].
> > > > >
> > > > > I'm currenlty using this functionality to manage terms of use
> > > > > and
> > > > > privacy policy files for our web platform. We have a
> > > > > requirement that
> > > > > they need to be translated and I believe that a text based
> > > > > format has
> > > > > many advantages in this situation than an office document. Most
> > > > > of them
> > > > > are related to the that:
> > > > >
> > > > > - content can be easily version controlled
> > > > >
> > > > > - content can be transformed easily into multiple output
> > > > > formats: html,
> > > > > text, pdf
> > > > >
> > > > > - content is easy to view/edit
> > > > >
> > > > > - rich text editors exist for markdown that can be added
> > > > >
> > > > >
> > > > > The way I am using it in my application is to register a Sling
> > > > > Model
> > > > > that allows me to convert from Markdown content to html on the
> > > > > fly
> > > > > (caching can be added).
> > > >
> > > >
> > > > > I've also defined a script "page/markdown" via
> > > > > sling:resourceType so I
> > > > > can leverage that functionality. My implementation is based on
> > > > > fling
> > > > > sample and uses thymeleaf.
> > > > >
> > > > > Bellow are some code snippets that I use. My implementation
> > > > > needs to
> > > > > handle content into multiple languages and we use a fallback
> > > > > mechanism:
> > > > > If requested language is not available, then we fallback to the
> > > > > default
> > > > > version - which is English version for most cases.
> > > > >
> > > > > ----
> > > > >
> > > > > @Model(adaptables = {Resource.class,
> > > > > SlingHttpServletRequest.class})
> > > > > @FieldDefaults(level = AccessLevel.PROTECTED)
> > > > > public class Page {
> > > > >
> > > > >   @SlingObject Resource resource;
> > > > >
> > > > >   @SlingObject(injectionStrategy = OPTIONAL)
> > > > >   SlingHttpServletRequest request;
> > > > >
> > > > >   @OSGiService HtmlRenderer htmlRenderer;
> > > > >   @OSGiService Parser parser;
> > > > >
> > > > >   List<PageTranslation> translations;
> > > > >
> > > > >   PageTranslation requestedTranslation;
> > > > >
> > > > >   @PostConstruct
> > > > >   protected void resolveContent() {
> > > > >     Locale lang = requestedLanguage();
> > > > >     translations = getPageTranslations();
> > > > >
> > > > >     log.warn("Parsing translation for resources {}",
> > > > > translations);
> > > > >     try {
> > > > >       requestedTranslation =
> > > > > findRequestedTranslationOrUseDefault();
> > > > >     } catch (Exception e) {
> > > > >       log.warn("Exception getting content ", e);
> > > > >     }
> > > > >   }
> > > > >
> > > > >   private List<PageTranslation> getPageTranslations() {
> > > > >     List<PageTranslation> translations = new ArrayList<>();
> > > > >
> > > > >     resource
> > > > >         .getChild("lang")
> > > > >         .getChildren()
> > > > >         .forEach(
> > > > >             resource1 -> {
> > > > >               PageTranslation translation =
> > > > > resource1.adaptTo(PageTranslation.class);
> > > > >               if (translation != null) {
> > > > >                 translations.add(translation);
> > > > >               }
> > > > >             });
> > > > >     return translations;
> > > > >   }
> > > > >
> > > > >   public String getTitle() {
> > > > >     return requestedTranslation.getTitle();
> > > > >   }
> > > > >
> > > > >   public String getLanguage() {
> > > > >     return requestedTranslation.getLanguage();
> > > > >   }
> > > > >
> > > > >   public String getContent() {
> > > > >     String content = requestedTranslation.getContent();
> > > > >     Node doc = parser.parse(content);
> > > > >     return htmlRenderer.render(doc);
> > > > >   }
> > > > >
> > > > > ----
> > > > >
> > > > > I'm hoping this can be added to Sling CMS, pending the markdown
> > > > > changes
> > > > > are upstreamed.
> > > > >
> > > > > I believe text based formats are cool and they solve some
> > > > > problems in an
> > > > > interesting way.
> > > > >
> > > >
> > > > I've used markdown a fair bit and agree for text heavy use cases.
> > > >
> > > >
> > > > > What do you think? Daniel, would you help me shape this so it
> > > > > can be
> > > > > included in Sling CMS ?
> > > >
> > > >
> > > > Totally. It'd seem like we'd need to include a markdown editor,
> > > > script
> > > > and model to render the markdown content. That way we could show
> > > > a HTML
> > > > editor and a markdown editor which might be nice from anyone
> > > > coming from a
> > > > markdown too such as Jekyll.
> > > >
> > > > Not related: I haven't seen a Sling CMS feature
> > > > > in Sling Karaf features. I would like to add one in the near
> > > > > future.
> > > > >
> > > >
> > > > That'd be great!
> > > >
> > > >
> > > > >
> > > > > Other notes: I've targeted asciidoc via asciidoctor but there
> > > > > are issues
> > > > > with running asciidoctorj in osgi.
> > > > >
> > > > > Regards,
> > > > >
> > > > > Eugen
> > > > >
> > > > > [1] https://github.com/atlassian/commonmark-java/pulls
> > > > >
> > > > > [2] https://bintray.com/netdava/maven/commonmark-java
> > > > >
> > > > >
>
>
>

Re: [DISCUSSION] markdown support for Sling CMS

Posted by Robert Munteanu <ro...@apache.org>.
Hi Dan,

On Thu, 2018-08-09 at 14:06 -0400, Daniel Klco wrote:
> Unfortunately, I'm not going to be at adapt.to :-( wrong side of the
> pond.
> 
> So for commonmark, I'm assuming you're referring to this one here:
> 
> https://github.com/atlassian/commonmark-java
> 
> We could embed the JAR into a bundle to provide markdown support and
> the
> implementation of the Sling Models and any other services. Let me
> take a
> look at it in my copious free time ;-)

Have you seen [1]? It's definitely buggy and missing features, but it
might work for your use case. In that scenario, we could graduate it
from the whiteboard.

I'm still waiting for a little time to also allow usage as a
ResourceDecorator, and that would allow a lot more flexibility in
usage.

Robert

[1]: https://github.com/apache/sling-whiteboard/tree/master/mdresourceprovider
> 
> On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <
> stan.ieugen@gmail.com>
> wrote:
> 
> > Hello Daniel,
> > 
> > I'm very happy to hear you have a use case for it and I hope we can
> > get it
> > included soon.
> > 
> > Are you coming to Adapt.to? We might do some work there.
> > 
> > I'm swamped with other work and can't work on this until then. If
> > you need
> > it sooner, I can't help you much.
> > 
> > Regarding markdown support, I failed to convince commonmark
> > developer to
> > merge my osgi PR's. Maybe you can push a bit and make it happen. If
> > not we
> > could try to push for flexmark. The developer might be more open to
> > contributions. This is for longer term.
> > 
> > Short term you can use the versions I published.
> > 
> > I saw another discussion about sling and markdown and I saw nice
> > features
> > being eiscussed (copy front matter properties to jcr properties,
> > caching,
> > etc) .
> > 
> > https://github.com/vsch/flexmark-java
> > 
> > 
> > *De la:* dklco@apache.org
> > *Trimis:* 9 august 2018 17:59
> > *Către:* ieugen@apache.org
> > *Cc:* users@sling.apache.org
> > *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
> > 
> > Hey Eugen,
> > 
> > Now that Sling CMS 0.9.0 is out I was thinking adding markdown
> > support to
> > Sling CMS would be a great addition (in part because I have a use
> > case for
> > it for filtered user generated content)
> > 
> > I've created an issue for it:
> > 
> > https://issues.apache.org/jira/browse/SLING-7819
> > 
> > Do you want to create a PR for integrating this? How can I help?
> > 
> > Thanks,
> > Dan
> > 
> > On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org>
> > wrote:
> > 
> > > 
> > > 
> > > On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org>
> > > wrote:
> > > 
> > > > Hello Daniel and all,
> > > > 
> > > > I've been working to deliver a piece of functionality that
> > > > leverages
> > > > Markdown support and I think it can be a great addition for
> > > > managing
> > > > content inside a Sling, more specifically Sling CMS.
> > > > 
> > > > My work is by no means ready to be released into the open but I
> > > > would
> > > > like to share some ideas and get some feedback. I think it
> > > > could make a
> > > > great adition to Sling CMS.
> > > > 
> > > > I've started from commonsmark-java [1] and I have made some
> > > > PR's to add
> > > > proper osgi support and Karaf features. Until they are
> > > > upstreamed, I've
> > > > published them to my public repository on bintray so you can
> > > > test it out
> > > > [2].
> > > > 
> > > > I'm currenlty using this functionality to manage terms of use
> > > > and
> > > > privacy policy files for our web platform. We have a
> > > > requirement that
> > > > they need to be translated and I believe that a text based
> > > > format has
> > > > many advantages in this situation than an office document. Most
> > > > of them
> > > > are related to the that:
> > > > 
> > > > - content can be easily version controlled
> > > > 
> > > > - content can be transformed easily into multiple output
> > > > formats: html,
> > > > text, pdf
> > > > 
> > > > - content is easy to view/edit
> > > > 
> > > > - rich text editors exist for markdown that can be added
> > > > 
> > > > 
> > > > The way I am using it in my application is to register a Sling
> > > > Model
> > > > that allows me to convert from Markdown content to html on the
> > > > fly
> > > > (caching can be added).
> > > 
> > > 
> > > > I've also defined a script "page/markdown" via
> > > > sling:resourceType so I
> > > > can leverage that functionality. My implementation is based on
> > > > fling
> > > > sample and uses thymeleaf.
> > > > 
> > > > Bellow are some code snippets that I use. My implementation
> > > > needs to
> > > > handle content into multiple languages and we use a fallback
> > > > mechanism:
> > > > If requested language is not available, then we fallback to the
> > > > default
> > > > version - which is English version for most cases.
> > > > 
> > > > ----
> > > > 
> > > > @Model(adaptables = {Resource.class,
> > > > SlingHttpServletRequest.class})
> > > > @FieldDefaults(level = AccessLevel.PROTECTED)
> > > > public class Page {
> > > > 
> > > >   @SlingObject Resource resource;
> > > > 
> > > >   @SlingObject(injectionStrategy = OPTIONAL)
> > > >   SlingHttpServletRequest request;
> > > > 
> > > >   @OSGiService HtmlRenderer htmlRenderer;
> > > >   @OSGiService Parser parser;
> > > > 
> > > >   List<PageTranslation> translations;
> > > > 
> > > >   PageTranslation requestedTranslation;
> > > > 
> > > >   @PostConstruct
> > > >   protected void resolveContent() {
> > > >     Locale lang = requestedLanguage();
> > > >     translations = getPageTranslations();
> > > > 
> > > >     log.warn("Parsing translation for resources {}",
> > > > translations);
> > > >     try {
> > > >       requestedTranslation =
> > > > findRequestedTranslationOrUseDefault();
> > > >     } catch (Exception e) {
> > > >       log.warn("Exception getting content ", e);
> > > >     }
> > > >   }
> > > > 
> > > >   private List<PageTranslation> getPageTranslations() {
> > > >     List<PageTranslation> translations = new ArrayList<>();
> > > > 
> > > >     resource
> > > >         .getChild("lang")
> > > >         .getChildren()
> > > >         .forEach(
> > > >             resource1 -> {
> > > >               PageTranslation translation =
> > > > resource1.adaptTo(PageTranslation.class);
> > > >               if (translation != null) {
> > > >                 translations.add(translation);
> > > >               }
> > > >             });
> > > >     return translations;
> > > >   }
> > > > 
> > > >   public String getTitle() {
> > > >     return requestedTranslation.getTitle();
> > > >   }
> > > > 
> > > >   public String getLanguage() {
> > > >     return requestedTranslation.getLanguage();
> > > >   }
> > > > 
> > > >   public String getContent() {
> > > >     String content = requestedTranslation.getContent();
> > > >     Node doc = parser.parse(content);
> > > >     return htmlRenderer.render(doc);
> > > >   }
> > > > 
> > > > ----
> > > > 
> > > > I'm hoping this can be added to Sling CMS, pending the markdown
> > > > changes
> > > > are upstreamed.
> > > > 
> > > > I believe text based formats are cool and they solve some
> > > > problems in an
> > > > interesting way.
> > > > 
> > > 
> > > I've used markdown a fair bit and agree for text heavy use cases.
> > > 
> > > 
> > > > What do you think? Daniel, would you help me shape this so it
> > > > can be
> > > > included in Sling CMS ?
> > > 
> > > 
> > > Totally. It'd seem like we'd need to include a markdown editor,
> > > script
> > > and model to render the markdown content. That way we could show
> > > a HTML
> > > editor and a markdown editor which might be nice from anyone
> > > coming from a
> > > markdown too such as Jekyll.
> > > 
> > > Not related: I haven't seen a Sling CMS feature
> > > > in Sling Karaf features. I would like to add one in the near
> > > > future.
> > > > 
> > > 
> > > That'd be great!
> > > 
> > > 
> > > > 
> > > > Other notes: I've targeted asciidoc via asciidoctor but there
> > > > are issues
> > > > with running asciidoctorj in osgi.
> > > > 
> > > > Regards,
> > > > 
> > > > Eugen
> > > > 
> > > > [1] https://github.com/atlassian/commonmark-java/pulls
> > > > 
> > > > [2] https://bintray.com/netdava/maven/commonmark-java
> > > > 
> > > > 



Re: Detecting whether job has been stopped by the user but JobExecutor hasn't terminated yet?

Posted by Robert Munteanu <ro...@apache.org>.
Hi John,

You replied to Eugen's previous email which caused the email to appear
in the same thread, and likely ignored by at least some subscribers.

I don't have a good answer for your email, but maybe resending without
replying to an existing email might help :-)

Best,

Robert

On Fri, 2018-08-10 at 22:24 +0000, John Logan wrote:
> Hi,
> 
> 
> In essence I'm trying to detect the in-progress state of a job being
> stopped.
> 
> 
> I see in the sling-event implementation that calling
> jobHandler.stopJobById() eventually works its way down to calling
> jobHandler.stop(), setting a flag in the JobHandler.
> 
> 
> The JobExecutor is responsible for calling
> jobExecutionContext.isStopped(), and if it returns true, the
> JobExecutor should clean up, call  and exit.
> 
> 
> There might be some time elapsed between the request to stop and the
> JobExecutor returning the JobExecutionResult that updates job
> state.  Is there a way to detect this interim condition via sling-
> event-api?  I had a look at the code and didn't see anything obvious.
> 
> 
> What I'm trying to do is indicate in my UI that a job is being
> cancelled, but cancellation isn't complete yet.
> 
> 
> Thanks!  John



Detecting whether job has been stopped by the user but JobExecutor hasn't terminated yet?

Posted by John Logan <Jo...@texture.com>.
Hi,


In essence I'm trying to detect the in-progress state of a job being stopped.


I see in the sling-event implementation that calling jobHandler.stopJobById() eventually works its way down to calling jobHandler.stop(), setting a flag in the JobHandler.


The JobExecutor is responsible for calling jobExecutionContext.isStopped(), and if it returns true, the JobExecutor should clean up, call  and exit.


There might be some time elapsed between the request to stop and the JobExecutor returning the JobExecutionResult that updates job state.  Is there a way to detect this interim condition via sling-event-api?  I had a look at the code and didn't see anything obvious.


What I'm trying to do is indicate in my UI that a job is being cancelled, but cancellation isn't complete yet.


Thanks!  John

Re: [DISCUSSION] markdown support for Sling CMS

Posted by Eugen Stan <ie...@netdava.com>.
Hi,

I also think flexmark might be a better choice. I think the developer is
more contributor friendly.

Regards,

[1] https://github.com/vsch/flexmark-java/issues/236


On 10.08.2018 02:02, Chris Millar wrote:
> It might be worth looking at flexmark [0], too. This is what jbake uses for
> its markdown parser.
>
> Chris
>
> [0] https://github.com/vsch/flexmark-java
>
>
> On Thu, Aug 9, 2018 at 12:06 PM, Daniel Klco <dk...@apache.org> wrote:
>
>> Unfortunately, I'm not going to be at adapt.to :-( wrong side of the pond.
>>
>> So for commonmark, I'm assuming you're referring to this one here:
>>
>> https://github.com/atlassian/commonmark-java
>>
>> We could embed the JAR into a bundle to provide markdown support and the
>> implementation of the Sling Models and any other services. Let me take a
>> look at it in my copious free time ;-)
>>
>> On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <st...@gmail.com>
>> wrote:
>>
>>> Hello Daniel,
>>>
>>> I'm very happy to hear you have a use case for it and I hope we can get
>> it
>>> included soon.
>>>
>>> Are you coming to Adapt.to? We might do some work there.
>>>
>>> I'm swamped with other work and can't work on this until then. If you
>> need
>>> it sooner, I can't help you much.
>>>
>>> Regarding markdown support, I failed to convince commonmark developer to
>>> merge my osgi PR's. Maybe you can push a bit and make it happen. If not
>> we
>>> could try to push for flexmark. The developer might be more open to
>>> contributions. This is for longer term.
>>>
>>> Short term you can use the versions I published.
>>>
>>> I saw another discussion about sling and markdown and I saw nice features
>>> being eiscussed (copy front matter properties to jcr properties, caching,
>>> etc) .
>>>
>>> https://github.com/vsch/flexmark-java
>>>
>>>
>>> *De la:* dklco@apache.org
>>> *Trimis:* 9 august 2018 17:59
>>> *Către:* ieugen@apache.org
>>> *Cc:* users@sling.apache.org
>>> *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
>>>
>>> Hey Eugen,
>>>
>>> Now that Sling CMS 0.9.0 is out I was thinking adding markdown support to
>>> Sling CMS would be a great addition (in part because I have a use case
>> for
>>> it for filtered user generated content)
>>>
>>> I've created an issue for it:
>>>
>>> https://issues.apache.org/jira/browse/SLING-7819
>>>
>>> Do you want to create a PR for integrating this? How can I help?
>>>
>>> Thanks,
>>> Dan
>>>
>>> On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org> wrote:
>>>
>>>>
>>>> On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org> wrote:
>>>>
>>>>> Hello Daniel and all,
>>>>>
>>>>> I've been working to deliver a piece of functionality that leverages
>>>>> Markdown support and I think it can be a great addition for managing
>>>>> content inside a Sling, more specifically Sling CMS.
>>>>>
>>>>> My work is by no means ready to be released into the open but I would
>>>>> like to share some ideas and get some feedback. I think it could make a
>>>>> great adition to Sling CMS.
>>>>>
>>>>> I've started from commonsmark-java [1] and I have made some PR's to add
>>>>> proper osgi support and Karaf features. Until they are upstreamed, I've
>>>>> published them to my public repository on bintray so you can test it
>> out
>>>>> [2].
>>>>>
>>>>> I'm currenlty using this functionality to manage terms of use and
>>>>> privacy policy files for our web platform. We have a requirement that
>>>>> they need to be translated and I believe that a text based format has
>>>>> many advantages in this situation than an office document. Most of them
>>>>> are related to the that:
>>>>>
>>>>> - content can be easily version controlled
>>>>>
>>>>> - content can be transformed easily into multiple output formats: html,
>>>>> text, pdf
>>>>>
>>>>> - content is easy to view/edit
>>>>>
>>>>> - rich text editors exist for markdown that can be added
>>>>>
>>>>>
>>>>> The way I am using it in my application is to register a Sling Model
>>>>> that allows me to convert from Markdown content to html on the fly
>>>>> (caching can be added).
>>>>
>>>>> I've also defined a script "page/markdown" via sling:resourceType so I
>>>>> can leverage that functionality. My implementation is based on fling
>>>>> sample and uses thymeleaf.
>>>>>
>>>>> Bellow are some code snippets that I use. My implementation needs to
>>>>> handle content into multiple languages and we use a fallback mechanism:
>>>>> If requested language is not available, then we fallback to the default
>>>>> version - which is English version for most cases.
>>>>>
>>>>> ----
>>>>>
>>>>> @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
>>>>> @FieldDefaults(level = AccessLevel.PROTECTED)
>>>>> public class Page {
>>>>>
>>>>>   @SlingObject Resource resource;
>>>>>
>>>>>   @SlingObject(injectionStrategy = OPTIONAL)
>>>>>   SlingHttpServletRequest request;
>>>>>
>>>>>   @OSGiService HtmlRenderer htmlRenderer;
>>>>>   @OSGiService Parser parser;
>>>>>
>>>>>   List<PageTranslation> translations;
>>>>>
>>>>>   PageTranslation requestedTranslation;
>>>>>
>>>>>   @PostConstruct
>>>>>   protected void resolveContent() {
>>>>>     Locale lang = requestedLanguage();
>>>>>     translations = getPageTranslations();
>>>>>
>>>>>     log.warn("Parsing translation for resources {}", translations);
>>>>>     try {
>>>>>       requestedTranslation = findRequestedTranslationOrUseDefault();
>>>>>     } catch (Exception e) {
>>>>>       log.warn("Exception getting content ", e);
>>>>>     }
>>>>>   }
>>>>>
>>>>>   private List<PageTranslation> getPageTranslations() {
>>>>>     List<PageTranslation> translations = new ArrayList<>();
>>>>>
>>>>>     resource
>>>>>         .getChild("lang")
>>>>>         .getChildren()
>>>>>         .forEach(
>>>>>             resource1 -> {
>>>>>               PageTranslation translation =
>>>>> resource1.adaptTo(PageTranslation.class);
>>>>>               if (translation != null) {
>>>>>                 translations.add(translation);
>>>>>               }
>>>>>             });
>>>>>     return translations;
>>>>>   }
>>>>>
>>>>>   public String getTitle() {
>>>>>     return requestedTranslation.getTitle();
>>>>>   }
>>>>>
>>>>>   public String getLanguage() {
>>>>>     return requestedTranslation.getLanguage();
>>>>>   }
>>>>>
>>>>>   public String getContent() {
>>>>>     String content = requestedTranslation.getContent();
>>>>>     Node doc = parser.parse(content);
>>>>>     return htmlRenderer.render(doc);
>>>>>   }
>>>>>
>>>>> ----
>>>>>
>>>>> I'm hoping this can be added to Sling CMS, pending the markdown changes
>>>>> are upstreamed.
>>>>>
>>>>> I believe text based formats are cool and they solve some problems in
>> an
>>>>> interesting way.
>>>>>
>>>> I've used markdown a fair bit and agree for text heavy use cases.
>>>>
>>>>
>>>>> What do you think? Daniel, would you help me shape this so it can be
>>>>> included in Sling CMS ?
>>>>
>>>> Totally. It'd seem like we'd need to include a markdown editor, script
>>>> and model to render the markdown content. That way we could show a HTML
>>>> editor and a markdown editor which might be nice from anyone coming
>> from a
>>>> markdown too such as Jekyll.
>>>>
>>>> Not related: I haven't seen a Sling CMS feature
>>>>> in Sling Karaf features. I would like to add one in the near future.
>>>>>
>>>> That'd be great!
>>>>
>>>>
>>>>> Other notes: I've targeted asciidoc via asciidoctor but there are
>> issues
>>>>> with running asciidoctorj in osgi.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Eugen
>>>>>
>>>>> [1] https://github.com/atlassian/commonmark-java/pulls
>>>>>
>>>>> [2] https://bintray.com/netdava/maven/commonmark-java
>>>>>
>>>>>



Re: [DISCUSSION] markdown support for Sling CMS

Posted by Chris Millar <cm...@apache.org>.
It might be worth looking at flexmark [0], too. This is what jbake uses for
its markdown parser.

Chris

[0] https://github.com/vsch/flexmark-java


On Thu, Aug 9, 2018 at 12:06 PM, Daniel Klco <dk...@apache.org> wrote:

> Unfortunately, I'm not going to be at adapt.to :-( wrong side of the pond.
>
> So for commonmark, I'm assuming you're referring to this one here:
>
> https://github.com/atlassian/commonmark-java
>
> We could embed the JAR into a bundle to provide markdown support and the
> implementation of the Sling Models and any other services. Let me take a
> look at it in my copious free time ;-)
>
> On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <st...@gmail.com>
> wrote:
>
> > Hello Daniel,
> >
> > I'm very happy to hear you have a use case for it and I hope we can get
> it
> > included soon.
> >
> > Are you coming to Adapt.to? We might do some work there.
> >
> > I'm swamped with other work and can't work on this until then. If you
> need
> > it sooner, I can't help you much.
> >
> > Regarding markdown support, I failed to convince commonmark developer to
> > merge my osgi PR's. Maybe you can push a bit and make it happen. If not
> we
> > could try to push for flexmark. The developer might be more open to
> > contributions. This is for longer term.
> >
> > Short term you can use the versions I published.
> >
> > I saw another discussion about sling and markdown and I saw nice features
> > being eiscussed (copy front matter properties to jcr properties, caching,
> > etc) .
> >
> > https://github.com/vsch/flexmark-java
> >
> >
> > *De la:* dklco@apache.org
> > *Trimis:* 9 august 2018 17:59
> > *Către:* ieugen@apache.org
> > *Cc:* users@sling.apache.org
> > *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
> >
> > Hey Eugen,
> >
> > Now that Sling CMS 0.9.0 is out I was thinking adding markdown support to
> > Sling CMS would be a great addition (in part because I have a use case
> for
> > it for filtered user generated content)
> >
> > I've created an issue for it:
> >
> > https://issues.apache.org/jira/browse/SLING-7819
> >
> > Do you want to create a PR for integrating this? How can I help?
> >
> > Thanks,
> > Dan
> >
> > On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org> wrote:
> >
> >>
> >>
> >> On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org> wrote:
> >>
> >>> Hello Daniel and all,
> >>>
> >>> I've been working to deliver a piece of functionality that leverages
> >>> Markdown support and I think it can be a great addition for managing
> >>> content inside a Sling, more specifically Sling CMS.
> >>>
> >>> My work is by no means ready to be released into the open but I would
> >>> like to share some ideas and get some feedback. I think it could make a
> >>> great adition to Sling CMS.
> >>>
> >>> I've started from commonsmark-java [1] and I have made some PR's to add
> >>> proper osgi support and Karaf features. Until they are upstreamed, I've
> >>> published them to my public repository on bintray so you can test it
> out
> >>> [2].
> >>>
> >>> I'm currenlty using this functionality to manage terms of use and
> >>> privacy policy files for our web platform. We have a requirement that
> >>> they need to be translated and I believe that a text based format has
> >>> many advantages in this situation than an office document. Most of them
> >>> are related to the that:
> >>>
> >>> - content can be easily version controlled
> >>>
> >>> - content can be transformed easily into multiple output formats: html,
> >>> text, pdf
> >>>
> >>> - content is easy to view/edit
> >>>
> >>> - rich text editors exist for markdown that can be added
> >>>
> >>>
> >>> The way I am using it in my application is to register a Sling Model
> >>> that allows me to convert from Markdown content to html on the fly
> >>> (caching can be added).
> >>
> >>
> >>> I've also defined a script "page/markdown" via sling:resourceType so I
> >>> can leverage that functionality. My implementation is based on fling
> >>> sample and uses thymeleaf.
> >>>
> >>> Bellow are some code snippets that I use. My implementation needs to
> >>> handle content into multiple languages and we use a fallback mechanism:
> >>> If requested language is not available, then we fallback to the default
> >>> version - which is English version for most cases.
> >>>
> >>> ----
> >>>
> >>> @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
> >>> @FieldDefaults(level = AccessLevel.PROTECTED)
> >>> public class Page {
> >>>
> >>>   @SlingObject Resource resource;
> >>>
> >>>   @SlingObject(injectionStrategy = OPTIONAL)
> >>>   SlingHttpServletRequest request;
> >>>
> >>>   @OSGiService HtmlRenderer htmlRenderer;
> >>>   @OSGiService Parser parser;
> >>>
> >>>   List<PageTranslation> translations;
> >>>
> >>>   PageTranslation requestedTranslation;
> >>>
> >>>   @PostConstruct
> >>>   protected void resolveContent() {
> >>>     Locale lang = requestedLanguage();
> >>>     translations = getPageTranslations();
> >>>
> >>>     log.warn("Parsing translation for resources {}", translations);
> >>>     try {
> >>>       requestedTranslation = findRequestedTranslationOrUseDefault();
> >>>     } catch (Exception e) {
> >>>       log.warn("Exception getting content ", e);
> >>>     }
> >>>   }
> >>>
> >>>   private List<PageTranslation> getPageTranslations() {
> >>>     List<PageTranslation> translations = new ArrayList<>();
> >>>
> >>>     resource
> >>>         .getChild("lang")
> >>>         .getChildren()
> >>>         .forEach(
> >>>             resource1 -> {
> >>>               PageTranslation translation =
> >>> resource1.adaptTo(PageTranslation.class);
> >>>               if (translation != null) {
> >>>                 translations.add(translation);
> >>>               }
> >>>             });
> >>>     return translations;
> >>>   }
> >>>
> >>>   public String getTitle() {
> >>>     return requestedTranslation.getTitle();
> >>>   }
> >>>
> >>>   public String getLanguage() {
> >>>     return requestedTranslation.getLanguage();
> >>>   }
> >>>
> >>>   public String getContent() {
> >>>     String content = requestedTranslation.getContent();
> >>>     Node doc = parser.parse(content);
> >>>     return htmlRenderer.render(doc);
> >>>   }
> >>>
> >>> ----
> >>>
> >>> I'm hoping this can be added to Sling CMS, pending the markdown changes
> >>> are upstreamed.
> >>>
> >>> I believe text based formats are cool and they solve some problems in
> an
> >>> interesting way.
> >>>
> >>
> >> I've used markdown a fair bit and agree for text heavy use cases.
> >>
> >>
> >>> What do you think? Daniel, would you help me shape this so it can be
> >>> included in Sling CMS ?
> >>
> >>
> >> Totally. It'd seem like we'd need to include a markdown editor, script
> >> and model to render the markdown content. That way we could show a HTML
> >> editor and a markdown editor which might be nice from anyone coming
> from a
> >> markdown too such as Jekyll.
> >>
> >> Not related: I haven't seen a Sling CMS feature
> >>> in Sling Karaf features. I would like to add one in the near future.
> >>>
> >>
> >> That'd be great!
> >>
> >>
> >>>
> >>> Other notes: I've targeted asciidoc via asciidoctor but there are
> issues
> >>> with running asciidoctorj in osgi.
> >>>
> >>> Regards,
> >>>
> >>> Eugen
> >>>
> >>> [1] https://github.com/atlassian/commonmark-java/pulls
> >>>
> >>> [2] https://bintray.com/netdava/maven/commonmark-java
> >>>
> >>>
>

Re: [DISCUSSION] markdown support for Sling CMS

Posted by Daniel Klco <dk...@apache.org>.
Unfortunately, I'm not going to be at adapt.to :-( wrong side of the pond.

So for commonmark, I'm assuming you're referring to this one here:

https://github.com/atlassian/commonmark-java

We could embed the JAR into a bundle to provide markdown support and the
implementation of the Sling Models and any other services. Let me take a
look at it in my copious free time ;-)

On Thu, Aug 9, 2018 at 12:05 PM Ioan Eugen Stan <st...@gmail.com>
wrote:

> Hello Daniel,
>
> I'm very happy to hear you have a use case for it and I hope we can get it
> included soon.
>
> Are you coming to Adapt.to? We might do some work there.
>
> I'm swamped with other work and can't work on this until then. If you need
> it sooner, I can't help you much.
>
> Regarding markdown support, I failed to convince commonmark developer to
> merge my osgi PR's. Maybe you can push a bit and make it happen. If not we
> could try to push for flexmark. The developer might be more open to
> contributions. This is for longer term.
>
> Short term you can use the versions I published.
>
> I saw another discussion about sling and markdown and I saw nice features
> being eiscussed (copy front matter properties to jcr properties, caching,
> etc) .
>
> https://github.com/vsch/flexmark-java
>
>
> *De la:* dklco@apache.org
> *Trimis:* 9 august 2018 17:59
> *Către:* ieugen@apache.org
> *Cc:* users@sling.apache.org
> *Subiect:* Re: [DISCUSSION] markdown support for Sling CMS
>
> Hey Eugen,
>
> Now that Sling CMS 0.9.0 is out I was thinking adding markdown support to
> Sling CMS would be a great addition (in part because I have a use case for
> it for filtered user generated content)
>
> I've created an issue for it:
>
> https://issues.apache.org/jira/browse/SLING-7819
>
> Do you want to create a PR for integrating this? How can I help?
>
> Thanks,
> Dan
>
> On Wed, Jun 20, 2018 at 10:16 PM Daniel Klco <dk...@apache.org> wrote:
>
>>
>>
>> On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <ie...@apache.org> wrote:
>>
>>> Hello Daniel and all,
>>>
>>> I've been working to deliver a piece of functionality that leverages
>>> Markdown support and I think it can be a great addition for managing
>>> content inside a Sling, more specifically Sling CMS.
>>>
>>> My work is by no means ready to be released into the open but I would
>>> like to share some ideas and get some feedback. I think it could make a
>>> great adition to Sling CMS.
>>>
>>> I've started from commonsmark-java [1] and I have made some PR's to add
>>> proper osgi support and Karaf features. Until they are upstreamed, I've
>>> published them to my public repository on bintray so you can test it out
>>> [2].
>>>
>>> I'm currenlty using this functionality to manage terms of use and
>>> privacy policy files for our web platform. We have a requirement that
>>> they need to be translated and I believe that a text based format has
>>> many advantages in this situation than an office document. Most of them
>>> are related to the that:
>>>
>>> - content can be easily version controlled
>>>
>>> - content can be transformed easily into multiple output formats: html,
>>> text, pdf
>>>
>>> - content is easy to view/edit
>>>
>>> - rich text editors exist for markdown that can be added
>>>
>>>
>>> The way I am using it in my application is to register a Sling Model
>>> that allows me to convert from Markdown content to html on the fly
>>> (caching can be added).
>>
>>
>>> I've also defined a script "page/markdown" via sling:resourceType so I
>>> can leverage that functionality. My implementation is based on fling
>>> sample and uses thymeleaf.
>>>
>>> Bellow are some code snippets that I use. My implementation needs to
>>> handle content into multiple languages and we use a fallback mechanism:
>>> If requested language is not available, then we fallback to the default
>>> version - which is English version for most cases.
>>>
>>> ----
>>>
>>> @Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
>>> @FieldDefaults(level = AccessLevel.PROTECTED)
>>> public class Page {
>>>
>>>   @SlingObject Resource resource;
>>>
>>>   @SlingObject(injectionStrategy = OPTIONAL)
>>>   SlingHttpServletRequest request;
>>>
>>>   @OSGiService HtmlRenderer htmlRenderer;
>>>   @OSGiService Parser parser;
>>>
>>>   List<PageTranslation> translations;
>>>
>>>   PageTranslation requestedTranslation;
>>>
>>>   @PostConstruct
>>>   protected void resolveContent() {
>>>     Locale lang = requestedLanguage();
>>>     translations = getPageTranslations();
>>>
>>>     log.warn("Parsing translation for resources {}", translations);
>>>     try {
>>>       requestedTranslation = findRequestedTranslationOrUseDefault();
>>>     } catch (Exception e) {
>>>       log.warn("Exception getting content ", e);
>>>     }
>>>   }
>>>
>>>   private List<PageTranslation> getPageTranslations() {
>>>     List<PageTranslation> translations = new ArrayList<>();
>>>
>>>     resource
>>>         .getChild("lang")
>>>         .getChildren()
>>>         .forEach(
>>>             resource1 -> {
>>>               PageTranslation translation =
>>> resource1.adaptTo(PageTranslation.class);
>>>               if (translation != null) {
>>>                 translations.add(translation);
>>>               }
>>>             });
>>>     return translations;
>>>   }
>>>
>>>   public String getTitle() {
>>>     return requestedTranslation.getTitle();
>>>   }
>>>
>>>   public String getLanguage() {
>>>     return requestedTranslation.getLanguage();
>>>   }
>>>
>>>   public String getContent() {
>>>     String content = requestedTranslation.getContent();
>>>     Node doc = parser.parse(content);
>>>     return htmlRenderer.render(doc);
>>>   }
>>>
>>> ----
>>>
>>> I'm hoping this can be added to Sling CMS, pending the markdown changes
>>> are upstreamed.
>>>
>>> I believe text based formats are cool and they solve some problems in an
>>> interesting way.
>>>
>>
>> I've used markdown a fair bit and agree for text heavy use cases.
>>
>>
>>> What do you think? Daniel, would you help me shape this so it can be
>>> included in Sling CMS ?
>>
>>
>> Totally. It'd seem like we'd need to include a markdown editor, script
>> and model to render the markdown content. That way we could show a HTML
>> editor and a markdown editor which might be nice from anyone coming from a
>> markdown too such as Jekyll.
>>
>> Not related: I haven't seen a Sling CMS feature
>>> in Sling Karaf features. I would like to add one in the near future.
>>>
>>
>> That'd be great!
>>
>>
>>>
>>> Other notes: I've targeted asciidoc via asciidoctor but there are issues
>>> with running asciidoctorj in osgi.
>>>
>>> Regards,
>>>
>>> Eugen
>>>
>>> [1] https://github.com/atlassian/commonmark-java/pulls
>>>
>>> [2] https://bintray.com/netdava/maven/commonmark-java
>>>
>>>