(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:
- I downloaded Java Markdown to my Linux machine. It’s a jar file.
- 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.
- I set up the
env.
stem variable so the environment is right for the java program to execute. - I fill the
stdin.
stem variable with the Markdown I want to process. This will be thestdin
. - I invoke BPXWUNIX to run the java program.
- I print the contents of
stdout
(stored in thestdout.
stem variable.) - I print the contents of
stderr
(stored in thestderr.
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!
-
The jar file I used was markdown4j–2.2-cj–1.0.jar ↩
One thought on “Java Markdown Processing On z/OS”