Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added formating of node payload in view activity #194

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion res/xml/preferences.xml
Expand Up @@ -47,10 +47,15 @@
android:summary="@string/summary_view_wrap_lines"
android:title="@string/title_view_wrap_lines" />
<CheckBoxPreference
android:key="viewDefaultEdit"
android:defaultValue="true"
android:key="viewDefaultEdit"
android:summary="When checked, the default behaviour for clicking on nodes without children will be editing. Else it will be viewing."
android:title="Edit on click" />
<CheckBoxPreference
android:defaultValue="true"
android:key="viewApplyFormating"
android:summary="Apply formating of orgmode emphasis, bold, underline and strike-through when viewing."
android:title="Apply view formating" />

<ListPreference
android:defaultValue="0"
Expand Down
27 changes: 24 additions & 3 deletions src/com/matburt/mobileorg/Gui/NodeViewActivity.java
Expand Up @@ -129,7 +129,8 @@ private String convertToHTML() {
text = text.replaceAll("\\n(\\s*\\d+[\\)\\.])", "<br/>\n$1"); // wrap ordered lists

text = text.replaceAll("((\\s*\\|[^\\n]*\\|\\s*(?:<br/>)?\\n)+)", "<pre>$1</pre>");


Log.d("MobileOrg", text);
text = "<html><body>" + text + "</body></html>";
} else {
text = text.replaceAll("\\n", "<br/>\n");
Expand All @@ -138,7 +139,6 @@ private String convertToHTML() {

return text;
}


private String convertLinks(String text) {
Pattern linkPattern = Pattern.compile("\\[\\[([^\\]]*)\\]\\[([^\\]]*)\\]\\]");
Expand Down Expand Up @@ -229,12 +229,33 @@ private String nodeToHTML(NodeWrapper node, int headingLevel) {
result.append("</b></font> <hr />");

if (!node.getCleanedPayload(appInst.getDB()).equals("")) {
result.append(node.getCleanedPayload(appInst.getDB()));
String payload = node.getCleanedPayload(appInst.getDB());
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
"viewApplyFormating", true))
payload = applyFormating(payload);
result.append(payload);
result.append("\n<br/>\n");
}

result.append("<br/>\n");
return result.toString();
}

private String getFormatingRegex(String character, String tag, String text) {
return text.replaceAll(
"(\\s)\\" + character +
"(\\S[\\S\\s]*\\S)" +
"\\" + character + "(\\s)"
, "$1<" + tag + ">$2</" + tag + ">$3");
}

private String applyFormating(String text) {
text = getFormatingRegex("*", "b", text);
text = getFormatingRegex("/", "i", text);
text = getFormatingRegex("_", "u", text);
text = getFormatingRegex("+", "strike", text);

return text;
}

}