From 8843f4b84b9124502c7396a6a7cc87a7e076b779 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 20 Dec 2012 11:26:27 +0530 Subject: [bug-fix]: From now on, all the special characters in the string inside "monospace" blocks (the ones surrounded by ` character) are quoted to the corresponding HTML number. modified: parsers/WordDecoration.java --- parsers/WordDecoration.java | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/parsers/WordDecoration.java b/parsers/WordDecoration.java index 1df8cc6..e7cc0ac 100644 --- a/parsers/WordDecoration.java +++ b/parsers/WordDecoration.java @@ -28,13 +28,14 @@ import scruf.io.*; public class WordDecoration implements Parser { private HashMap tagMap; + private SymbolMap symbolMap; public WordDecoration() { tagMap = new HashMap(); tagMap.put("''","$7"); tagMap.put("__","$7"); tagMap.put("'''","$7"); tagMap.put("%%%","
$7
"); - tagMap.put("`","$7"); + symbolMap = new SymbolMap(); } public String parse(String fileContent) { Pattern pattern = @@ -44,10 +45,35 @@ public class WordDecoration implements Parser { StringBuffer sbuffer = new StringBuffer(); String replacement; while(matcher.find()) { - replacement = tagMap.get(matcher.group(1)); + // if the block found is a monospace block, + // get the replacement from 'monospaceBlock' + // method, else get it from the 'tagMap': + if(matcher.group(6)!=null) { + // group 7 is the string inside the word decorated + // mark up. (see the pattern above) + replacement = monospaceBlock(matcher.group(7)); + }else { + replacement = tagMap.get(matcher.group(1)); + } matcher.appendReplacement(sbuffer,replacement); } matcher.appendTail(sbuffer); return sbuffer.toString(); } + + // monopace blocks need special treatment, therefore, + // this method for its construction: + private String monospaceBlock(String content) { + // quote all special characters in the monospace + // block: + String quotedContent= symbolMap.quote(content); + + // build monospace HTML block: + StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append(quotedContent); + sb.append(""); + + return sb.toString(); + } } -- cgit v1.2.3