Skip to content

Commit

Permalink
LDEV-5261 move markdown to an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jan 19, 2025
0 parents commit 552655a
Show file tree
Hide file tree
Showing 17 changed files with 867 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Java CI

on: [push, pull_request,workflow_dispatch]

jobs:
build:
runs-on: ubuntu-latest
env:
luceeVersion: light-6.2.0.284-SNAPSHOT
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ext-markdown
restore-keys: |
${{ runner.os }}-m2
maven-cache
- name: Cache Lucee files
uses: actions/cache@v4
with:
path: _actions/lucee/lucee-script-engine-runner/main/lucee-download-cache
key: lucee-downloads-${{ env.luceeVersion }}
restore-keys: |
lucee-downloads
- name: Build extension-markdown with Ant
run: ant -noinput -verbose -buildfile build.xml
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: markdown-lex
path: dist/*.lex
- name: Checkout Lucee
uses: actions/checkout@v4
with:
repository: lucee/lucee
path: lucee
- name: Run Lucee Test Suite, labels="markdown"
uses: lucee/script-runner@main
with:
webroot: ${{ github.workspace }}/lucee/test
execute: /bootstrap-tests.cfm
luceeVersion: ${{ env.luceeVersion }}
extensionDir: ${{ github.workspace }}/dist
extensions:
env:
testLabels: markdown
testAdditional: ${{ github.workspace }}/tests
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/dist
**/Test.java
**/.DS_Store
**/.svn/
/*.project
va specific
*.class
target
target/*
*.lock
*.DS_Store
temp
502 changes: 502 additions & 0 deletions License.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Lucee Markdown Extension

Uses the Commonmark markdown parser https://github.com/commonmark/commonmark-java

3 changes: 3 additions & 0 deletions build.number
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun Jan 19 11:29:42 CET 2025
build.number=1
9 changes: 9 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundlename: markdown.extension
filename: markdown-extension
bundleversion: 0.0.0.
id: 3AEDA748-F62B-42E3-8E8DC5AE0DDABE09
luceeCoreVersion: 5.3.0.0
releaseType: server
appendix: -SNAPSHOT
label: Markdown Extension
description: Extension to convert Markdown to HTML using Commonmark
161 changes: 161 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<project default="clean" basedir="." name="markdown-extension">
<description>
Build Markdown Extension
</description>
<!-- set global properties for this build -->

<property file="build.properties" />

<property name="lib" location="source/java/libs" />
<property name="src" location="source/java/src" />
<property name="srcImg" location="source/images" />
<property name="temp" location="temp" />
<property name="build" location="build" />
<property name="dist" location="dist" />

<property name="tld" location="source/tld" />
<property name="fld" location="source/fld" />


<buildnumber file="build.number" />

<scriptdef name="replace" language="javascript">
<attribute name="haystack" />
<attribute name="needle" />
<attribute name="repl" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("haystack");
var needle = attributes.get("needle");
var repl = attributes.get("repl");
text=text.trim();
var regex = new RegExp(needle,'g');
text=text.replace(regex,repl);
project.setProperty(attributes.get("property"), text);
]]>
</scriptdef>

<path id="classpath">
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</path>

<target name="init">
<!-- Create the time stamp -->
<tstamp />

<delete dir="${temp}" />
<delete dir="${dist}" />

<!-- Create the build directory structure used by compile -->
<mkdir dir="${temp}" />
<mkdir dir="${build}" />
<mkdir dir="${dist}/" />
</target>


<target name="copy" depends="init" description="copy source file to temp">
<!-- copy the source -->
<copy todir="${temp}">
<fileset dir="${src}">
<include name="**/*.java" />
<exclude name="**/Test.java" />
</fileset>
</copy>

<tstamp>
<format property="NOW" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>

<echo file="${dist}/extension/META-INF/MANIFEST.MF">Manifest-Version: 1.0
Built-Date: ${NOW}
version: "${bundleversion}${build.number}${appendix}"
id: "${id}"
name: "${label}"
description: "${description}"
lucee-core-version: "${luceeCoreVersion}"
release-type: ${releaseType}
start-bundles: false
</echo>
</target>

<target name="compile" depends="copy"
description="compile the source ">
<!-- Compile ACF-Infinspan source -->
<javac srcdir="${temp}" source="11" target="11" destdir="${build}" debug="true"
debuglevel="lines,vars,source">
<classpath refid="classpath" />
</javac>
</target>

<target name="dist" depends="compile"
description="generate the distribution">
<!-- copy the source -->
<echo>-------------------------</echo>
<copy todir="${build}">
<fileset dir="${src}">
<include name="**/*.jar" />
</fileset>
</copy>
<!-- Put everything in ${build} into .jar file -->
<jar
jarfile="${dist}/extension/jars/${filename}-${bundleversion}${build.number}${appendix}.jar"
basedir="${build}" manifest="${src}/META-INF/MANIFEST.MF">
<manifest>
<attribute name="Bundle-Version" value="${bundleversion}${build.number}${appendix}" />
<attribute name="Built-Date" value="${NOW}" />
<attribute name="Bundle-SymbolicName" value="${bundlename}" />
</manifest>
</jar>

<!-- copy the flds necessary -->
<loadfile property="content1" srcFile="${fld}/function.fld" />
<replace haystack="${content1}" needle="{bundle-name}" repl="${bundlename}" property="content2" />
<replace haystack="${content2}" needle="{bundle-version}"
repl="${bundleversion}${build.number}${appendix}" property="content3" />
<echo message="${content3}" file="${dist}/extension/flds/markdownToHtml.fld" />

<!-- copy the jars necessary -->
<copy todir="${dist}/extension/jars">
<fileset dir="${lib}">
<include name="**/*.jar" />
<exclude name="**/javax.*" />
<exclude name="**/jsp-*" />
<exclude name="**/lucee.jar" />
<exclude name="**/org.apache.felix.framework-*" />

<!-- we exclude this because this is part of the Lucee core and in worst case it is loaded
on the fly -->
<exclude name="**/httpcomponents-*" />
<exclude name="**/org.lucee.httpcomponents.*" />
<!-- <exclude name="**/org.apache.commons.codec-*"/> -->
<exclude name="**/commons-codec-*" />
<exclude name="**/log4j-*" />
<exclude name="**/javax-mail-activation-*" />
</fileset>
</copy>

<!-- copy the logo -->
<copy todir="${dist}/extension/META-INF">
<fileset dir="${srcImg}/">
<include name="logo.png" />
</fileset>
</copy>

<!-- Zip everything -->
<zip destfile="${dist}/${filename}-${bundleversion}${build.number}${appendix}.lex">
<zipfileset dir="${dist}/extension" />
</zip>

</target>

<target name="clean" depends="dist" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}" />
<delete dir="${temp}" />
</target>

</project>
49 changes: 49 additions & 0 deletions source/fld/function.fld
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE func-lib PUBLIC "-//Railo//DTD CFML Function Library 1.0//EN"
"dtd/web-cfmfunctionlibrary_1_0.dtd">
<!-- http://www.getrailo.com/j2ee/dtd/web-jspfunctionlibrary_1_0.dtd -->
<func-lib>
<flib-version>1.00</flib-version>
<short-name>Markdown</short-name>
<uri>http://extension.lucee.org/function/markdown</uri>
<display-name>Markdown</display-name>
<description>
Function to generate HTML from Markdown
</description>

<!-- MarkdownToHTML -->
<function>
<name>MarkdownToHTML</name>
<member-name>MarkdownToHTML</member-name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.markdown.functions.MarkdownToHTML</class>
<keywords>string</keywords>
<description>Transforms Markdown formatted String into HTML.</description>
<introduced>6.0.0.150</introduced>
<argument>
<name>string</name>
<alias>markdown</alias>
<type>string</type>
<required>Yes</required>
<description>A Markdown formatted string or a path to a file containf a markdown formatted string to convert to HTML</description>
</argument>
<argument>
<name>safeMode</name>
<type>boolean</type>
<alias>safe</alias>
<default>false</default>
<required>No</required>
<description>If set to true it does escape unsafe HTML tags</description>
</argument>
<argument>
<name>encoding</name>
<type>string</type>
<alias>charset</alias>
<required>No</required>
<description>Charset, only used in case the argument markdown contains a file path</description>
</argument>
<return>
<type>string</type>
</return>
</function>

</func-lib>
Binary file added source/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions source/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin
Binary file added source/java/libs/javax.servlet-api-3.1.0.jar
Binary file not shown.
Binary file added source/java/libs/jsp-api-2.2.jar
Binary file not shown.
Binary file added source/java/libs/lucee.jar
Binary file not shown.
Binary file added source/java/libs/org-lucee-commonmark-0-22-0.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions source/java/src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Export-Package: org.lucee.extension.markdown.functions
Bundle-ManifestVersion: 2
Require-Bundle: org.lucee.commonmark;bundle-version=0.22.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.lucee.extension.markdown.functions;

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
import lucee.runtime.PageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.BIF;
import lucee.runtime.util.Cast;
import lucee.runtime.util.Excepton;

public abstract class FunctionSupport extends BIF {

static CFMLEngine eng;
static Cast cast;
static Excepton exp;

static {
eng = CFMLEngineFactory.getInstance();
cast=eng.getCastUtil();
exp=eng.getExceptionUtil();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.lucee.extension.markdown.functions;

import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;

import lucee.runtime.PageContext;
import org.lucee.extension.markdown.functions.FunctionSupport;
import lucee.runtime.exp.PageException;


public class MarkdownToHTML extends FunctionSupport {

private static final long serialVersionUID = 3775127934350736736L;

public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length < 1 || args.length > 2) {
throw exp.createExpressionException("MarkdownToHTML requires between 1 and 3 arguments [string, safemode, encoding], but ["
+ args.length + " ] provided");
}
return call(pc, cast.toString(args[0]));
}

public static String call(PageContext pc, String markdown) {
return call(pc, markdown, false, null);
}

public static String call(PageContext pc, String markdown, boolean safeMode) {
return call(pc, markdown, safeMode, null);
}

public static String call(PageContext pc, String markdown, boolean safeMode, String encoding) {
Parser parser = Parser.builder().build();
// Parse the markdown to a Node
Node document = parser.parse(markdown);
// Create a HTML renderer
HtmlRenderer renderer = HtmlRenderer.builder().build();
// Render the Node to HTML
return renderer.render(document);
}

/*
* public static void main(String[] args) { print.e(Processor.process("This is ***TXTMARK***",
* false)); }
*/
}

0 comments on commit 552655a

Please sign in to comment.