summaryrefslogtreecommitdiffstats
path: root/parsers
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2012-06-26 22:06:51 +0530
committerrsiddharth <rsiddharth@ninthfloor.org>2012-06-26 22:06:51 +0530
commit726314a77a2138f8d6bca200af9972e006f43311 (patch)
tree1f0ca34734309f018754d4edb51493dbab36b5a7 /parsers
parente3b2d9aa86d97154421e753d91856bc73a4be591 (diff)
conversion/FileSieve.java: modified the regex to ignore backup file (#*#).
parsers/Footer.java: Aesthetic modification. parsers/Header.java: add "meta" tags for the html output, mainly for compliance sake. I have also re-arranged the html tags a bit -- the "back button" is now the last thing in the <article> block. parsers/Images.java (bug-fix): The regex had small precisely deducting images, so the regex was slightly modified to make all work properly. There was another significant change made to the way the image tag is created -- "alt" is mandatory now, even if the markup doesn't give a "alt" for the <img> tag, a default "alt" is created -- the image-file-name. parsers/Links.java: From now on, the links generated will not have 'target="_blank"`, I felt that the reader must choose whether to open the link in a new window/tab, so the change. Period. In the last revision, link description was made optional in the link mark-up, the regex was slightly erroneous, I rectified it. parsers/Paragraphs.java: As of this revision, the <p> generation is still rough around the edges, I need to smoothen it in future revisions. parsers/ParserList.java: Order of parser list was modified -- now, Paragraphs comes before Headings, it was the reverse before.
Diffstat (limited to 'parsers')
-rw-r--r--parsers/Footer.java2
-rw-r--r--parsers/Header.java5
-rw-r--r--parsers/Images.java9
-rw-r--r--parsers/Links.java7
-rw-r--r--parsers/Paragraphs.java27
-rw-r--r--parsers/ParserList.java4
6 files changed, 36 insertions, 18 deletions
diff --git a/parsers/Footer.java b/parsers/Footer.java
index 4ff50ed..d949017 100644
--- a/parsers/Footer.java
+++ b/parsers/Footer.java
@@ -8,7 +8,7 @@ public class Footer implements Parser {
Matcher matcher = pattern.matcher(fileContent);
StringBuffer sbuffer = new StringBuffer();
while(matcher.find()) {
- PresentFile.footer = "<footer>"+matcher.group(1)+"</footer>";
+ PresentFile.footer = "<footer>"+matcher.group(1)+"</footer>\n";
fileContent = new NullIt().nullIt(fileContent,matcher.group());
}
diff --git a/parsers/Header.java b/parsers/Header.java
index 96ffa05..946613a 100644
--- a/parsers/Header.java
+++ b/parsers/Header.java
@@ -14,6 +14,7 @@ public class Header implements Parser {
// Embed necessay headers.
sbuilder.append("<!DOCTYPE html> \n");
sbuilder.append("<head> \n");
+ sbuilder.append("<meta charset=\"UTF-8\">\n");
sbuilder.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /> \n");
sbuilder.append("<title>");
sbuilder.append(PresentFile.name);
@@ -24,12 +25,12 @@ public class Header implements Parser {
sbuilder.append("<article>\n");
// insert File Content.
sbuilder.append(fileContent);
- // insert back button.
- sbuilder.append(PresentFile.backButton);
// add footer if footer is available.
if(PresentFile.footer!=null) {
sbuilder.append(PresentFile.footer);
}
+ // insert back button.
+ sbuilder.append(PresentFile.backButton);
sbuilder.append("</article>\n");
// add "powered by scruf" at bottom of page.
sbuilder.append("<div class=\"scruf\">\n");
diff --git a/parsers/Images.java b/parsers/Images.java
index f049f34..803537c 100644
--- a/parsers/Images.java
+++ b/parsers/Images.java
@@ -4,10 +4,10 @@ import java.util.regex.*;
public class Images implements Parser {
// set of strings to build the img tag
- private String openTag = "<img src=\"$1\"";
+ private String openTag = "<img src=\"$1\" alt=\"$";
private String closeTag = " />";
public String parse(String fileContent) {
- Pattern pattern = Pattern.compile("\\{\\{(.+\\.(png|jpg))(\\|(.+))?\\}\\}", Pattern.DOTALL);
+ Pattern pattern = Pattern.compile("\\{\\{(.+?\\.(png|jpg))(\\|(.+?))?\\}\\}", Pattern.DOTALL);
Matcher matcher = pattern.matcher(fileContent);
StringBuffer sbuffer = new StringBuffer();
StringBuilder replacementString =new StringBuilder();
@@ -18,7 +18,10 @@ public class Images implements Parser {
replacementString.append(openTag);
// if the "title" is given add to the _img_ tag.
if(matcher.group(3)!=null) {
- replacementString.append("alt=\"$4\" title=\"$4\"");
+ replacementString.append("4\" title=\"$4\"");
+ }
+ else {
+ replacementString.append("1\"");
}
// close the _img_ tag.
replacementString.append(closeTag);
diff --git a/parsers/Links.java b/parsers/Links.java
index 87e4109..0253846 100644
--- a/parsers/Links.java
+++ b/parsers/Links.java
@@ -4,10 +4,10 @@ import java.util.regex.*;
public class Links implements Parser {
// set of strings to build the html link
- private String openTag = "<a href=\"$1\" target=\"_blank\">";
+ private String openTag = "<a href=\"$1\">";
private String closeTag = "</a>";
public String parse(String fileContent) {
- Pattern pattern = Pattern.compile("\\[\\[(.+?)(\\|(.+?))\\]\\]", Pattern.DOTALL);
+ Pattern pattern = Pattern.compile("\\[\\[(.+?)(\\|(.+?))?\\]\\]", Pattern.DOTALL);
Matcher matcher = pattern.matcher(fileContent);
StringBuffer sbuffer = new StringBuffer();
StringBuilder replacementString = new StringBuilder();
@@ -20,6 +20,9 @@ public class Links implements Parser {
if(matcher.group(3)!=null) {
replacementString.append(matcher.group(3));
}
+ else {
+ replacementString.append(matcher.group(1));
+ }
// close the <a> tag
replacementString.append(closeTag);
matcher.appendReplacement(sbuffer,replacementString.toString());
diff --git a/parsers/Paragraphs.java b/parsers/Paragraphs.java
index 0d6fda6..295d14a 100644
--- a/parsers/Paragraphs.java
+++ b/parsers/Paragraphs.java
@@ -3,17 +3,28 @@ package scruf.parsers;
import java.util.regex.*;
public class Paragraphs implements Parser {
-
+ private String paragraph = "<p>\n $5</p>\n";
public String parse(String fileContent) {
-
- Pattern pattern = Pattern.compile("((^.+$)\\n)+",Pattern.MULTILINE);
+ /**
+ * This regex contains two parts seperated by a '|';
+ * the first part is regex for a html Heading (See Heading.java)
+ * and the second part is the regex for a paragraph. For an input,
+ * if the first part of the regex is matched, then it is necessarily
+ * a Heading, so, we ignore it; but if the second part of the regex is
+ * matched for an input, then it is a paragraph, so, we put the necessary
+ * tags in place.
+ */
+ Pattern pattern = Pattern.compile("((\\={10,})\\n(.+?)\\n(\\2))|((^.+$\\n)+)",Pattern.MULTILINE);
Matcher matcher = pattern.matcher(fileContent);
- StringBuilder sbuilder = new StringBuilder();
+ StringBuffer sbuffer = new StringBuffer();
while(matcher.find()) {
- sbuilder.append("\n<p>\n");
- sbuilder.append(matcher.group());
- sbuilder.append("</p>\n");
+ // group 1 contains the regex for the Heading, so
+ // if that is null, then it means that we have actually
+ // found a paragraph.
+ if(matcher.group(1)==null)
+ matcher.appendReplacement(sbuffer,paragraph);
}
- return sbuilder.toString();
+ matcher.appendTail(sbuffer);
+ return sbuffer.toString();
}
} \ No newline at end of file
diff --git a/parsers/ParserList.java b/parsers/ParserList.java
index 11e3de0..f5c1ebf 100644
--- a/parsers/ParserList.java
+++ b/parsers/ParserList.java
@@ -6,12 +6,12 @@ public class ParserList {
private List<Parser> parsers;
public ParserList() {
parsers = new ArrayList<Parser>();
- // add Parsers.
+ // add Parsers. NOTE: parser order is significant.
parsers.add(new DocumentName());
parsers.add(new WordDecoration());
parsers.add(new CodeBlocks());
- parsers.add(new Headings());
parsers.add(new Paragraphs());
+ parsers.add(new Headings());
parsers.add(new Links());
parsers.add(new Images());
parsers.add(new Footer());