项目作者: jason-fox

项目描述 :
Pandoc DITA-OT Plug-in for extending the available input formats for DITA-OT. Non DITA input sources can be pre-processed to create create valid DITA source.
高级语言: Lua
项目地址: git://github.com/jason-fox/fox.jason.passthrough.pandoc.git
创建时间: 2019-07-19T19:08:59Z
项目社区:https://github.com/jason-fox/fox.jason.passthrough.pandoc

开源协议:Apache License 2.0

下载


Pandoc Plugin for DITA-OT

license
DITA-OT 4.2
CI
Quality Gate Status

This is a DITA-OT Plug-in to extend the available input formats for DITA-OT. Non DITA
input sources can be pre-processed using Pandoc to create create valid DITA source. Files written
in multiple input formats can be directly added to a *.ditamap and processed as if they had been written in DITA.

:arrow_forward: Video from DITA-OT Day 2019


Table of Contents

- Background
- Install
- Installing DITA-OT
- Installing the Plug-in
- Installing Pandoc
- Usage
- How to annotate Pandoc passthrough files
- ID and outputclass
- Sections
- Note
- Metadata
- Ditamap topicmeta for Pandoc Files
- License

Background

Pandoc is a Haskell library for converting from one markup format to another, and a
command-line tool that uses this library. It can convert from the following formats:

This plug-in contains a Lua template which extends the output formats supported by Pandoc to include DITA. The
output consists of a single DITA topic for each input file added to the ditamap.

Unlike the standard Markdown Plug-in, this plug-in does not fail if the
h1...h6 headers are incorrectly incremented. This is because the Lua template has been designed to calculate that
headers are incrementing at most one level at a time - the downside of this is that the output maybe unexpected.

Note that because Pandoc’s intermediate representation of a document is less expressive than many of the formats it
converts between, one should not expect perfect conversions between every format and every other. Pandoc attempts to
preserve the structural elements of a document, but not formatting details such as margin size. And some document
elements, such as complex tables, may not fit into pandoc’s simple document model. While conversions from pandoc’s
Markdown to all formats aspire to be perfect, conversions from formats more expressive than pandoc’s Markdown can be
expected to be lossy.

Install

The DITA-OT Pandoc Pass Through plug-in has been tested against DITA-OT 4.x. It is
recommended that you upgrade to the latest version.

Installing DITA-OT

The DITA-OT Pandoc plug-in is a file reader for the DITA Open Toolkit.

  • Full installation instructions for downloading DITA-OT can be found
    here.

    1. Download the dita-ot-4.2.zip package from the project website at
      dita-ot.org/download
    2. Extract the contents of the package to the directory where you want to install DITA-OT.
    3. Optional: Add the absolute path for the bin directory to the PATH system variable.

    This defines the necessary environment variable to run the dita command from the command line.

  1. curl -LO https://github.com/dita-ot/dita-ot/releases/download/4.2/dita-ot-4.2.zip
  2. unzip -q dita-ot-4.2.zip
  3. rm dita-ot-4.2.zip

Installing the Plug-in

  • Run the plug-in installation commands:
  1. dita install https://github.com/doctales/org.doctales.xmltask/archive/master.zip
  2. dita install https://github.com/jason-fox/fox.jason.passthrough/archive/master.zip
  3. dita install https://github.com/jason-fox/fox.jason.passthrough.pandoc/archive/master.zip

The dita command line tool requires no additional configuration.


Installing Pandoc

To download a copy follow the instructions on the Install page

If running DITA-OT with the Oxygen editor on Mac OS, and if you start Oxygen from the Terminal using sh oxygen.sh in the Oxygen installation
folder, when Oxygen runs the DITA OT, the build file manages to run the pandoc executable. Starting Oxygen by double clicking the shortcut
in the Finder, does not work reliably, it works only if the path to the Pandoc executable /usr/local/bin/ is fully specified in the configuration file.
fox.jason.passthrough.pandoc/cfg/configuration.properties

Usage

To mark a file to be passed through for Pandoc processing, label it with format="pandoc" within the *.ditamap as
shown:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE bookmap PUBLIC "-//OASIS//DTD DITA BookMap//EN" "bookmap.dtd">
  3. <bookmap>
  4. ...etc
  5. <chapter format="pandoc" href="sample.docx"></chapter>
  6. </bookmap>

The additional file will run against the Pandoc XXX-to-DITA lua filter to be converted to a *.dita file and will be
added to the build job without further processing. The navtitle of the included topic will be the same as root name of
the file. Any underscores in the filename will be replaced by spaces in title.

How to annotate Pandoc passthrough files

The examples below use Markdown as a passthrough format, other formats need to provide equivalent annotations to obtain
full functionality. Where possible, annotation aligns with the
Markdown DITA syntax reference based on
CommonMark. The chapter title is taken from the first header found. Thereafter the document
is processed as expected:

  1. # Chapter title
  2. The abstract (if any) goes here...
  3. ## Topic 1
  4. Body of topic 1 goes here.
  5. ## Topic 2
  6. Body of topic 2 goes here.
  7. ...etc

Ideally input files should only contain a single <h1> header

ID and outputclass

Pandoc header_attributes can be used to define id or
outputclass attributes:

  1. # Topic title {#carrot .juice}

Sections

The following class values in header_attributes have a
special meaning on header levels.

  • section
  • example

They are used to generate <section> and <example> elements:

  1. # Topic title
  2. ## Section title {.section}
  3. ## Example title {.example}

Note

The following class values in header_attributes has a
special meaning on header levels.

  • note

They are used to generate <note> elements:

  1. # Topic title
  2. Contents of the topic go here ...
  3. ---
  4. ## Note|Warning|Tip|Important {.note}
  5. Contents of the note
  6. ---
  7. Contents of the topic continue here ...

The type of the note is defined by the title of the header. The <note> will continue until the next header element
or horizontal rule ---, which ever comes sooner

Metadata

YAML metadata block as defined in Pandoc pandoc_metadata_block can be used to specify different
metadata elements. The supported elements are:

  • author
  • source
  • publisher
  • permissions
  • audience
  • category
  • keyword
  • resourceid
  • shortdesc

Unrecognized keys are output using data element.

  1. ---
  2. author:
  3. - Author One
  4. - Author Two
  5. source: Source
  6. publisher: Publisher
  7. permissions: Permissions
  8. audience: Audience
  9. category: Category
  10. keyword:
  11. - Keyword1
  12. - Keyword2
  13. resourceid:
  14. - Resourceid1
  15. - Resourceid2
  16. workflow: review
  17. ---
Sample output with YAML header
  1. <title>Sample with YAML header</title>
  2. <prolog>
  3. <author>Author One</author>
  4. <author>Author Two</author>
  5. <source>Source</source>
  6. <publisher>Publisher</publisher>
  7. <permissions view="Permissions"></permissions>
  8. <metadata>
  9. <audience audience="Audience"></audience>
  10. <category>Category</category>
  11. <keywords>
  12. <keyword>Keyword1</keyword>
  13. <keyword>Keyword2</keyword>
  14. </keywords>
  15. </metadata>
  16. <resourceid appid="Resourceid1"></resourceid>
  17. <resourceid appid="Resourceid2"></resourceid>
  18. <data name="workflow" value="review"></data>
  19. </prolog>

Ditamap TopicMeta for Pandoc Files

Ditamap <topicmeta> processing is also supported.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE bookmap PUBLIC "-//OASIS//DTD DITA BookMap//EN" "bookmap.dtd">
  3. <bookmap>
  4. <chapter format="pandoc" processing-role="normal" type="topic" href="markdown.md">
  5. <topicmeta>
  6. <shortdesc>This is where the shortdesc goes</shortdesc>
  7. <metadata>
  8. <keywords>
  9. <keyword>Keyword1</keyword>
  10. <keyword>Keyword2</keyword>
  11. </keywords>
  12. </metadata>
  13. </topicmeta>
  14. </chapter>
  15. </bookmap>

This allows for topic metadata to be added to files for formats other than Markdown.

License

Apache 2.0 © 2019 - 2024 Jason Fox