From d5a7153c54d09502f58acbacb047041c1917bbd7 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 5 Mar 2017 20:24:57 +0100 Subject: [PATCH] Fix some bad line breaks on HTML supports --- src/be/nikiroo/fanfix/output/BasicOutput.java | 22 +++-- .../fanfix/reader/LocalReaderFrame.java | 2 +- .../fanfix/supported/BasicSupport.java | 88 +++++++++++-------- 3 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/be/nikiroo/fanfix/output/BasicOutput.java b/src/be/nikiroo/fanfix/output/BasicOutput.java index 9bf096cc..1ac6101d 100644 --- a/src/be/nikiroo/fanfix/output/BasicOutput.java +++ b/src/be/nikiroo/fanfix/output/BasicOutput.java @@ -175,15 +175,19 @@ public abstract class BasicOutput { throws IOException { storyPg = pg; - target = new File(target).getAbsolutePath(); - File targetDir = new File(target).getParentFile(); - String targetName = new File(target).getName(); - - String ext = getDefaultExtension(false); - if (ext != null && !ext.isEmpty()) { - if (targetName.toLowerCase().endsWith(ext)) { - targetName = targetName.substring(0, - targetName.length() - ext.length()); + File targetDir = null; + String targetName = null; + if (target != null) { + target = new File(target).getAbsolutePath(); + targetDir = new File(target).getParentFile(); + targetName = new File(target).getName(); + + String ext = getDefaultExtension(false); + if (ext != null && !ext.isEmpty()) { + if (targetName.toLowerCase().endsWith(ext)) { + targetName = targetName.substring(0, targetName.length() + - ext.length()); + } } } diff --git a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java index 1dc63e78..a7935138 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java @@ -562,7 +562,7 @@ class LocalReaderFrame extends JFrame { */ private void outOfUi(Progress progress, final Runnable run) { final Progress pg = new Progress(); - final Progress reload = new Progress("Reload local caches"); + final Progress reload = new Progress("Reload books"); if (progress == null) { progress = new Progress(); } diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index e3b6fab3..18113188 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -597,57 +597,71 @@ public abstract class BasicSupport { if (isHtml()) { // Special
processing: content = content.replaceAll("(
]*>)|(
)|(
)", - "\n* * *\n"); + "
* * *
"); } List paras = new ArrayList(); - InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); - try { - BufferedReader buff = new BufferedReader(new InputStreamReader(in, - "UTF-8")); - - for (String encodedLine = buff.readLine(); encodedLine != null; encodedLine = buff - .readLine()) { - String lines[]; - if (isHtml()) { - lines = encodedLine.split("(

|

|
|
|\\n)"); - } else { - lines = new String[] { encodedLine }; - } - - for (String aline : lines) { - String line = aline.trim(); - URL image = null; - if (line.startsWith("[") && line.endsWith("]")) { - image = getImageUrl(this, source, - line.substring(1, line.length() - 1).trim()); + if (content != null && !content.trim().isEmpty()) { + if (isHtml()) { + for (String line : content.split("(

|

|
|
)")) { + paras.add(makeParagraph(source, line.trim())); + } + } else { + BufferedReader buff = null; + try { + buff = new BufferedReader( + new InputStreamReader(new ByteArrayInputStream( + content.getBytes("UTF-8")), "UTF-8")); + for (String line = buff.readLine(); line != null; line = buff + .readLine()) { + paras.add(makeParagraph(source, line.trim())); } - - if (image != null) { - paras.add(new Paragraph(image)); - } else { - paras.add(processPara(line)); + } finally { + if (buff != null) { + buff.close(); } } } - } finally { - in.close(); - } - // Check quotes for "bad" format - List newParas = new ArrayList(); - for (Paragraph para : paras) { - newParas.addAll(requotify(para)); - } - paras = newParas; + // Check quotes for "bad" format + List newParas = new ArrayList(); + for (Paragraph para : paras) { + newParas.addAll(requotify(para)); + } + paras = newParas; - // Remove double blanks/brks - fixBlanksBreaks(paras); + // Remove double blanks/brks + fixBlanksBreaks(paras); + } return paras; } + /** + * Convert the given line into a single {@link Paragraph}. + * + * @param source + * the source URL of the story + * @param line + * the textual content of the paragraph + * + * @return the {@link Paragraph} + */ + private Paragraph makeParagraph(URL source, String line) { + URL image = null; + if (line.startsWith("[") && line.endsWith("]")) { + image = getImageUrl(this, source, + line.substring(1, line.length() - 1).trim()); + } + + if (image != null) { + return new Paragraph(image); + } else { + return processPara(line); + } + } + /** * Fix the {@link ParagraphType#BLANK}s and {@link ParagraphType#BREAK}s of * those {@link Paragraph}s. -- 2.27.0