use of org.jsoup.select.Elements in project jsoup by jhy.
the class HtmlParserTest method handlesUnclosedDefinitionLists.
@Test
public void handlesUnclosedDefinitionLists() {
// jsoup used to create a <dl>, but that's not to spec
String h = "<dt>Foo<dd>Bar<dt>Qux<dd>Zug";
Document doc = Jsoup.parse(h);
// no auto dl
assertEquals(0, doc.select("dl").size());
assertEquals(4, doc.select("dt, dd").size());
Elements dts = doc.select("dt");
assertEquals(2, dts.size());
assertEquals("Zug", dts.get(1).nextElementSibling().text());
}
use of org.jsoup.select.Elements in project jsoup by jhy.
the class HtmlParserTest method createsFormElements.
// form tests
@Test
public void createsFormElements() {
String html = "<body><form><input id=1><input id=2></form></body>";
Document doc = Jsoup.parse(html);
Element el = doc.select("form").first();
assertTrue("Is form element", el instanceof FormElement);
FormElement form = (FormElement) el;
Elements controls = form.elements();
assertEquals(2, controls.size());
assertEquals("1", controls.get(0).id());
assertEquals("2", controls.get(1).id());
}
use of org.jsoup.select.Elements in project jsoup by jhy.
the class HtmlParserTest method testSupportsNonAsciiTags.
@Test
public void testSupportsNonAsciiTags() {
String body = "<進捗推移グラフ>Yes</進捗推移グラフ><русский-тэг>Correct</<русский-тэг>";
Document doc = Jsoup.parse(body);
Elements els = doc.select("進捗推移グラフ");
assertEquals("Yes", els.text());
els = doc.select("русский-тэг");
assertEquals("Correct", els.text());
}
use of org.jsoup.select.Elements in project AozoraEpub3 by hmdev.
the class WebAozoraConverter method getExtractText.
String getExtractText(Document doc, ExtractInfo[] extractInfos, boolean replace) {
if (extractInfos == null)
return null;
for (ExtractInfo extractInfo : extractInfos) {
String text = null;
Elements elements = doc.select(extractInfo.query);
if (elements == null || elements.size() == 0)
continue;
StringBuilder buf = new StringBuilder();
if (extractInfo.idx == null) {
for (Element element : elements) {
String html = element.html();
if (html != null)
buf.append(" ").append(replaceHtmlText(html, replace ? extractInfo : null));
}
} else {
for (int i = 0; i < extractInfo.idx.length; i++) {
if (elements.size() > extractInfo.idx[i]) {
int pos = extractInfo.idx[i];
//負の値なら後ろから
if (pos < 0)
pos = elements.size() + pos;
if (pos >= 0 && elements.size() > pos) {
String html = elements.get(pos).html();
if (html != null)
buf.append(" ").append(replaceHtmlText(html, replace ? extractInfo : null));
}
}
}
if (buf.length() > 0)
text = buf.deleteCharAt(0).toString();
}
//置換指定ならreplaceして返す
if (text != null && text.length() > 0) {
return text;
}
}
return null;
}
use of org.jsoup.select.Elements in project AozoraEpub3 by hmdev.
the class WebAozoraConverter method printRuby.
/** ルビを青空ルビにして出力 */
private void printRuby(BufferedWriter bw, Element ruby) throws IOException {
Elements rb = ruby.getElementsByTag("rb");
Elements rt = ruby.getElementsByTag("rt");
if (rb.size() > 0) {
if (rt.size() > 0) {
bw.append('|');
printText(bw, rb.get(0).text());
bw.append('《');
printText(bw, rt.get(0).text());
bw.append('》');
} else {
printText(bw, rb.get(0).text());
}
}
}
Aggregations