Added extensions, ratched IOException inside of Processor.process(String), updated README.

This commit is contained in:
Rene' Jeschke 2011-04-16 23:48:52 +02:00
parent 658ef204a1
commit 7720004acc
2 changed files with 123 additions and 14 deletions

View File

@ -17,6 +17,88 @@ This is a RC version, tagged v0.5
For an in-depth explanation of the markdown syntax have a look at [daringfireball.net](http://daringfireball.net/projects/markdown/syntax).
### Where Txtmark is not like Markdown
***
* Txtmark does not produce empty `title` attributes in link and image tags.
* Unescaped `"` in link titles starting with `"` are not recognized and result
in unexpected behaviour.
* Due to a different list parsing approach some things get interpreted differently:
* List
> Quote
will produce when processed with Markdown:
<p><ul>
<li>List</p>
<blockquote>
<p>Quote</li>
</ul></p>
</blockquote>
and this when produced with Txtmark:
<ul>
<li>List<blockquote><p>Quote</p>
</blockquote>
</li>
</ul>
Another one:
* List
====
will produce when processed with Markdown:
<h1>* List</h1>
and this when produced with Txtmark:
<ul>
<li><h1>List</h1>
</li>
</ul>
### Txtmark extensions
***
To enable Txtmark's extended markdown parsing you can use the $PROFILE$ mechanism:
[$PROFILE$]: extended
This seemed to me as the easiest and safest way to enable different behaviours.
(All other markdown processors will ignore this line.)
#### Behavior changes when using `[$PROFILE$]: extended`
* Lists and code blocks end a paragraph (inspired by [Actuarius])
In normal markdown the following:
This is a paragraph
* and this is not a list
will produce:
<p>This is a paragraph
* and this is not a list</p>
When using Txtmark extensions this changes to:
<p>This is a paragraph</p>
<ul>
<li>and this is not a list</li>
</ul>
* More to come ...
### Markdown conformity

View File

@ -24,7 +24,9 @@ public class Processor
private final Reader reader;
/** The emitter. */
private final Emitter emitter;
/** Extension flag. */
private boolean useExtensions = false;
/**
* Constructor.
*
@ -41,11 +43,18 @@ public class Processor
*
* @param input The String to process.
* @return The processed String.
* @throws IOException if an IO error occurs
*/
public static String process(final String input) throws IOException
public static String process(final String input)
{
return process(new StringReader(input));
try
{
return process(new StringReader(input));
}
catch(IOException e)
{
// This _can never_ happen
return null;
}
}
/**
@ -53,11 +62,18 @@ public class Processor
*
* @param input The String to process.
* @return The processed String.
* @throws IOException if an IO error occurs
*/
public static String process(final String input, final Decorator decorator) throws IOException
public static String process(final String input, final Decorator decorator)
{
return process(new StringReader(input), decorator);
try
{
return process(new StringReader(input), decorator);
}
catch(IOException e)
{
// This _can never_ happen
return null;
}
}
/**
@ -305,13 +321,22 @@ public class Processor
}
}
if(isLinkRef)
// To make compiler happy: add != null checks
if(isLinkRef && id != null && link != null)
{
// Store linkRef and skip line
final LinkRef lr = new LinkRef(link, comment);
this.emitter.addLinkRef(id, lr);
if(comment == null)
lastLinkRef = lr;
if(id.toLowerCase().equals("$profile$"))
{
this.useExtensions = link.toLowerCase().equals("extended");
lastLinkRef = null;
}
else
{
// Store linkRef and skip line
final LinkRef lr = new LinkRef(link, comment);
this.emitter.addLinkRef(id, lr);
if(comment == null)
lastLinkRef = lr;
}
}
else
{
@ -397,7 +422,9 @@ public class Processor
while(line != null && !line.isEmpty)
{
final LineType t = line.getLineType();
if(listMode && (t == LineType.OLIST || t == LineType.ULIST))
if((listMode || this.useExtensions) && (t == LineType.OLIST || t == LineType.ULIST))
break;
if(this.useExtensions && (t == LineType.CODE))
break;
if(t == LineType.HEADLINE || t == LineType.HEADLINE1 || t == LineType.HEADLINE2
|| t == LineType.HR || t == LineType.BQUOTE