(Spanned spanned, Context context)
| 4292 | } |
| 4293 | |
| 4294 | static String toHtml(Spanned spanned, Context context) { |
| 4295 | HtmlEx converter = new HtmlEx(context); |
| 4296 | String html = converter.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_INDIVIDUAL); |
| 4297 | |
| 4298 | Document doc = JsoupEx.parse(html); |
| 4299 | |
| 4300 | if (doc.head().select("meta[name=viewport]").first() == null) |
| 4301 | doc.head().prependElement("meta") |
| 4302 | .attr("name", "viewport") |
| 4303 | .attr("content", "width=device-width, initial-scale=1.0"); |
| 4304 | |
| 4305 | for (Element span : doc.select("span")) { |
| 4306 | if (span.attr("dir").equals("rtl")) { |
| 4307 | Element next = span.nextElementSibling(); |
| 4308 | if (next != null && next.tagName().equals("br")) { |
| 4309 | span.tagName("div"); |
| 4310 | span.appendElement("br"); |
| 4311 | next.remove(); |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | String style = span.attr("style"); |
| 4316 | if (TextUtils.isEmpty(style)) |
| 4317 | continue; |
| 4318 | |
| 4319 | StringBuilder sb = new StringBuilder(); |
| 4320 | |
| 4321 | String[] params = style.split(";"); |
| 4322 | for (String param : params) { |
| 4323 | int semi = param.indexOf(":"); |
| 4324 | if (semi < 0) { |
| 4325 | sb.append(param).append(';'); |
| 4326 | continue; |
| 4327 | } |
| 4328 | |
| 4329 | String key = param.substring(0, semi).trim(); |
| 4330 | String value = param.substring(semi + 1).trim(); |
| 4331 | |
| 4332 | switch (key) { |
| 4333 | case "text-align": |
| 4334 | sb.append(" display:block;"); |
| 4335 | Element next = span.nextElementSibling(); |
| 4336 | if (next != null && next.tagName().equals("br")) |
| 4337 | next.remove(); |
| 4338 | // fall through |
| 4339 | default: |
| 4340 | sb.append(param).append(';'); |
| 4341 | } |
| 4342 | |
| 4343 | if (sb.length() == 0) |
| 4344 | span.removeAttr("style"); |
| 4345 | else |
| 4346 | span.attr("style", sb.toString()); |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | for (Element e : doc.select("ol,ul")) { |
| 4351 | int ltr = 0; |
no test coverage detected