Skip to content

Commit

Permalink
Bugfix to display node/note/detail content containing # character
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Koeppel committed Jan 31, 2023
1 parent f7a753e commit a30e573
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.benediktkoeppel.code.droidplane"
android:versionCode="13"
android:versionName="1.0.13">
android:versionCode="14"
android:versionName="1.0.14">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import android.net.Uri;
import android.text.Html;
import android.util.Log;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;


/**
Expand Down Expand Up @@ -151,7 +153,7 @@ public MindmapNode(Node node, MindmapNode parentNode, Mindmap mindmap) {
String text = tmpElement.getAttribute("TEXT");

// extract the richcontent (HTML) of the node. This works both for nodes with a rich text content
// (TYPE="NODE"), and for "Notes" (TYPE="NOTE").
// (TYPE="NODE"), for "Notes" (TYPE="NOTE"), for "Details" (TYPE="DETAILS").
String richTextContent = null;
// find 'richcontent TYPE="NODE"' subnode, which will contain the rich text content
NodeList richtextNodeList = tmpElement.getChildNodes();
Expand All @@ -160,7 +162,7 @@ public MindmapNode(Node node, MindmapNode parentNode, Mindmap mindmap) {
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals("richcontent")) {
Element richcontentElement = (Element)n;
String typeAttribute = richcontentElement.getAttribute("TYPE");
if (typeAttribute.equals("NODE") || typeAttribute.equals("NOTE")) {
if (typeAttribute.equals("NODE") || typeAttribute.equals("NOTE") || typeAttribute.equals("DETAILS")) {

// extract the whole rich text (XML), to show in a WebView activity
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.os.Bundle;
import android.util.Base64;
import android.webkit.WebView;

public class RichTextViewActivity extends Activity {
Expand All @@ -12,12 +13,23 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rich_text_view);

// get data from intent
// get data from intent. Data has to be base64 encoded, otherwise WebView stops processing
// at the first # character. See https://developer.android.com/reference/android/webkit/WebView#loadData(java.lang.String,%20java.lang.String,%20java.lang.String)
// > For all other values of encoding (including null) it is assumed that the data uses
// > ASCII encoding for octets inside the range of safe URL characters and use the standard
// > %xx hex encoding of URLs for octets outside that range. See RFC 3986 for more
// > information. Applications targeting Build.VERSION_CODES.Q or later must either use
// > base64 or encode any # characters in the content as %23, otherwise they will be treated
// > as the end of the content and the remaining text used as a document fragment
// > identifier.

String richTextContent = getIntent().getStringExtra("richTextContent");
String encodedContent = Base64.encodeToString(richTextContent.getBytes(), Base64.NO_PADDING);

// set data of web view
WebView webView = findViewById(R.id.webview);
webView.loadData(richTextContent, "text/html", "UTF-8");

webView.loadData(encodedContent, "text/html", "base64");

}

Expand Down
7 changes: 0 additions & 7 deletions droidplane.iml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="droidplane" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
148 changes: 148 additions & 0 deletions test/Rich Text/richtext-markdown.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<map version="freeplane 1.11.1">
<!--To view this file, download free mind mapping software Freeplane from https://www.freeplane.org -->
<node TEXT="TEST MAP" FOLDED="false" ID="ID_696401721" CREATED="1610381621824" MODIFIED="1674731908385" STYLE="oval">
<font SIZE="18"/>
<hook NAME="MapStyle">
<properties edgeColorConfiguration="#808080ff,#ff0000ff,#0000ffff,#00ff00ff,#ff00ffff,#00ffffff,#7c0000ff,#00007cff,#007c00ff,#7c007cff,#007c7cff,#7c7c00ff" associatedTemplateLocation="template:/standard-1.6.mm" fit_to_viewport="false" show_note_icons="true"/>

<map_styles>
<stylenode LOCALIZED_TEXT="styles.root_node" STYLE="oval" UNIFORM_SHAPE="true" VGAP_QUANTITY="24 pt">
<font SIZE="24"/>
<stylenode LOCALIZED_TEXT="styles.predefined" POSITION="bottom_or_right" STYLE="bubble">
<stylenode LOCALIZED_TEXT="default" ID="ID_271890427" ICON_SIZE="12 pt" COLOR="#000000" STYLE="fork">
<arrowlink SHAPE="CUBIC_CURVE" COLOR="#000000" WIDTH="2" TRANSPARENCY="200" DASH="" FONT_SIZE="9" FONT_FAMILY="SansSerif" DESTINATION="ID_271890427" STARTARROW="NONE" ENDARROW="DEFAULT"/>
<font NAME="SansSerif" SIZE="10" BOLD="false" ITALIC="false"/>
<richcontent CONTENT-TYPE="plain/auto" TYPE="DETAILS"/>
<richcontent TYPE="NOTE" CONTENT-TYPE="plain/auto"/>
</stylenode>
<stylenode LOCALIZED_TEXT="defaultstyle.details"/>
<stylenode LOCALIZED_TEXT="defaultstyle.attributes">
<font SIZE="9"/>
</stylenode>
<stylenode LOCALIZED_TEXT="defaultstyle.note" COLOR="#000000" BACKGROUND_COLOR="#ffffff" TEXT_ALIGN="LEFT"/>
<stylenode LOCALIZED_TEXT="defaultstyle.floating">
<edge STYLE="hide_edge"/>
<cloud COLOR="#f0f0f0" SHAPE="ROUND_RECT"/>
</stylenode>
<stylenode LOCALIZED_TEXT="defaultstyle.selection" BACKGROUND_COLOR="#afd3f7" BORDER_COLOR_LIKE_EDGE="false" BORDER_COLOR="#afd3f7"/>
</stylenode>
<stylenode LOCALIZED_TEXT="styles.user-defined" POSITION="bottom_or_right" STYLE="bubble">
<stylenode LOCALIZED_TEXT="styles.topic" COLOR="#18898b" STYLE="fork">
<font NAME="Liberation Sans" SIZE="10" BOLD="true"/>
</stylenode>
<stylenode LOCALIZED_TEXT="styles.subtopic" COLOR="#cc3300" STYLE="fork">
<font NAME="Liberation Sans" SIZE="10" BOLD="true"/>
</stylenode>
<stylenode LOCALIZED_TEXT="styles.subsubtopic" COLOR="#669900">
<font NAME="Liberation Sans" SIZE="10" BOLD="true"/>
</stylenode>
<stylenode LOCALIZED_TEXT="styles.important" ID="ID_67550811">
<icon BUILTIN="yes"/>
<arrowlink COLOR="#003399" TRANSPARENCY="255" DESTINATION="ID_67550811"/>
</stylenode>
</stylenode>
<stylenode LOCALIZED_TEXT="styles.AutomaticLayout" POSITION="bottom_or_right" STYLE="bubble">
<stylenode LOCALIZED_TEXT="AutomaticLayout.level.root" COLOR="#000000" STYLE="oval" SHAPE_HORIZONTAL_MARGIN="10 pt" SHAPE_VERTICAL_MARGIN="10 pt">
<font SIZE="18"/>
</stylenode>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,1" COLOR="#0033ff">
<font SIZE="16"/>
</stylenode>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,2" COLOR="#00b439">
<font SIZE="14"/>
</stylenode>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,3" COLOR="#990000">
<font SIZE="12"/>
</stylenode>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,4" COLOR="#111111">
<font SIZE="10"/>
</stylenode>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,5"/>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,6"/>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,7"/>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,8"/>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,9"/>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,10"/>
<stylenode LOCALIZED_TEXT="AutomaticLayout.level,11"/>
</stylenode>
</stylenode>
</map_styles>
</hook>
<hook NAME="AutomaticEdgeColor" COUNTER="3" RULE="ON_BRANCH_CREATION"/>
<node TEXT="Test" POSITION="bottom_or_right" ID="ID_630811681" CREATED="1674035545257" MODIFIED="1674035549690">
<edge COLOR="#0000ff"/>
<node TEXT="Child 1 with details" ID="ID_734194014" CREATED="1674035550134" MODIFIED="1674731933081"><richcontent CONTENT-TYPE="xml/" TYPE="DETAILS">
<html>
<head>

</head>
<body>
<p>
Some details
</p>
</body>
</html>
</richcontent>
</node>
<node TEXT="Child 2" ID="ID_749163868" CREATED="1674035553856" MODIFIED="1674731830862">
<node TEXT="https://github.com/freeplane/freeplane/discussions/" ID="ID_99748537" CREATED="1674731936105" MODIFIED="1674731963065"/>
</node>
<node TEXT="Child 3 with markdown note" ID="ID_1632614895" CREATED="1674035556389" MODIFIED="1674732447326"><richcontent TYPE="NOTE" CONTENT-TYPE="xml/markdown">
<html>
<head>

</head>
<body>
<p>
## Markdown
</p>
<p>

</p>
<p>
Test **some text**
</p>
<p>

</p>
<p>
- test 1
</p>
<p>
&#xa0;- test 2
</p>
<p>
- test 3
</p>
</body>
</html>
</richcontent>
</node>
<node TEXT="Child 4 with text" ID="ID_30451442" CREATED="1674035559658" MODIFIED="1674731878462"><richcontent TYPE="NOTE" CONTENT-TYPE="xml/">
<html>
<head>

</head>
<body>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: Open Sans, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: rgb(255, 255, 255)">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque dignissim, nisl sit amet sodales sagittis, nunc libero aliquet libero, eget elementum nulla velit in nisl. Vivamus non nunc hendrerit, sodales lacus vel, blandit orci. Aenean aliquam enim nec molestie fringilla. Vestibulum nec nunc sed urna porta convallis. Aliquam vitae ipsum eget metus convallis consectetur. Mauris varius nibh arcu, a fermentum est ultricies sit amet. Integer eu turpis quis tellus aliquet faucibus. Maecenas sed dignissim nisi. Nulla posuere, lorem eu facilisis venenatis, ex risus ornare dolor, sit amet pharetra arcu purus eu erat. Vestibulum ipsum ipsum, molestie non arcu et, faucibus commodo sapien. Phasellus ultrices, erat et vehicula congue, erat est vehicula sapien, eu venenatis lectus mauris blandit magna. Maecenas egestas augue est, eget feugiat ligula mollis eu. Vestibulum ullamcorper neque et tellus bibendum pellentesque.
</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: Open Sans, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: rgb(255, 255, 255)">
Curabitur ex mi, viverra non sem vitae, consequat porta velit. Aenean non odio ac urna ultricies porta. Suspendisse odio sapien, lobortis posuere porta a, scelerisque et ante. Vivamus nec nisl in massa rutrum elementum. Morbi efficitur est vel dolor auctor, id convallis felis tempus. Etiam ullamcorper malesuada cursus. Vestibulum venenatis ante nunc, ut lobortis ipsum porta sit amet. Etiam est nisl, posuere ac sodales at, suscipit auctor arcu. Praesent in molestie ligula. Etiam fermentum, tortor sed scelerisque molestie, eros elit ultricies dui, sed dignissim nunc libero vel tortor. Duis dapibus risus mauris, nec tristique magna mollis mattis.
</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: Open Sans, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: rgb(255, 255, 255)">
Sed venenatis, libero vel lobortis tempus, ligula sem vehicula justo, sed convallis velit dui eu diam. Phasellus varius, quam sed condimentum congue, neque metus rutrum ante, a bibendum diam velit a quam. Integer consectetur laoreet elit, nec laoreet lacus fermentum eget. Nam interdum placerat ligula, ut venenatis turpis. Cras justo arcu, egestas et viverra non, eleifend et tortor. Donec fringilla eros non justo gravida posuere. Donec tincidunt turpis lorem, et viverra sem scelerisque eu. Phasellus justo tellus, vulputate a eleifend vitae, pretium ac magna. Aliquam a sodales libero. Fusce ligula tellus, vestibulum vitae justo at, molestie congue dui. Praesent ac enim nec erat suscipit mattis eu ut libero. Suspendisse pretium placerat augue, at egestas ligula auctor sed. Duis varius eros scelerisque, gravida tortor eu, iaculis tellus. Mauris venenatis vehicula leo vel tristique. Nullam hendrerit nunc lorem, vel rutrum diam mollis in. Donec placerat suscipit ligula.
</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: Open Sans, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: rgb(255, 255, 255)">
Curabitur nisi arcu, consectetur sit amet metus sed, pulvinar tincidunt quam. Fusce eu accumsan ligula. In metus tellus, porttitor in mattis in, elementum quis dui. Suspendisse eget condimentum nibh. In in nisi massa. Pellentesque pharetra massa risus, a faucibus augue dignissim non. Maecenas ac luctus felis. Mauris feugiat elit sed tellus mollis ultrices. Proin efficitur sit amet nunc at facilisis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer cursus nulla id augue fermentum ornare. Mauris non tortor non ante ultricies accumsan. Cras suscipit nulla eu quam pharetra imperdiet. Sed a mattis est. Praesent lacinia lectus quam, id placerat libero congue dignissim.
</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: Open Sans, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: rgb(255, 255, 255)">
Pellentesque mauris metus, eleifend id interdum ac, dictum et purus. Sed facilisis augue sit amet massa mollis ullamcorper. Quisque nec nulla sem. Etiam tincidunt fermentum diam at vehicula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Nunc tristique tempus hendrerit. Sed aliquam eget augue et aliquam. Vestibulum aliquet, diam non faucibus varius, enim nulla pulvinar magna, a luctus purus ante sed nisi.
</p>
</body>
</html>
</richcontent>
</node>
</node>
</node>
</map>

0 comments on commit a30e573

Please sign in to comment.