From 88b46e3db46ff8d8754797fcff8fe9eba19f7ddd Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Fri, 15 Nov 2013 14:00:35 +0530 Subject: now, scruf does'nt wrap

around text inside HTML blocks in scruffy markup file. With this, I guess, HTML can be written in scruffy marked up files. --- parsers/Paragraphs.java | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'parsers/Paragraphs.java') diff --git a/parsers/Paragraphs.java b/parsers/Paragraphs.java index 7b21d69..d4ad31c 100644 --- a/parsers/Paragraphs.java +++ b/parsers/Paragraphs.java @@ -21,18 +21,14 @@ package scruf.parsers; import java.util.regex.*; - +import scruf.status.*; public class Paragraphs implements Parser { - private String paragraph = "

\n$0

\n"; + private String paragraph = "

$0

"; + private DetectHTMLTag detectTag; public String parse(String fileContent) { + detectTag = new DetectHTMLTag(); /** - * 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. + * The pattern for matching paragraphs */ Pattern pattern = Pattern.compile("(^.+$\\n)+",Pattern.MULTILINE); /** @@ -42,21 +38,15 @@ public class Paragraphs implements Parser { Matcher matcher = pattern.matcher(fileContent); Matcher htmlTag; StringBuffer sbuffer = new StringBuffer(); + while(matcher.find()) { - /** - * give the paragraph that is identified htmlTagPattern - * and see whether the "paragraph" that is actually - * deducted is some other html block like

(heading) - * or
, etcetera. If "matcher.find()" has - * actually found a html block then we don't need to do - * the conversion. - */ htmlTag = htmlTagPattern.matcher(matcher.group()); - /** - * if "matcher.find()" _has not_ deducted a html block, - * then we do the conversion. - */ - if(!htmlTag.find()) { + + String subString = fileContent.substring(matcher.start()); + boolean htmlTagP = htmlTag.find(); + boolean htmlInScruffy = detectTag.isHtmlInScruffy(subString); + boolean pWrap = !htmlTagP && !htmlInScruffy; + if(pWrap) { matcher.appendReplacement(sbuffer,paragraph); } } -- cgit v1.2.3