On Sun, Jun 17, 2018, 9:26 PM Eugen Stan <[email protected]> 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
>
>