From 44e585f8284f0aca1ddb48db0ead6b05df159afa Mon Sep 17 00:00:00 2001 From: Cui <11811305@mail.sustech.edu.cn> Date: Wed, 12 May 2021 20:22:05 +0800 Subject: [PATCH] update --- .../android/markdown/MarkdownUtilTest.java | 20 +++++++++---------- .../android/markdown/MarkdownUtil.java | 9 +++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java b/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java index ea4fb6c8..d359e53e 100644 --- a/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java +++ b/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java @@ -752,19 +752,19 @@ public class MarkdownUtilTest extends TestCase { assertEquals("Foo_Test_Bar", MarkdownUtil.removeMarkdown("Foo_Test_Bar")); assertEquals("Foo__Test__Bar", MarkdownUtil.removeMarkdown("Foo__Test__Bar")); assertEquals("Foo___Test___Bar", MarkdownUtil.removeMarkdown("Foo___Test___Bar")); - assertEquals("Foo\n\nHeader\n\nBar", MarkdownUtil.removeMarkdown("Foo\n# Header\nBar")); - assertEquals("Foo\n\nHeader\n\nBar", MarkdownUtil.removeMarkdown("Foo\n### Header\nBar")); - assertEquals("Foo\n\nHeader\n\nBar", MarkdownUtil.removeMarkdown("Foo\n# Header #\nBar")); - assertEquals("Foo\n\nHeader\n\nBar", MarkdownUtil.removeMarkdown("Foo\n## Header ####\nBar")); + assertEquals("Foo\nHeader\nBar", MarkdownUtil.removeMarkdown("Foo\n# Header\nBar")); + assertEquals("Foo\nHeader\nBar", MarkdownUtil.removeMarkdown("Foo\n### Header\nBar")); + assertEquals("Foo\nHeader\nBar", MarkdownUtil.removeMarkdown("Foo\n# Header #\nBar")); + assertEquals("Foo\nHeader\nBar", MarkdownUtil.removeMarkdown("Foo\n## Header ####\nBar")); assertEquals("Foo\nNo Header #\nBar", MarkdownUtil.removeMarkdown("Foo\nNo Header #\nBar")); - assertEquals("Foo\nHeader\n\nBar", MarkdownUtil.removeMarkdown("Foo\nHeader\n=\nBar")); - assertEquals("Foo\nHeader\n\nBar", MarkdownUtil.removeMarkdown("Foo\nHeader\n-----\nBar")); + assertEquals("Foo\nHeader\nBar", MarkdownUtil.removeMarkdown("Foo\nHeader\n=\nBar")); + assertEquals("Foo\nHeader\nBar", MarkdownUtil.removeMarkdown("Foo\nHeader\n-----\nBar")); assertEquals("Foo\nHeader\n--=--\nBar", MarkdownUtil.removeMarkdown("Foo\nHeader\n--=--\nBar")); - assertEquals("Foo\n\nAufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n* Aufzählung\nBar")); - assertEquals("Foo\n\nAufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n+ Aufzählung\nBar")); - assertEquals("Foo\n\nAufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n- Aufzählung\nBar")); + assertEquals("Foo\nAufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n* Aufzählung\nBar")); + assertEquals("Foo\nAufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n+ Aufzählung\nBar")); + assertEquals("Foo\nAufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n- Aufzählung\nBar")); assertEquals("Foo\n- Aufzählung\nBar", MarkdownUtil.removeMarkdown("Foo\n - Aufzählung\nBar")); - assertEquals("Foo\n\nAufzählung *\nBar", MarkdownUtil.removeMarkdown("Foo\n* Aufzählung *\nBar")); + assertEquals("Foo\nAufzählung *\nBar", MarkdownUtil.removeMarkdown("Foo\n* Aufzählung *\nBar")); assertEquals("Title", MarkdownUtil.removeMarkdown("# Title")); assertEquals("Aufzählung", MarkdownUtil.removeMarkdown("* Aufzählung")); // assertEquals("Foo Link Bar", MarkdownUtil.removeMarkdown("Foo [Link](https://example.com) Bar")); diff --git a/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java b/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java index 24473d23..5d6c87ba 100644 --- a/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java +++ b/markdown/src/main/java/it/niedermann/android/markdown/MarkdownUtil.java @@ -572,15 +572,12 @@ public class MarkdownUtil { return ""; // Create HTML string from Markup String html = renderer.render(parser.parse(replaceCheckboxesWithEmojis(s))); - html = html.replaceAll("\n", ""); - // Convert Spanned from HTML. Using HtmlCompat to convert has some problems, which is that sometimes the \n in the text would double. - Spanned spanned = HtmlCompat.fromHtml(html, 0); - //Maybe we could use Html to convert, it doesn't have such problems. - //Spanned spanned = Html.fromHtml(html,Html.FROM_HTML_MODE_COMPACT); + // Convert Spanned from HTML. + Spanned spanned = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_COMPACT); // Convert from spanned to string s = spanned.toString(); // The default string has two additional \n in the end, the substring is used to delete this two \n. - s = s.substring(0, s.length() - 2); + s = s.substring(0, s.length() - 1); return s; } }