Menu

#39 Add support for Markdown documents inside Velocity templates

1.2
open
nobody
None
2015-12-10
2015-12-10
Jose A.
No

Doxia recently added support for Markdown documents in its version 1.7-SNAPSHOT. I have migrated some sites that used doxia-include-macro with apt to Markdown but apparently Markdown isn't parsed in my Velocity excerpts.

My site has a page cfg-enable.md. If I placed Markdown code in there it would be rendered correctly. However its actual content is:

<!-- MACRO{include|custom-library-enable=true} -->

I have a project as a dependency of maven-site-plugin. This project implements RequestParameterTransformer to allow me to translate some config xml + velocity templates into (hopefully) Markdown code. In RequestParameterTransformer.transformParameters(Map<String, Object> requestParams) I end up translating the original requestParams:

At the beginning of the method they were:

{sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, custom-library-enable=true, source-content=null, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@acd3a1db}

And after executing the code below:

Object value = requestParams.get("custom-library-enable");
if (value != null) {
   requestParams.put("source-content", requestParams.get(ENABLE_COMPONENT_PARAM));
    requestParams.put("namespace-aware", true);
    correctEncoding(requestParams);
    transformEnableLibrary(value, requestParams);
}

I get

{namespace-aware=true, sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, verbatim=false, source=classpath:/site/templates/components/enable-library.md.vm, source-class=org.tinyjee.maven.dim.extensions.XmlLoader, charset=UTF-8, xml=component.xml, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@86214f1a}

The problem is that the code inside my velocity templates is never interpreted as Markdown. For instance enable-library.md.vm:

#set($h1 = '#')
#set($h2 = '##')
#set($h3 = '###')

$h2 How to include this component $h2

To include the component follow these steps:


* Add the next dependency to *pom.xml*:

<!-- MACRO{include|custom-include-library=true} -->


* Add [this server resources](./cfg-resources.html).


* Add [the next properties configuration](./cfg-properties.html#properties_example) to *application-config.properties*

This is rendered as it appears in the file and the embedded MACRO isn't interpreted either.

Discussion

  • Jose A.

    Jose A. - 2015-12-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,44 +1,46 @@
     Doxia recently added support for Markdown documents in its version [1.7-SNAPSHOT](https://issues.apache.org/jira/browse/DOXIA-492). I have migrated some sites that used doxia-include-macro with apt to Markdown but apparently Markdown isn't parsed in my Velocity excertps.
    
     My site has a page cfg-enable.md. If I place Markdown code in there it is rendered correctly. However it's actual content is:
    -```
    -<!-- MACRO{include|custom-library-enable=true} -->
    -```
    +
    
    +    <!-- MACRO{include|custom-library-enable=true} -->
    +    
     I have a project as a dependency of maven-site-plugin. This project implements `RequestParameterTransformer` to allow me to translate some config xml + velocity templates into (hopefully) Markdown code. In `RequestParameterTransformer.transformParameters(Map<String, Object> requestParams)` I end up translating the original requestParams:
    
     At the beginning of the method they were:
    -```
    -{sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, mma-library-enable=true, source-content=null, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@acd3a1db}
    -```
    +
    
    +    {sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, mma-library-enable=true, source-content=null, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@acd3a1db}
    +
     And after executing the code below:
    -```
    -Object value = requestParams.get("custom-library-enable");
    -if (value != null) {
    -   requestParams.put("source-content", requestParams.get(ENABLE_COMPONENT_PARAM));
    -   requestParams.put("namespace-aware", true);
    -   correctEncoding(requestParams);
    -   transformEnableLibrary(value, requestParams);
    -}
    -```
    -{namespace-aware=true, sourceContent=<html><head></head><body><!-- MACRO{include|mma-library-enable=true} --></body></html>, verbatim=false, source=classpath:/site/templates/components/enable-library.md.vm, source-class=org.tinyjee.maven.dim.extensions.XmlLoader, charset=UTF-8, xml=component.xml, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@86214f1a}
    +
    +    Object value = requestParams.get("custom-library-enable");
    +    if (value != null) {
    +      requestParams.put("source-content", requestParams.get(ENABLE_COMPONENT_PARAM));
    +       requestParams.put("namespace-aware", true);
    +       correctEncoding(requestParams);
    +       transformEnableLibrary(value, requestParams);
    +    }
    +
    +I get
    +
    +    {namespace-aware=true, sourceContent=<html><head></head><body><!-- MACRO{include|mma-library-enable=true} --></body></html>, verbatim=false, source=classpath:/site/templates/components/enable-library.md.vm, source-class=org.tinyjee.maven.dim.extensions.XmlLoader, charset=UTF-8, xml=component.xml, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@86214f1a}
    
     The problem is that the code inside my velocity templates is never interpreted as Markdown. For instance `enable-library.md.vm`:
    -```
    -#set($h1 = '#')
    -#set($h2 = '##')
    -#set($h3 = '###')
    
    -$h2 How to include this component $h2
    
    +    #set($h1 = '#')
    +    #set($h2 = '##')
    +    #set($h3 = '###')
    
    -To include the component follow these steps: 
    
    +    $h2 How to include this component $h2
    +
    +    To include the component follow these steps: 
    
    -* Add the next dependency to *pom.xml*:
    
    +    * Add the next dependency to *pom.xml*:
    
    -<!-- MACRO{include|mma-include-library=true} -->
    
    +    <!-- MACRO{include|mma-include-library=true} -->
    
    -* Add [this server resources](./cfg-resources.html).
    
    +    * Add [this server resources](./cfg-resources.html).
    
    -* Add [the next properties configuration](./cfg-properties.html#properties_example) to *application-config.properties*
    -```
    
    +    * Add [the next properties configuration](./cfg-properties.html#properties_example) to *application-config.properties*
    +
     This is rendered as it appears in the file and the embedded MACRO isn't interpreted either.
    
     
  • Jose A.

    Jose A. - 2015-12-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,7 +8,7 @@
    
     At the beginning of the method they were:
    
    
    -    {sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, mma-library-enable=true, source-content=null, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@acd3a1db}
    +    {sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, custom-library-enable=true, source-content=null, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@acd3a1db}
    
     And after executing the code below:
    
     
  • Jose A.

    Jose A. - 2015-12-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -Doxia recently added support for Markdown documents in its version [1.7-SNAPSHOT](https://issues.apache.org/jira/browse/DOXIA-492). I have migrated some sites that used doxia-include-macro with apt to Markdown but apparently Markdown isn't parsed in my Velocity excertps.
    +Doxia recently added support for Markdown documents in its version [1.7-SNAPSHOT](https://issues.apache.org/jira/browse/DOXIA-492). I have migrated some sites that used doxia-include-macro with apt to Markdown but apparently Markdown isn't parsed in my Velocity excerpts.
    
     My site has a page cfg-enable.md. If I place Markdown code in there it is rendered correctly. However it's actual content is:
    
     
  • Jose A.

    Jose A. - 2015-12-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     Doxia recently added support for Markdown documents in its version [1.7-SNAPSHOT](https://issues.apache.org/jira/browse/DOXIA-492). I have migrated some sites that used doxia-include-macro with apt to Markdown but apparently Markdown isn't parsed in my Velocity excerpts.
    
    -My site has a page cfg-enable.md. If I place Markdown code in there it is rendered correctly. However it's actual content is:
    +My site has a page cfg-enable.md. If I placed Markdown code in there it would be rendered correctly. However its actual content is:
    
         <!-- MACRO{include|custom-library-enable=true} -->
    
     
  • Jose A.

    Jose A. - 2015-12-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -22,7 +22,7 @@
    
     I get
    
    
    -    {namespace-aware=true, sourceContent=<html><head></head><body><!-- MACRO{include|mma-library-enable=true} --></body></html>, verbatim=false, source=classpath:/site/templates/components/enable-library.md.vm, source-class=org.tinyjee.maven.dim.extensions.XmlLoader, charset=UTF-8, xml=component.xml, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@86214f1a}
    +    {namespace-aware=true, sourceContent=<html><head></head><body><!-- MACRO{include|custom-library-enable=true} --></body></html>, verbatim=false, source=classpath:/site/templates/components/enable-library.md.vm, source-class=org.tinyjee.maven.dim.extensions.XmlLoader, charset=UTF-8, xml=component.xml, parser=org.apache.maven.doxia.module.xhtml.XhtmlParser@86214f1a}
    
     The problem is that the code inside my velocity templates is never interpreted as Markdown. For instance `enable-library.md.vm`:
    
    @@ -36,7 +36,7 @@
    
    
         * Add the next dependency to *pom.xml*:
    
    
    -    <!-- MACRO{include|mma-include-library=true} -->
    +    <!-- MACRO{include|custom-include-library=true} -->
    
    
         * Add [this server resources](./cfg-resources.html).
    
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB