{"id":27696697,"url":"https://github.com/alipsa/groovymarkdown","last_synced_at":"2026-04-02T01:08:56.967Z","repository":{"id":49325792,"uuid":"517337906","full_name":"Alipsa/GroovyMarkdown","owner":"Alipsa","description":"Groovy Markdown processor","archived":false,"fork":false,"pushed_at":"2026-02-05T15:06:21.000Z","size":17392,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-06T01:37:26.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alipsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-24T13:55:01.000Z","updated_at":"2026-02-05T15:09:52.000Z","dependencies_parsed_at":"2024-07-14T15:02:09.343Z","dependency_job_id":"e907b908-90a6-4551-a793-07a6a3147b4b","html_url":"https://github.com/Alipsa/GroovyMarkdown","commit_stats":null,"previous_names":["alipsa/groovymarkdown"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/Alipsa/GroovyMarkdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2FGroovyMarkdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2FGroovyMarkdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2FGroovyMarkdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2FGroovyMarkdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alipsa","download_url":"https://codeload.github.com/Alipsa/GroovyMarkdown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2FGroovyMarkdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31293647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:05:07.454Z","status":"ssl_error","status_checked_at":"2026-04-02T00:56:46.496Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-25T15:12:29.242Z","updated_at":"2026-04-02T01:08:56.953Z","avatar_url":"https://github.com/Alipsa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maven Central](https://maven-badges.herokuapp.com/maven-central/se.alipsa.gmd/gmd-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/se.alipsa.gmd/gmd-core)\n[![javadoc](https://javadoc.io/badge2/se.alipsa.gmd/gmd-core/javadoc.svg)](https://javadoc.io/doc/se.alipsa.gmd/gmd-core)\n# gmd - Groovy Markdown\n\nGroovy markdown is basically markdown with some groovy code for dynamic rendering.\nIt is based on the GmdTemplateEngine and the [Commonmark\nMarkdown package](https://commonmark.org/).\n\nA gmd file (or text) is markdown with groovy code in codeblocks starting with \\```{groovy} and ending with \\```\n(similar to rmd and mdr files) and \\`= \\` for direct value output.\n\nHere is an example:\n\n```markdown\n    # The thing\n    Here it is\n    ```{groovy}\n      import java.time.LocalDate\n      import java.time.format.TextStyle\n      import java.util.Locale\n\n      def now = LocalDate.parse(\"2022-07-23\")\n      def dayName(theDate) {\n        return theDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())\n      }\n      out.println \"## Today (\" + dayName(now) + \") is \" + now + \".\"\n    ```\n    How about that?    \n```\nThis will generate the following markdown\n````markdown\n# The thing\nHere it is\n```groovy\n  import java.time.LocalDate\n  import java.time.format.TextStyle\n  import java.util.Locale\n\n  def now = LocalDate.parse(\"2022-07-23\")\n  def dayName(theDate) {\n    return theDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())\n  }\n  out.println \"## Today (\" + dayName(now) + \") is \" + now + \".\"\n```\n## Today (Saturday) is 2022-07-23.\n\nHow about that?\n````\nIf you don't want to echo the code in the Markdown document you can set the\necho property to false e.g. \\```{groovy echo=false}\n\nInline variables (similar to the \u003c%= expression %\u003e syntax in scriptlets) can be done using \\`= expression \\`\nhere is an example:\n````markdown\n```{groovy echo=false}\n    aVal = 123 + 234\n```\n123 + 234 = `= aVal `\n````\nWhich will result in\n```markdown\n123 + 234 = 357\n```\n\nThis kind of Markdown text can then be transformed to html and pdf using the Gmd class e.g:\n```groovy\ndef gmd = new se.alipsa.gmd.core.Gmd()\n// html is a string of html markup\ndef html = gmd.gmdToHtml(text)\n\n// create a pdf file from the html\ndef pdfFile = File.createTempFile(\"weather\", \".pdf\")\ngmd.htmlToPdf(html, pdfFile)\n```\n\nIf you want to pass parameters to be used in the gmd text/file you can do that like this:\n```groovy\ndef text = 'Hello `=name`!'\ndef gmd = new se.alipsa.gmd.core.Gmd()\ndef md = gmd.gmdToMd(text, [name: \"Per\"])\n\n// Or directly to html\ndef html = gmd.gmdToHtml(text, [name: \"Per\"])\n\n// the html can then be used to create a pdf\ngmd.htmlToPdf(html, [name: \"Per\"], new File(\"pdfFile.pdf\"))\n```\n\nGMD supports the [Matrix](https://github.com/Alipsa/matrix) library directly, i.e. Matrix, Chart and MatrixXChart \ntypes can be used with the `out` PrintWriter object without needing to convert them into markdown first. \nHere is an example:\n````\n# Employees\n    \n```{groovy echo=false}\nimport static se.alipsa.matrix.core.ListConverter.*\n\nimport se.alipsa.matrix.core.*\nimport se.alipsa.matrix.xchart.*\nimport java.time.LocalDate \n\nimport static se.alipsa.matrix.core.ListConverter.*\n\n// if we dont do def or specify the type, the variable will be \"global\" and can be \n// used in subsequent code blocks\nempData = Matrix.builder().data(\n            emp_id: 1..5,\n            emp_name: [\"Rick\",\"Dan\",\"Michelle\",\"Ryan\",\"Gary\"],\n            salary: [623.3,515.2,611.0,729.0,843.25],\n            start_date: toLocalDates(\"2012-01-01\", \"2013-09-23\", \"2014-11-15\", \"2014-05-11\", \"2015-03-27\"))\n            .types(int, String, Number, LocalDate)\n            .build()\nBarChart chart = BarChart.create(empData, 800, 600)\n        .setTitle(\"Salaries\")\n        .addSeries(\"Salaries\", \"emp_name\", \"salary\")\nout.println(chart)\n```\n## Employee details\n```{groovy echo=false}\nout.println(empData)\n```\n\n````\nFor \"Special\" characters e.g. match symbol, you could use the html escape codes. E.g.\nto write `X = ∑(√2π + ∛3)`, you could do `X = \u0026amp;sum;(\u0026amp;radic;2\u0026amp;pi; + \u0026amp;#8731;3)` and scope the \nexpression with parenthesis as appropriate. Otherwise, it will show up as `X = ?(?2? + ?3)` when you turn it into html or pdf.\nSee [HTML Math Symbols](https://www.toptal.com/designers/htmlarrows/math/) for an extensive list.\nAn alternative is to generate a whole html doc encoded in UTF-8 that includes unicode fonts. \nThe gmdToHtmlDoc() and mdToHtmlDoc() does just that. Those methods also includes highlightJs and Bootstrap in the html.\n\nHighlightJS requires the execution of the highligtJs init script for the code sections to be properly formatted. \nIn order for this to happen, the html code need to be rendered in a browser with javascript support. \n\nGmd supports processing the javascript by running it in the JavaFx WebView as in the following \nexample usage:\n\n```groovy\ndef text = \"\"\"\n# Test\n\n\u0026grave;\u0026grave;\u0026grave;{groovy echo=false}\ndef a = 3\nfor (i in 1..a) {\n  out.println('Hello ' + i)  \n}\n\u0026grave;\u0026grave;\u0026grave;\n\n- first \n- second\n\n\u0026grave;\u0026grave;\u0026grave;groovy\ndef q = 213\nprintln('q is ' + q)\n\u0026grave;\u0026grave;\u0026grave;\n \nX = ∑(√2π + ∛3) = `=Math.sqrt(2* Math.PI) + Math.cbrt(3)`\n\"\"\"\ndef gmd = new Gmd()\ndef html = gmd.gmdToHtmlDoc(text)\n\n// create a pdf file from the html\ndef pdfFile = File.createTempFile(\"test\", \".pdf\")\ngmd.processHtmlAndSaveAsPdf(html, pdfFile)\n```\nAlternatives to using JavaFx WebView might be [Web-K](https://github.com/Earnix/Web-K) or [J2V8](https://github.com/eclipsesource/J2V8)\n, but I have not tested any of those.\n\nTo use it from within a JavaFx application see the [GmdTestGui](https://github.com/Alipsa/gmd/tree/main/GmdTestGui/src/main/groovy/se/alipsa/gmdtest/GmdTestGui.groovy) \nfor an approach that I found to provide the best performance and usability.\n\nThe library, which requires Java 21 or later, is available from maven central:\n\nGradle: \n```groovy\ndef groovyVersion = '5.0.4' // any 4.x version should work\nimplementation \"se.alipsa.gmd:gmd-core:3.0.2\"\nimplementation \"org.apache.groovy:groovy:${groovyVersion}\"\nimplementation \"org.apache.groovy:groovy-templates:${groovyVersion}\"\nimplementation \"org.apache.groovy:groovy-jsr223:${groovyVersion}\"\nimplementation 'org.apache.ivy:ivy:2.5.3'\n```\n\nMaven:\n```xml\n\u003cbuild\u003e\n  \u003cdependencies\u003e  \n    \u003cdependency\u003e\n      \u003cgroupId\u003ese.alipsa.gmd\u003c/groupId\u003e\n      \u003cartifactId\u003egmd-core\u003c/artifactId\u003e\n      \u003cversion\u003e3.0.2\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.apache.groovy\u003c/groupId\u003e\n      \u003cartifactId\u003egroovy\u003c/artifactId\u003e\n      \u003cversion\u003e5.0.4\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.apache.groovy\u003c/groupId\u003e\n      \u003cartifactId\u003egroovy-templates\u003c/artifactId\u003e\n      \u003cversion\u003e5.0.4\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.apache.groovy\u003c/groupId\u003e\n      \u003cartifactId\u003egroovy-jsr223\u003c/artifactId\u003e\n      \u003cversion\u003e5.0.4\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.apache.ivy\u003c/groupId\u003e\n      \u003cartifactId\u003eivy\u003c/artifactId\u003e\n      \u003cversion\u003e2.5.3\u003c/version\u003e\n    \u003c/dependency\u003e\n  \u003c/dependencies\u003e\n\u003c/build\u003e\n```\n## Using Gmd from the command line\nThe release artifacts on github contains a fat jar (e.g. gmd-3.0.0.jar)\nthat enables you to use Gmd from the command line.\n```\njava -jar gmd-3.0.2.jar toHtml test.gmd test.html\n```\nor for a pdf:\n```\njava -jar gmd-3.0.2.jar toPdf test.gmd test.pdf\n```\nNote: If you don't want the styled (highlight) PDF version you can use toPdfRaw instead.\n\n## Using Gmd in Gradle\n\nThe gmd-gradle-plugin is a gradle plugin that allows you to use Gmd in your gradle build.\nUsage is a follows:\n```groovy\nplugins {\n  id 'se.alipsa.gmd.gmd-gradle-plugin'\n}\ngmdPlugin {\n  sourceDir = 'src/test/gmd'\n  targetDir = 'build/gmd'\n  outputType = 'md' // or 'html' or 'pdf'\n}\n```\nSee the [gmd-gradle-plugin/readme](gmd-gradle-plugin/readme.md) for more details.\n\n## Using Gmd in Maven\nThe gmd-maven-plugin is a maven plugin that allows you to use Gmd in your maven build.\nUsage is a follows:\n```xml\n  \u003cbuild\u003e\n    \u003cplugins\u003e\n      \u003cplugin\u003e\n        \u003cgroupId\u003ese.alipsa.gmd\u003c/groupId\u003e\n        \u003cartifactId\u003egmd-maven-plugin\u003c/artifactId\u003e\n        \u003cgoals\u003e\u003cgoal\u003eprocessGmd\u003c/goal\u003e\u003c/goals\u003e\n        \u003cconfiguration\u003e\n          \u003csourceDir\u003esrc/test/gmd\u003c/sourceDir\u003e\n          \u003ctargetDir\u003etarget/gmd\u003c/targetDir\u003e\n          \u003coutputType\u003ehtml\u003c/outputType\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n    \u003c/plugins\u003e\n  \u003c/build\u003e\n```\nSee the [gmd-maven-plugin/readme](gmd-maven-plugin/readme.md) for more details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fgroovymarkdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falipsa%2Fgroovymarkdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fgroovymarkdown/lists"}