Comments (4)
Thanks for reporting.
The code works for me when I change the first lines to
String contentOld = "<html><body>festive 8</body></html>";
String contentNew = "<html><body>What was your highlight of 8?</body></html>";
Keep in mind that DaisyDiff was created to compare XHTML and that the behaviour
for
other input is undefined.
Does this help you or do you believe DaisyDiff should support plain text?
Original comment by [email protected]
on 17 Feb 2009 at 4:43
- Changed state: WontFix
from daisydiff.
This is not the ideal solution I was looking for. Padding texts with html tags
should
not be mandatory.
Although DaisyDiff was created to compare XHTML, I think it should be extended
to
handle textual inputs too (just a suggestion). A classic case where this can
come in
handy is where you have two different stories to compare and you use this
library
from a custom tag to compare the author, created date, title, summary etc. of
the two
stories.
Original comment by [email protected]
on 17 Feb 2009 at 5:09
from daisydiff.
BTW, I got it to work using the following piece of code.
<code>
String contentOld = "festive 8";
String contentNew = "What was your highlight of 8?";
getDiffForHTMLInput(contentOld, contentNew);
private String getDiffForHTMLInput ( String contentOld, String contentNew )
throws Exception
{
contentOld = contentOld == null ? "" : contentOld;
contentNew = contentNew == null ? "" : contentNew;
StringWriter writer = new StringWriter(contentNew.length() +
contentOld.length());
List styleList = new ArrayList();
styleList.add("/static/js/difftag/css/difftag.css");
SAXTransformerFactory tf = (SAXTransformerFactory)
TransformerFactory.newInstance();
TransformerHandler result = tf.newTransformerHandler();
result.setResult(new StreamResult(writer));
ContentHandler postProcess = result;
Locale locale = Locale.getDefault();
String prefix = "diff";
HtmlCleaner cleaner = new HtmlCleaner();
InputSource oldSource = new InputSource(new
ByteArrayInputStream(contentOld.getBytes("UTF-8")));
InputSource newSource = new InputSource(new
ByteArrayInputStream(contentNew.getBytes("UTF-8")));
DomTreeBuilder oldHandler = new DomTreeBuilder();
cleaner.cleanAndParse(oldSource, oldHandler);
TextNodeComparator leftComparator = new TextNodeComparator(oldHandler,
locale);
DomTreeBuilder newHandler = new DomTreeBuilder();
cleaner.cleanAndParse(newSource, newHandler);
TextNodeComparator rightComparator = new TextNodeComparator(newHandler,
locale);
postProcess.startDocument();
postProcess.startElement("", "diffreport", "diffreport", new
AttributesImpl());
attachStyleSheets(styleList, postProcess);
postProcess.startElement("", "diff", "diff", new AttributesImpl());
HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix);
HTMLDiffer differ = new HTMLDiffer(output);
differ.diff(leftComparator, rightComparator);
postProcess.endElement("", "diff", "diff");
postProcess.endElement("", "diffreport", "diffreport");
postProcess.endDocument();
return writer.getBuffer().toString();
}
private void attachStyleSheets ( List styles, ContentHandler handler ) throws
SAXException
{
handler.startElement("", "css", "css", new AttributesImpl());
for (Iterator i = styles.iterator(); i.hasNext(); handler.endElement("",
"link", "link"))
{
String cssLink = (String) i.next();
AttributesImpl attr = new AttributesImpl();
attr.addAttribute("", "href", "href", "CDATA", cssLink);
attr.addAttribute("", "type", "type", "CDATA", "text/css");
attr.addAttribute("", "rel", "rel", "CDATA", "stylesheet");
handler.startElement("", "link", "link", attr);
}
}
</code>
Original comment by [email protected]
on 17 Feb 2009 at 5:12
from daisydiff.
Btw, if you want to diff plain text then I can recommend
http://code.google.com/p/google-diff-match-patch/ . If you have the time I'd be
very
happy to accept patches that add support for plain text.
Valid XML should have a single root element (like <html>) so anything else is
not
valid input and you should indeed wrap your snippets.
Original comment by [email protected]
on 17 Feb 2009 at 5:31
from daisydiff.
Related Issues (20)
- Add location of css and js directories as a commandline option HOT 1
- Indentation goes crazy when you compare two html pages having lot of numbered lists HOT 2
- Indentation goes crazy when you compare two html pages having lot of numbered lists HOT 4
- Alternative jQuery UI for Diff results
- Daisydiff fails to process certain invalid HTML files HOT 9
- DOM structure is modified in the daisydiff output HOT 5
- Unit test fails due to a missing newline character HOT 2
- Empty IMG tag throws NullPointerException
- when we comparing the two files have no change, daisy diff throwing Uncaught unknown destination..
- Does not Diff <Title> or <Meta> or <JavaScript> in HTML HOT 3
- An element that was moved out of a table can lead to broken table elements in the diff HOT 1
- Invalid tags are generated HOT 2
- Word changed but showing removed and added & change in image showing improper in Chrome. HOT 1
- error on line 6 at column 8: Opening and ending tag mismatch: link line 0 and head HOT 8
- [deleted issue]
- Compare result error for table
- [deleted issue]
- TextNode->IsSame() references not declared variable $html2 in php
- Is it possible to display the new created content? Not display the whole line.
- Xerces Impl included in daisydiff.jar has security vulnerabilities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from daisydiff.