ashokrenukappa / java-wikipedia-parser

Automatically exported from code.google.com/p/java-wikipedia-parser
0 stars 0 forks source link

adding image support #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
i was wondering if there was a simple way to add image support (or any 
other "tag" support without modifying the base code? i haven't looked at 
the code, but i'm thinking something like:

Parser parser = new Parser();
TagSupport caret = new TagSupport() {
  public String getTag() { return "^"; }
  public String startTag(AttributeList attr) {
    return "<caret>";
  }
  public String handleTag(String content) {
    return content;
  }
  public String endTag() {
    return "</caret>";
  }
};
parser.addSupport(caret);

String test = "^test^";
String result = parser.toHtml(test); // returns "<caret>test</caret>"

if we had something like this, adding image support wouldn't be too hard. 
i'm writing an application that needs to resize the images as static 
files are created, this would make it easy to do so. it would also be 
nice to be able to disable support for anything i wish. good job on the 
parser by the way.

Original issue reported on code.google.com by sodamn...@gmail.com on 18 Mar 2008 at 7:47

GoogleCodeExporter commented 9 years ago
Wikipedia inserts images as links:

  [[Image:image name.png]]

The double brackets are "SmartLinks" and, one can alter what happens when these 
occur
by extending the HtmlVisitor class.

Currently, it appends the following:

 start:  <a href="[resolved link]">
 end:    </a>

You could overwrite this when an image link is detected:

  start: <img src="[image link]" />
  end:   

(nothing for the end tag).  Note that content still may appear after the image 
if the
SmartLink had a caption.  This is something I'm interested in changing too, as
customizing the parser is of course what we're most interested in.

Original comment by bodhi.r...@gmail.com on 11 Dec 2008 at 10:03