7a5870dc09
* Added CSS based on Docco (blatantly copied). * Updated sample text to better fit the emerging usage patterns. Some of the things I did to make it render nicely for the Literate output may cause problems when we go to render API output. I will cross that bridge when I come to it. * Added parsing infrastructure to the Generator behaviour to allow a pre-processing pass over the document. Current the LiterateMarkdownGenerator is using this to compile a map of `@org` references. * Tweaked the HTML output slightly. * Added a layer over the PegDownProcessor in LiterateMarkdownGenerator to capture and transform `jlp://` links into relative links.
79 lines
2.5 KiB
Groovy
79 lines
2.5 KiB
Groovy
import com.jdblabs.jlp.*
|
|
import com.jdblabs.jlp.experimental.LiterateMarkdownGenerator
|
|
import org.parboiled.Parboiled
|
|
import org.parboiled.parserunners.ReportingParseRunner
|
|
import org.parboiled.parserunners.RecoveringParseRunner
|
|
|
|
makeParser = {
|
|
println "Making the standard parser."
|
|
println "---------------------------"
|
|
|
|
parser = Parboiled.createParser(JLPPegParser.class)
|
|
parseRunner = new ReportingParseRunner(parser.SourceFile())
|
|
}
|
|
|
|
makeExperimentalParser = {
|
|
println "Making the experimental parser."
|
|
println "-------------------------------"
|
|
|
|
parser = Parboiled.createParser(com.jdblabs.jlp.experimental.JLPPegParser.class)
|
|
parseRunner = new ReportingParseRunner(parser.SourceFile())
|
|
}
|
|
|
|
simpleTest = {
|
|
println "Parsing the simple test into 'result'."
|
|
println "--------------------------------------"
|
|
|
|
testLine = """%% This the first test line.
|
|
%% Second Line
|
|
%% Third Line \n\n Fifth line \n\n %% Seventh line \n\n
|
|
%% @author Eigth Line
|
|
%% @Example Ninth Line
|
|
%% Markdown lines (tenth line)
|
|
%% Still markdown (eleventh line)
|
|
Twelfth line is a code line"""
|
|
|
|
simpleResult = parseRunner.run(testLine)
|
|
}
|
|
|
|
vbsTest = {
|
|
println "Parsing vbs_db_records.hrl into 'vbsResult'."
|
|
println "--------------------------------------------"
|
|
|
|
vbsTestFile = new File('vbs_db_records.hrl')
|
|
println "vbsTestFile is ${vbsTestFile.exists() ? 'present' : 'absent'}."
|
|
vbsTestInput = vbsTestFile.text
|
|
|
|
vbsParsed = parseRunner.run(vbsTestInput)
|
|
|
|
vbsResult = MarkdownGenerator.generateDocuments([vbs: vbsParsed.resultValue]).vbs
|
|
|
|
println "Writing to file 'vbs_result.html'."
|
|
println "----------------------------------"
|
|
|
|
(new File('vbs_result.html')).withWriter { out -> out.println vbsResult }
|
|
|
|
return [vbsParsed, vbsResult]
|
|
}
|
|
|
|
experimentalTest = {
|
|
makeExperimentalParser()
|
|
|
|
println "Parsing vbs_db_records.hrl into 'vbsResult'."
|
|
println "--------------------------------------------"
|
|
|
|
vbsTestFile = new File('vbs_db_records.hrl')
|
|
println "vbsTestFile is ${vbsTestFile.exists() ? 'present' : 'absent'}."
|
|
vbsTestInput = vbsTestFile.text
|
|
|
|
vbsParsed = parseRunner.run(vbsTestInput)
|
|
|
|
vbsResult = LiterateMarkdownGenerator.generateDocuments(["vbs_db_records.hrl": vbsParsed.resultValue])."vbs_db_records.hrl"
|
|
|
|
println "Writing to file 'vbs_result.html'."
|
|
println "----------------------------------"
|
|
|
|
(new File('vbs_result.html')).withWriter { out -> out.println vbsResult }
|
|
|
|
}
|