DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post here questions and problems related to oXygen frameworks/document types.
msambasiva
Posts: 91
Joined: Tue Jul 17, 2018 6:57 am

DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by msambasiva »

Hi Team,
DITA-OT: 3.4.1
We are able to transform dita content into markdown using default markdown transformation. The images also copied to target location same as markdown files.

But we want to store the image files into separate folder (/images folder)
Below is the ant command using to run the transformation process, with params defined into build.properties file,
ant -f integrator.xml && ant -f build.xml -propertyfile build.properties

transtype=markdown
args.input=C:\\doc.ditamap
output.dir=C:\\docoutput

Please suggest if there is an option to store images into separate folder like(/images)

If not possible using default plugin , please confirm if we can customize the markdown plugin to have images into separate folder. It would be great help if you can suggest reference to customize markdown plugin.
Thanks in advance,
Samba.
Radu
Posts: 9431
Joined: Fri Jul 09, 2004 5:18 pm

Re: DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by Radu »

Hi,
You seem to be using an old DITA Open Toolkit and your problem also does not seem to be related to Oxygen's functionality.
From what I'm testing with Oxygen 27.0 and its bundled DITA OT 4.2.3, if in my original DITA XML content all images are placed inside an "images" folder, then also in the generated Markdown content the images are placed inside an "images" folder, so the original folder structure is preserved.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msambasiva
Posts: 91
Joined: Tue Jul 17, 2018 6:57 am

Re: DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by msambasiva »

Thanks Radu for quick response.
Unfortunately we are getting all dita content like topics, ditamaps, images in single folder without subfolders.
Please confirm if we can customize markdown plugin to have custom rules like below, Please suggest the extension point if we need to customize the markdown plugin.
https://www.dita-ot.org/dev/topics/plugin-rewrite-rules

<xsl:template match="file[@format = 'image']/@result">
<xsl:attribute name="{local-name()}" select="concat('images/', .)"/>
</xsl:template>
msambasiva
Posts: 91
Joined: Tue Jul 17, 2018 6:57 am

Re: DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by msambasiva »

Hi Radu,
Able to transform the dita content to markdown using custom plugin created without folder for images. Below are the sample code.
Here are the steps. Somehow I am not getting messages in console while I tried to print using <xsl:message>. Please correct me if Iam wrong. Thanks
plugin.xml,

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://www.dita-ot.org/rng/plugin.rnc" type="application/relax-ng-compact-syntax"?>

<plugin id="infodev.markdown">
  <require plugin="org.lwdita"/>
  <transtype name="infodev-markdown" extends="markdown" desc="InfoDev Markdown"/>
  <feature extension="dita.transtype.print" value="infodev-markdown"/>
  <feature extension="ant.import" file="integrator.xml"/>
</plugin>
integrator.xml

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <target name="dita2infodev-markdown"
       depends="dita2infodev-markdown.init, dita2markdown"/>
  <target name="dita2infodev-markdown.init">
    <property name="customization.dir"
          location="${infodev.markdown.dir}/cfg"/>
	<property name="result.rewrite-rule.xsl" 
              value="${infodev.markdown.dir}/cfg/custom-rules.xsl"/>
   </target>
</project>
cfg/custom-rules.xsl

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                version="2.0">
  <!-- Move figure title to top and description to bottom -->
	<xsl:template match="node() | @*">
	  <xsl:message>******************Hello node</xsl:message>
	  <xsl:copy>
		<xsl:apply-templates select="node() | @*"/>
	  </xsl:copy>
	</xsl:template>
	<xsl:template match="file[@format = 'image']/@result">
	  <xsl:message>#################Hello image</xsl:message>
		<xsl:attribute name="{local-name()}" select="concat('images/', .)"/>
	</xsl:template>

</xsl:stylesheet>
Thanks,
Samba.
Radu
Posts: 9431
Joined: Fri Jul 09, 2004 5:18 pm

Re: DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by Radu »

Hi Samba,

Can you add a "terminate=yes" attribute on the xsl:message from the custom-rules.xsl and run the publishing? If the publishing does not break, it means your XSLT is not called at all.

Maybe you can debug this problem, open the build file "DITA-OT/plugins/org.dita.base/build_preprocess.xml" look for the target "clean-preprocess" and maybe add some echo's inside it to see if it gets called, if the "result.rewrite-rule.xsl" is set when it gets called...

Maybe another way to approach fixing this would be for you to use some kind of python script and fixup the output folder after the publishing, move images to a folder, update references to them.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msambasiva
Posts: 91
Joined: Tue Jul 17, 2018 6:57 am

Re: DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by msambasiva »

Hi Radu,
As you suspect, clean-preprocess of build_preprocess.xml(org.dita.base) has not been called. Tried to put echo in 'clean-preprocess' target as below. I don't find message in the console.

Code: Select all

  <target name="clean-preprocess" unless="preprocess.clean-preprocess.skip" description="Clean preprocess">
    <echo message="###################clean-preprocess"/>
As per the documentation, https://www.dita-ot.org/dev/topics/plugin-rewrite-rules
To dynamically adjust the names and locations of output files in the map-first pre-processing routine (preprocess2), you can create a custom plug-in and specify the code that contains your custom rewrite rules.


Am I setting result.rewrite-rule.xsl parameter in the correct place?
Could you please review the below code?
infodev.markdown/integrator.xml

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <target name="dita2infodev-markdown.init">
    <property name="customization.dir"
          location="${dita.plugin.infodev.markdown.dir}/cfg"/>
	<property name="result.rewrite-rule.xsl" 
              value="${customization.dir}/custom-rules.xsl"/>
    <echo message="###################Hello, world ${dita.plugin.infodev.markdown.dir}"
	/>
    <echo message="###################custom dir ${customization.dir}"/>

   </target>
  <target name="dita2infodev-markdown"
       depends="dita2infodev-markdown.init, dita2markdown">

  </target>
</project>
Could you please confirm on required plugin from the below plugin.xml?

Code: Select all

<plugin id="infodev.markdown">
[b]  <require plugin="org.lwdita"/>[/b]
  <transtype name="infodev-markdown" extends="markdown" desc="InfoDev Markdown"/>
  <feature extension="dita.transtype.print" value="infodev-markdown"/>
  <feature extension="ant.import" file="integrator.xml"/>
  </plugin>
Thanks,
Samba.
Radu
Posts: 9431
Joined: Fri Jul 09, 2004 5:18 pm

Re: DITA-OT: 3.4.1 Markdown transformation - Store images to separate folder

Post by Radu »

Hi Samba,

I'm afraid you will need to debug this problem on your own.
So in the ANT build file your "dita2infodev-markdown" ANT target calls the base "dita2markdown" target which is defined in "DITA-OT/plugins/org.lwdita/build-markdown.xml" and it calls the "preprocess" target which is defined in the ANT build file DITA-OT/plugins/org.dita.base/build_preprocess.xml
and depends on the "clean-preprocess" target.
So maybe you can add some <echo>s in the build file to understand why the "clean-preprocess" target is not getting called.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply