Skip to content

Commit

Permalink
Replaced grails markdown plugin with commonmark #3419
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Jan 23, 2025
1 parent eeb65f0 commit 54f84c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ dependencies {
exclude module: "xercesImpl"
}
implementation 'org.grails.plugins:grails-cookie:2.0.3'
implementation 'org.grails.plugins:grails-markdown:3.0.0'

implementation 'org.apache.poi:ooxml-schemas:1.4'
implementation 'org.apache.poi:poi:4.1.2'
Expand All @@ -150,7 +149,8 @@ dependencies {
implementation "commons-io:commons-io:2.6"
implementation "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0"
implementation "com.bertramlabs.plugins:asset-pipeline-grails:$assetPipelineVersion"
implementation group: 'com.googlecode.owasp-java-html-sanitizer', name: 'owasp-java-html-sanitizer', version: '20220608.1'
implementation "org.commonmark:commonmark:0.24.0"
implementation "com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20240325.1"

compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
Expand Down
10 changes: 7 additions & 3 deletions grails-app/taglib/au/org/ala/merit/FCTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import au.org.ala.cas.util.AuthenticationCookieUtils
import au.org.ala.merit.config.ProgramConfig
import au.org.ala.web.AuthService
import bootstrap.Attribute
import com.naleid.grails.MarkdownService
import grails.converters.JSON
import grails.web.servlet.mvc.GrailsParameterMap
import groovy.util.logging.Slf4j
Expand All @@ -16,6 +15,8 @@ import org.owasp.html.HtmlChangeListener
import org.owasp.html.HtmlPolicyBuilder
import org.owasp.html.PolicyFactory
import org.owasp.html.Sanitizers
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer

@Slf4j
class FCTagLib {
Expand All @@ -25,7 +26,6 @@ class FCTagLib {
def commonService
def userService
def settingService
MarkdownService markdownService
AuthService authService
MetadataService metadataService

Expand Down Expand Up @@ -1174,7 +1174,11 @@ class FCTagLib {
}

private String markdownToHtmlAndSanitise(String text) {
String html = markdownService.markdown(text)
Parser parser = Parser.builder().build()
org.commonmark.node.Node document = parser.parse(text)
HtmlRenderer renderer = HtmlRenderer.builder().build()
String html = renderer.render(document)

internalSanitise(policy, html)
}

Expand Down

0 comments on commit 54f84c8

Please sign in to comment.