Skip to content

Commit

Permalink
Merge pull request scalate#13 from sroebuck/master
Browse files Browse the repository at this point in the history
PegDown filter
  • Loading branch information
jstrachan committed Dec 13, 2011
2 parents 932c15c + c044d89 commit 1b132a4
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
79 changes: 79 additions & 0 deletions scalate-pegdown/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009-2011 the original author or authors.
See the notice.md file distributed with this work for additional
information regarding copyright ownership.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fusesource.scalate</groupId>
<artifactId>scalate-project</artifactId>
<version>1.6.0-SNAPSHOT</version>
</parent>

<artifactId>scalate-pegdown</artifactId>
<packaging>bundle</packaging>

<name>${project.artifactId}</name>
<description>A Scalate filter that uses PegDown</description>

<properties>
</properties>

<dependencies>

<dependency>
<groupId>org.fusesource.scalate</groupId>
<artifactId>scalate-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.1.0</version>
</dependency>

<!-- testing -->
<dependency>
<groupId>org.fusesource.scalate</groupId>
<artifactId>scalate-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.scalatest</groupId>
<artifactId>${scalatest-artifact}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (C) 2009-2011 the original author or authors.
# See the notice.md file distributed with this work for additional
# information regarding copyright ownership.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

org.fusesource.scalate.filter.PegDownFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (C) 2009-2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fusesource.scalate.filter

/**
* Copyright (C) 2009-2010 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.fusesource.scalate.{TemplateEngineAddOn, RenderContext, TemplateEngine}
import org.fusesource.scalate.filter.Filter
import org.pegdown.{Extensions, PegDownProcessor}

/**
* Renders markdown syntax with multi-markdown like extras.
*
* @author <a href="stuart.roebuck@gmail.com">Stuart Roebuck</a>
*/
object PegDownFilter extends Filter with TemplateEngineAddOn {

private val pegDownProcessor = new PegDownProcessor(
Extensions.ABBREVIATIONS |
Extensions.AUTOLINKS |
Extensions.DEFINITIONS |
Extensions.FENCED_CODE_BLOCKS |
Extensions.QUOTES |
Extensions.SMARTS |
Extensions.TABLES |
Extensions.WIKILINKS
)

def filter(context: RenderContext, content: String) = {
synchronized {
// This code block is synchronized as the PegDownProcessor is not thread safe.
pegDownProcessor.markdownToHtml(content).stripLineEnd
}
}

/**
* Add the markdown filter to the template engine.
*/
def apply(te: TemplateEngine) = {
te.filters += "multimarkdown" -> PegDownFilter
te.pipelines += "mmd" -> List(PegDownFilter)
te.pipelines += "multimarkdown" -> List(PegDownFilter)
}
}

0 comments on commit 1b132a4

Please sign in to comment.