Java Markdown Processing On z/OS

(Originally posted 2016-05-01.)

In Episode 1 of MPT Podcast we discussed Markdown and Marna asked me if it could be run on z/OS. My answer was “you could try a Python Markdown processor via Jython”.[1]

Then, on IBM-MAIN, Dave Griffiths suggested using one of the Java Markdown processors, instead of Jython.

So I got to experimenting:

  1. I downloaded Java Markdown to my Linux machine. It’s a jar file.
  2. I wrote a short wrapper program in Java and tested it.

Here’s the program. Feel free to swipe it and improve on it.

import org.markdown4j.Markdown4jProcessor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Markdown {
  public static void main(String[] args) {
    String markdownSource="",inputLine;

    try {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      while((inputLine=br.readLine())!=null){
        markdownSource+=inputLine+"\n";
      }

      String html=new Markdown4jProcessor().process(markdownSource);
      System.out.println(html);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}

Then I uploaded the jar file[2] and the class file (without ASCII to EBCDIC translation) and tested again. No problems with that.

But it gets better…

Drawing on this post I wrote some wrapper REXX.

The REXX is here:

/* REXX */
env.0=1
env.1="CLASSPATH="
env.1=env.1"/u/userhfs/pmmpac/markdown4j/markdown4j-2.2-cj-1.0.jar"
env.1=env.1":/u/userhfs/pmmpac/markdown4j"

stdin.0=11
stdin.1="###A Heading"
stdin.2=""
stdin.3="First Paragraph"
stdin.4=""
stdin.5="Second Paragraph"
stdin.6=""
stdin.7="* Bullet 1"
stdin.8=""
stdin.9="* Bullet 2"
stdin.10=""
stdin.11="Third paragraph"

cmd="/usr/lpp/java/J7.0/bin/java Markdown"

call bpxwunix cmd,stdin.,stdout.,stderr.,env.

say "stdout:"
do i=1 to stdout.0
  say stdout.i
end

say "stderr:"
do i=1 to stderr.0
  say stderr.i
end

and the JCL:

//STEP10 EXEC PGM=IKJEFT1B,REGION=0M
//SYSEXEC DD DISP=SHR,DSN=PMMPAC.MARKDOWN.JCL
//SYSTSPRT DD SYSOUT=K,HOLD=YES
//SYSTSIN DD *
  %MARKDOWN
/*

Again, feel free to swipe and improve.

  1. I set up the env. stem variable so the environment is right for the java program to execute.
  2. I fill the stdin. stem variable with the Markdown I want to process. This will be the stdin.
  3. I invoke BPXWUNIX to run the java program.
  4. I print the contents of stdout (stored in the stdout. stem variable.)
  5. I print the contents of stderr (stored in the stderr. stem variable.)

The net effect is I can invoke a Markdown processor from REXX on z/OS in Batch and postprocess the HTML generated to my heart’s content.

One example might be injecting some CSS or some javascript.

I would argue this is easier than having your REXX generate HTML in the first place.

And part of the beauty of this is the Java is zIIP-eligible.

The sample program is just a toy, illustrating the principle. I’m sure there’s much more that could be done with it. Have fun!


  1. I’ve talked about Jython on z/OS before  ↩

  2. The jar file I used was markdown4j–2.2-cj–1.0.jar  ↩

Published by Martin Packer

.

One thought on “Java Markdown Processing On z/OS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: