GithubHelp home page GithubHelp logo

markdownj's Introduction

README

Build Status

MarkdownJ is the pure Java port of Markdown (a text-to-html conversion tool written by John Gruber.)

Quick Start

If you're after the core functionality provided by MarkdownJ, add markdown-core as a dependency:

<dependency>
  <groupId>org.markdownj</groupId>
  <artifactId>markdownj-core</artifactId>
  <version>0.4</version>
</dependency>

Related Projects

License

The project is licensed under a Revised BSD License. Refer to the accompanying LICENSE file.

markdownj's People

Contributors

enr avatar gitter-badger avatar iceout avatar myabc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdownj's Issues

Web site expired?

"BUY THIS DOMAIN
The domain markdownj.org may be for sale by its owner!"

Markdown conversion stream -> stream

Currently the MarkdownProcessor takes in and returns a String. This can become very slow if the markdown if very large. Usually the actual markdown is accessed throw some io operation, like reading from a file of an http call, which with the current implementation requires the caller to convert the raw stream into an String. It would be much more efficient if the MarkdownProcessor would read the markdown dirrectly form the InputStream, and allow a String as a separate option.

Add OSGi metadata

I am interested in adding OSGi metadata to this project, to make it easier to consume in OSGi environments. The changes are built-time only, to ensure that proper metadata is added to the MANIFEST file.

Would you be interested in merging such a contribution?

Problem with escaping < and >

From [email protected] on November 21, 2011 12:31:11

Found a bug in markdownj compiled from trunk.

Here's class to reproduce it:

import com.petebevin.markdown.MarkdownProcessor;

public class Foo {

    public static void main(String[] args) {
        System.out.println(new MarkdownProcessor().markdown(
                "`y>x` foo `y<x` bar `y>x`"));
        System.out.println(new MarkdownProcessor().markdown(
                "`y>x` foo\n`y<x` bar\n`y>x`\n"));
    }   
}

The printed strings are

<p><code>y&gt;x</code> foo <code>y&lt;x` bar `y&gt;x</code></p>

and

<p><code>y&gt;x</code> foo
`y<x` bar
`y>x`</p>

I tracked the problem down to runSpanGamut() and escapeSpecialCharsWithinTagAttributes(). The latter tried to get text between < and > and replace special chars within those tokens, but the tokenizing is going wrong.

I noticed that in the original markdown runSpanGamut() does the code spans first and then does the special chars, so unless they've been swapped for some other reason, that's probably the way to fix it. Otherwise TextEditor.tokenizeHTML() will need to do a better job.

I've previously reported this to alex via email, but got no response.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=19

Underscores in links can generate undeeded em tags - SourceForge Issue #1996888

From alex.coles on October 28, 2008 01:21:14

Underscores in links can generate undeeded em tags

As an example:

[ http://www.mysite.com/my_folder/file/](http://www.mysite.com/my_folder/fil e/) to read the report. Also see: at
http://www.mysite.com/test?q=xx_yy to test.

Generates

http://www.mysite.com/myfolder/file/ to read the report. Also see: at http://www.mysite.com/test?q=xxyy to test.

This site shows the output from various processors, showing others also
exhibit this problem. http://babelmark.bobtfish.net/?markdown=&#37;5Bhttp&#37;3A&#37;2F&#37;2Fwww.mysite.com&#37;2Fmy _folder%2Ffile%2F%5D%28http%3A%2F%2Fwww.mysite.com%2Fmy_folder%2Ffile%2F+%2
2My+File%22%29+to+read+the+report.+Also+see%3A+at+%5Bhttp%3A%2F%2Fwww.mysit
e.com%2Ftest%3Fq%3Dxx_yy%5D%28http%3A%2F%2Fwww.mysite.com%2Ftest%3Fg%3Dxx_y
y+%22A+test%22%29+to+test.&normalize=on&src=1&dest=2

Mark Smithson
[email protected]

Original issue: http://code.google.com/p/markdownj/issues/detail?id=3

API documentation wanted

From [email protected] on August 02, 2009 09:26:14

Having some API documentation would help a lot, preferably javadoc, but a
simple wiki page will suffice. As it is, one downloads a .jar file and am
immediately stuck. What classes exist? What methods do they have?

It would be great if there were some way of finding out that's easier than
getting the source from git and then running javadoc on it.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=13

20 unit test failures on Windows Vista.

From [email protected] on April 30, 2009 21:13:06

What steps will reproduce the problem? 1. Get the latest trunk on Windows Vista SP1
2. run ant test
3. several unit tests fail. What is the expected output? What do you see instead? Expected would be to pass most of the tests. The jUnit report however shows
too many problems (see attachment). What version of the product are you using? On what version of the JDK? I'm using the latest from github. The JDK is 1.6, but the build.xml should
have the correct javac version setting. Please provide any additional information below. See attached test report generated by jUnit

Attachment: junit-noframes.html

Original issue: http://code.google.com/p/markdownj/issues/detail?id=8

Underscores around text gives performance problems - SourceForge Issue #2086757

From alex.coles on October 28, 2008 01:22:45

Underscores around text gives performance problems

I have discovered what appears to be a bug that can lead to rather severe
performance problems. The bug becomes evident when trying to "markdown"
strings similar to "_ _ _ _ _ _ text _ _ _ _ ". The easiest test case that
demonstrates this bug is the following code snippet: processor.markdown("

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ T");

After some testing, it seems like every additional "_ " BEFORE the "T" will
increase the time for "markdown" to execute doubles. When having 26 "_ "
(that is, underscore followed by space), the "markdown" takes about 100
seconds on my laptop. 25 "_ " takes around 50 seconds, and so on.

Below is the code snippet that can be used to reproduce the results.

If more details are needed, I can be contacted at Per Hallström
[email protected].

=== CODE ===
public void test2() {
String problematicPlaintext = "T";

for(int i=0;i<30;i++) {
long start = System.currentTimeMillis();
processor.markdown(problematicPlaintext);
long end = System.currentTimeMillis();
System.out.printf("i = %02d: %08d ms -- %56s\n", i,
(end-start), problematicPlaintext);
problematicPlaintext = "_ " + problematicPlaintext;
}
}

=== EXAMPLE OUTPUT ===

i = 15: 00000051 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 16: 00000096 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 17: 00000207 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 18: 00000405 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 19: 00000905 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 20: 00001514 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 21: 00003008 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 22: 00006115 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 23: 00012232 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 24: 00024220 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T
i = 25: 00048662 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
T

Original issue: http://code.google.com/p/markdownj/issues/detail?id=4

can't convert data to table

example:

column1 column2
value1 value1
value2 value2
value3 value3

code is convert table

   private TextEditor doTableRules(TextEditor text) {
    String[] paragraphs;
    if (text.isEmpty()) {
        paragraphs = new String[0];
    } else {
        paragraphs = Pattern.compile("\\n").split(text.toString());
    }
    String tablesRule = "^\\s*\\-{3,}(\\|\\-{3,})+[ ]*$";
    String tdRules = "^(.*\\|.*)+$";
    boolean find = false;
    int length = 0;
    for (int i = 0; i < paragraphs.length; i++) {
        String paragraph = paragraphs[i];
        if (find) {
            if (paragraph.matches(tdRules)) {
                String td = formatTd(paragraph, length);
                paragraphs[i] = td;
            } else {
                paragraphs[i - 1] += "<tbody></table>";
                find = false;
            }
        } else {
            if (paragraph.matches(tdRules) && i + 2 < paragraphs.length) {
                String head = paragraphs[i + 1];
                String content = paragraphs[i + 2];
                if (head.matches(tablesRule) && content.matches(tdRules)) {
                    length = head.split("\\|").length;
                    String table = formatTh(paragraph, length);
                    String td = formatTd(content, length);
                    paragraphs[i] = table;
                    paragraphs[i + 1] = "<tbody>";
                    paragraphs[i + 2] = td;
                    i += 2;
                    find = true;
                }
            }
        }
    }
    return new TextEditor(join("\n", paragraphs));
}

private String formatTh(String line, int length) {
    StringBuilder tr = new StringBuilder("<table><thead><tr>\n");
    String tds[] = line.split("\\|");
    for (String td : tds) {
        tr.append("<th>").append(StringUtils.trimToNull(td)).append("</th>\n");
    }
    for (int i = tds.length; i < length; i++) {
        tr.append("<th>&nbsp;</th>\n");
    }
    tr.append("</tr>\n</thead>\n");
    return tr.toString();
}

private String formatTd(String line, int length) {
    StringBuilder tr = new StringBuilder("<tr>\n");
    String tds[] = line.split("\\|");
    for (String td : tds) {
        tr.append("<td>").append(StringUtils.trimToNull(td)).append("</td>\n");
    }
    for (int i = tds.length; i < length; i++) {
        tr.append("<td>&nbsp;</td>\n");
    }
    tr.append("</tr>\n");
    return tr.toString();
}

Cant install from Maven

The maven snippet found on http://markdownj.org/

<dependency>
  <groupId>org.markdownj</groupId>
  <artifactId>markdownj</artifactId>
  <version>0.4.0</version>
</dependency>

leads to the following error:

Downloading: http://repo.maven.apache.org/maven2/org/markdownj/markdownj/0.4.0/markdownj-0.4.0.pom
[WARNING] The POM for org.markdownj:markdownj:jar:0.4.0 is missing, no dependency information available
...
[ERROR] Failed to execute goal on project slides: Could not resolve dependencies for project com.eclipsesource.trainings:slides:jar:0.0.1-SNAPSHOT: Could not find artifact org.markdownj:markdownj:jar:0.4.0 in central (http://repo.maven.apache.org/maven2) -> [Help 1]

java.lang.StackOverflowError on JDK 1.6

From alex.coles on October 31, 2008 00:26:59

What steps will reproduce the problem? 1. Use SoyLatte JDK
java version "1.6.0_03-p3"
Java(TM) SE Runtime Environment (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00)
Java HotSpot(TM) Server VM (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00, mixed
mode)

  1. Excecute MarkdownJ unit tests using "mvn test" What is the expected output? What do you see instead? MarkdownTestTester fails with the the StackOverflowError. Needs further investigation, but
    looking at stack trace, it looks as though there is some unlimited recursion going on in the RegEx
    engine.

This error is not reproducible using the latest version of the 32-bit JDK 5.0 for Leopard. Please use labels and text to provide additional information.

Attachment: com.petebevin.markdown.test.MarkdownTestTester.txt

Original issue: http://code.google.com/p/markdownj/issues/detail?id=6

CharacterProtector is not thread-safe, can lead to infinite loops

From [email protected] on December 23, 2011 18:59:29

One of our servers just tied itself in a knot when multiple threads got stuck in HashMap.put() and HashMap.get() via the CharacterProtector class.

One thread was stuck here:

java.util.HashMap.put(HashMap.java:391)
com.petebevin.markdown.CharacterProtector.addToken(CharacterProtector.java:68)
com.petebevin.markdown.CharacterProtector.encode(CharacterProtector.java:52)
com.petebevin.markdown.MarkdownProcessor$2.replacement(MarkdownProcessor.java:207)
com.petebevin.markdown.TextEditor.replaceAll(TextEditor.java:122)
com.petebevin.markdown.MarkdownProcessor.hashHTMLBlocks(MarkdownProcessor.java:210)
com.petebevin.markdown.MarkdownProcessor.markdown(MarkdownProcessor.java:89)

Every other thread was stuck here:

java.util.HashMap.get(HashMap.java:320)
com.petebevin.markdown.CharacterProtector.decode(CharacterProtector.java:58)
com.petebevin.markdown.MarkdownProcessor.formParagraphs(MarkdownProcessor.java:270)
com.petebevin.markdown.MarkdownProcessor.runBlockGamut(MarkdownProcessor.java:155)
com.petebevin.markdown.MarkdownProcessor.markdown(MarkdownProcessor.java:91)

The problem is that the access to HashMap is not done in a thread-safe manner. While every MarkdownProcessor involved is a separate instance, they all share a single, static CharacterProtector instance and, therefore, a single, static HashMap instance.

The HashMaps in the CharacterProtector class should probably be wrapped in Collection.synchronizedMap() instances.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=20

Strikethrough text

Strikethrough (~~ text here ~~) doesn't get properly parsed.

Sample input:

~~ Strike me ~~

Expected result:

<span style="text-decoration: line-through;">Strike me</span>

Actual result:

<p>~~ Strike me~~</p>

MarkdownJ is eating newlines.

From [email protected] on April 30, 2009 21:29:31

What steps will reproduce the problem? 1. Build Markdownj from the latest source
2. run it on some very simple files
3. newlines seem to be eaten - the generated content is very incomplete. What is the expected output? What do you see instead? Nice HTML, similar to what Maruku http://maruku.rubyforge.org/ generates
(or even better). Very bad HTML with many ignored transformations What version of the product are you using? On what version of the JDK? Latest from trunk (github) built on Windows Vista with JDK 1.6. Please provide any additional information below. Trying to migrate markdown pages generated previously with Maruku.
MarkdownJ fails mostly :(.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=10

Support Maven Doxia

From alex.coles on August 30, 2009 21:52:59

Supporting Maven Doxia would allow use of Markdown in Maven-generated sites (including our
own). Instead of transforming Markdown to HTML, the Markdown would be parsed and represented
using the Sink generic markup interface. It can then be transformed to PDF, HTML, or any of several
content formats.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=14

Mutiple plugins don't work if they are not separated by text

When I try something like this:

%%% plugin1
some text
%%%

%%% plugin2
some text
%%%

Only first plugin is processed. I must insert some text between plugins to get second one processed too.

And, second, plugin is not processed when its content is empty (nothing between %%% lines)

Add support for Markdown extensions.

From [email protected] on May 01, 2009 23:02:28

Please add support for Markdown extensions, e.g.: http://michelf.com/projects/php-markdown/extra/ since the original standard has quite a few limitations (besides even the
author suggests using extensions - not changing the standard).

Especially the impossibility to render inside block elements is very
missing from the standard :( : http://michelf.com/projects/php-markdown/extra/#markdown-attr Thank you,
A.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=11

Allow full HTML file generation.

From [email protected] on April 30, 2009 21:19:45

Please allow to generate complete HTML files too, not just the content of
the HTML body, so that other tools can use directly the output of MarkdownJ.
Example of such a method to MarkdownProcessor that works pretty well:

/**
* Perform the conversion from Markdown to HTML, generating a
"complete" file,
* and trying to put as title the first h1 element.
*
* @param txt input in markdown format
* @param complete if it should generate a complete HTML
* @return HTML complete file corresponding to txt passed in.
*/
public String markdown(String txt, boolean complete) {
String body =this.markdown(txt);
if(!complete)
return body;

    String result = "<html>\n  <head>\n    <title>";

    String title="NO TITLE";
    // try to extract the first h1 as a title
    // startsWith should be replaced with "startsWithIgnoreWhiteSpace"
    if(body.startsWith("<h1")) {
        int end = body.indexOf("</h1>");
        int start = 4; //body.indexOf("<h1>")+4;
        title = body.substring(start,end);
    }
    result+=title;
    result+="</title>\n  </head>\n<body>\n";
    result+=body;
    result+="\n</body>\n</html>";
    return result;
}

This method could be than used by the ANT filter and the command line too
(with the according parameter).
Having so as a separate method, is also backward compatible.

Thank you,
A.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=9

No support for Superscript text

From [email protected] on August 23, 2013 00:55:45

Hi

I have some markdown text that contains Links as well as Superscipts. When I process that markdown through the Markdown4jProcessor it is not handling Superscript. Here is my input Markdown.

INPUT

[Some Text]( http://example.com/ )

This text contains [superscript] text.

OUTPUT

<p><a href=" http://example.com/">Some Text</a></p>
<p>This text contains [superscript] text.</p>

The expected output should be

Some Text

This text contains superscript text.


I am using markdown4j-2.2.jar on JDK 6.

Please let me know if this could be done using some configuration or Do I need a custom solution

thanks.

Original issue: http://code.google.com/p/markdownj/issues/detail?id=21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.