From 7720004acc07bdbd494bfff5b6061a0d220ddcd5 Mon Sep 17 00:00:00 2001
From: Rene' Jeschke
Date: Sat, 16 Apr 2011 23:48:52 +0200
Subject: [PATCH] Added extensions, ratched IOException inside of
Processor.process(String), updated README.
---
README.md | 82 +++++++++++++++++++++++++++++++++
src/java/txtmark/Processor.java | 55 ++++++++++++++++------
2 files changed, 123 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 285881e..f6882ef 100644
--- a/README.md
+++ b/README.md
@@ -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:
+
+
+
+
+ Quote
+
+
+
+ and this when produced with Txtmark:
+
+
+
+ Another one:
+
+ * List
+ ====
+
+ will produce when processed with Markdown:
+
+ * List
+
+ and this when produced with Txtmark:
+
+
+
+### 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:
+
+ This is a paragraph
+ * and this is not a list
+
+ When using Txtmark extensions this changes to:
+
+ This is a paragraph
+
+ - and this is not a list
+
+
+* More to come ...
+
### Markdown conformity
diff --git a/src/java/txtmark/Processor.java b/src/java/txtmark/Processor.java
index 913eb0b..28c3c99 100644
--- a/src/java/txtmark/Processor.java
+++ b/src/java/txtmark/Processor.java
@@ -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