Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into small_features_an…
Browse files Browse the repository at this point in the history
…d_improvements
  • Loading branch information
harshad1 committed Dec 4, 2023
2 parents a98a1c8 + 1fb8f83 commit e6f9d83
Show file tree
Hide file tree
Showing 52 changed files with 327 additions and 271 deletions.
26 changes: 13 additions & 13 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ Where:
* **[Dugite Code](https://github.com/dugite-code)**<br/>~° Artwork
* **[billchenchina](https://github.com/billchenchina)**<br/>~° Simplified Chinese translation
* **[Kanthi Subramanian](https://github.com/subkanthi)**<br/>~° File Info Dialog
* **[Emanuele Petriglia](https://github.com/ema-pe)**<br>~° Italian translation
* **[Emanuele Petriglia](https://github.com/ema-pe)**<br/>~° Italian translation
* **[Tiago Danin](https://tiagodanin.github.io)**<br/>~° Brazilian Portuguese translation
* **[Jesica Chu](https://github.com/jesicachu)**<br/>~° Spanish and Traiditonal Chinese translation
* **[Ankush S Shetkar](https://www.linkedin.com/in/livelycoder/)**<br/>~° Added Chrome custom tabs for urls
* **[Lars Pontoppidan](https://github.com/larpon)**<br/>~° Danish translation
* **[Amaya Lim](https://github.com/nightrainlily)**<br/>~° Improve project description
* **[Jawkwon Im](https://github.com/jakeoneijk)**<br/>~° Add keep screen on
* **[Amaya Lim](https://github.com/nightrainlily)**<br/>~° Improved project description
* **[Jawkwon Im](https://github.com/jakeoneijk)**<br/>~° Added keep screen on
* **[Mark Goldman](https://github.com/goldmanm)**<br/>~° Added sorting for todo.txt, improved wiki
* **[natanelho]([email protected])**<br/>~° Hebrew translation
* **[Alexander Sachse]([email protected])**<br/>~° Added simple word counter
* **[Kyle Phelps]([email protected])**<br/>~° Added functionality to share multiple files from file browser
* **[Vladislav Glinsky](https://github.com/cl0ne)**<br/>~° Ukrainian/Russian translations
* **[David Hebbeker](https://david.hebbeker.info/)**<br/>~° Added tooltips for text actions.
* **[Harshad Srinivasan](https://github.com/harshad1)**<br/>~° Added functionality to handle leading spaces in lists.
* **[Niels](https://stackoverflow.com/users/432115/niels)**<br>~° Added encryption for textfile contents.
* **[Helguli](https://github.com/Helguli)**<br>~° Added fast scroll to editor.
* **[Patricia Heimfarth](https://github.com/PatriciaHeimfarth)**<br>~° Added checkbox for todo completion date
* **[Peter Schwede](https://github.com/pschwede)**<br>~° Added Zim-Wiki support.
* **[Frederic Jacob](https://github.com/fredericjacob)**<br>~° Added Zim-Wiki highlighting, text actions, view mode, page creation.
* **[Winston Feng](https://github.com/tifish)**<br>~° Support spaces in URL.
* **[k3b](https://github.com/k3b)**<br>~° Added CSV-Support.
* **[Ayowel](https://github.com/ayowel)**<br>~° Mermaid update.
* **[David Hebbeker](https://david.hebbeker.info/)**<br/>~° Added tooltips for text actions
* **[Harshad Srinivasan](https://github.com/harshad1)**<br/>~° Added functionality to handle leading spaces in lists
* **[Niels](https://stackoverflow.com/users/432115/niels)**<br/>~° Added encryption for textfile contents
* **[Helguli](https://github.com/Helguli)**<br/>~° Added fast scroll to editor
* **[Patricia Heimfarth](https://github.com/PatriciaHeimfarth)**<br/>~° Added checkbox for todo completion date
* **[Peter Schwede](https://github.com/pschwede)**<br/>~° Added Zim-Wiki support
* **[Frederic Jacob](https://github.com/fredericjacob)**<br/>~° Added Zim-Wiki highlighting, text actions, view mode, page creation
* **[Winston Feng](https://github.com/tifish)**<br/>~° Support spaces in URL
* **[k3b](https://github.com/k3b)**<br/>~° Added CSV-Support
* **[Li Guanglin](https://github.com/guanglinn)**<br/>~° Added line numbers support
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.gsantner.markor.model.AppSettings;
import net.gsantner.markor.model.Document;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.frontend.base.GsFragmentBase;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.util.GsFileUtils;
Expand Down Expand Up @@ -217,7 +218,7 @@ private void handleLaunchingIntent(final Intent intent) {
} else if (intentData != null) {
final String line = intentData.getQueryParameter("line");
if (line != null) {
startLine = TextViewUtils.tryParseInt(line, -1);
startLine = GsTextUtils.tryParseInt(line, -1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MarkdownSyntaxHighlighter extends SyntaxHighlighterBase {
private static final int MD_COLOR_LINK = 0xff1ea3fe;
private static final int MD_COLOR_LIST = 0xffdaa521;
private static final int MD_COLOR_QUOTE = 0xff88b04c;
private static final int MD_COLOR_CODEBLOCK = 0xff8c8c8c;
private static final int MD_COLOR_CODEBLOCK = 0x448c8c8c;

public MarkdownSyntaxHighlighter(AppSettings as) {
super(as);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

import other.com.vladsch.flexmark.ext.katex.FlexmarkKatexExtension;
import other.de.stanetz.jpencconverter.JavaPasswordbasedCryption;
import other.flexmark.ext.codeblocks.LineNumbersExtension;

@SuppressWarnings({"unchecked", "WeakerAccess"})
public class MarkdownTextConverter extends TextConverterBase {
Expand Down Expand Up @@ -83,7 +82,7 @@ public class MarkdownTextConverter extends TextConverterBase {
//########################
//## Injected CSS / JS / HTML
//########################
public static final String CSS_BODY = CSS_S + "body{margin:0;padding:2.5vw}" + CSS_E;
public static final String CSS_BODY = CSS_S + "body{margin:0;padding:1.25vh 2.5vw}" + CSS_E;
public static final String CSS_HEADER_UNDERLINE = CSS_S + " .header_no_underline { text-decoration: none; color: " + TOKEN_BW_INVERSE_OF_THEME + "; } h1 < a.header_no_underline { border-bottom: 2px solid #eaecef; } " + CSS_E;
public static final String CSS_H1_H2_UNDERLINE = CSS_S + " h1,h2 { border-bottom: 2px solid " + TOKEN_BW_INVERSE_OF_THEME_HEADER_UNDERLINE + "; } " + CSS_E;
public static final String CSS_BLOCKQUOTE_VERTICAL_LINE = CSS_S + "blockquote{padding:0px 14px;border-" + TOKEN_TEXT_DIRECTION + ":3.5px solid #dddddd;margin:4px 0}" + CSS_E;
Expand Down Expand Up @@ -158,28 +157,22 @@ public class MarkdownTextConverter extends TextConverterBase {
//########################

@Override
public String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file) {
public String convertMarkup(String markup, Context context, boolean lightMode, boolean enableLineNumbers, File file) {
String converted = "", onLoadJs = "", head = "";

final MutableDataSet options = new MutableDataSet();

if (lineNum) {
// Add code blocks Line numbers extension
final ArrayList<Extension> extensions = new ArrayList<>(flexmarkExtensions);
extensions.add(LineNumbersExtension.create());
options.set(Parser.EXTENSIONS, extensions);
} else {
options.set(Parser.EXTENSIONS, flexmarkExtensions);
}
options.set(Parser.EXTENSIONS, flexmarkExtensions);

options.set(Parser.SPACE_IN_LINK_URLS, true); // allow links like [this](some filename with spaces.md)
//options.set(HtmlRenderer.SOFT_BREAK, "<br />\n"); // Add linefeed to html break

// options.set(HtmlRenderer.SOFT_BREAK, "<br />\n"); // Add linefeed to HTML break

options.set(EmojiExtension.USE_IMAGE_TYPE, EmojiImageType.UNICODE_ONLY); // Use unicode (OS/browser images)

// GitLab extension
options.set(GitLabExtension.RENDER_BLOCK_MATH, false);

// gfm table parsing
// GFM table parsing
options.set(TablesExtension.WITH_CAPTION, false)
.set(TablesExtension.COLUMN_SPANS, true)
.set(TablesExtension.MIN_HEADER_ROWS, 0)
Expand Down Expand Up @@ -276,7 +269,7 @@ public String convertMarkup(String markup, Context context, boolean lightMode, b
}

// Enable View (block) code syntax highlighting
head += getViewHlPrismIncludes(GsContextUtils.instance.isDarkModeEnabled(context) ? "-tomorrow" : "", lineNum);
head += getViewHlPrismIncludes(GsContextUtils.instance.isDarkModeEnabled(context) ? "-tomorrow" : "", enableLineNumbers);

// Jekyll: Replace {{ site.baseurl }} with ..--> usually used in Jekyll blog _posts folder which is one folder below repository root, for reference to e.g. pictures in assets folder
markup = markup.replace("{{ site.baseurl }}", "..").replace(TOKEN_SITE_DATE_JEKYLL, TOKEN_POST_TODAY_DATE);
Expand Down Expand Up @@ -323,6 +316,15 @@ public String convertMarkup(String markup, Context context, boolean lightMode, b
}
}

if (_appSettings.getDocumentWrapState(file.getAbsolutePath())) {
onLoadJs += "wrapCodeBlockWords();";
}

if (enableLineNumbers) {
// For Prism line numbers plugin
onLoadJs += "enableLineNumbers();adjustLineNumbers();";
}

// Deliver result
return putContentIntoTemplate(context, converted, lightMode, file, onLoadJs, head);
}
Expand Down Expand Up @@ -360,18 +362,22 @@ private String escapeSpacesInLink(final String markup) {
}

@SuppressWarnings({"StringConcatenationInsideStringBufferAppend"})
private String getViewHlPrismIncludes(final String themeName, final boolean lineNum) {
private String getViewHlPrismIncludes(final String themeName, final boolean enableLineNumbers) {
final StringBuilder sb = new StringBuilder(1000);
sb.append(CSS_PREFIX + "prism/themes/prism" + themeName + ".min.css" + CSS_POSTFIX);
sb.append(CSS_PREFIX + "prism/style.css" + CSS_POSTFIX);
sb.append(JS_PREFIX + "prism/prism.js" + JS_POSTFIX);
sb.append(JS_PREFIX + "prism/plugins/autoloader/prism-autoloader.min.js" + JS_POSTFIX);
sb.append(JS_PREFIX + "prism/main.js" + JS_POSTFIX);

if (lineNum) {
sb.append(CSS_PREFIX + "prism/plugins/line-numbers/prism-line-numbers.css" + CSS_POSTFIX);
if (enableLineNumbers) {
sb.append(CSS_PREFIX + "prism/plugins/line-numbers/style.css" + CSS_POSTFIX);
sb.append(JS_PREFIX + "prism/plugins/line-numbers/prism-line-numbers.min.js" + JS_POSTFIX);
sb.append(JS_PREFIX + "prism/plugins/line-numbers/main.js" + JS_POSTFIX);
}
sb.append("\n");

return sb.append("\n").toString();
return sb.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ private void setDate() {
};

new DateFragment()
.setActivity(getActivity())
.setListener(listener)
.setCalendar(initDate)
.show(((FragmentActivity) getActivity()).getSupportFragmentManager(), "date");
Expand Down Expand Up @@ -359,7 +358,6 @@ private void setDueDate(final int offset) {
};

new DateFragment()
.setActivity(getActivity())
.setListener(listener)
.setCalendar(initDate)
.setMessage(getContext().getString(R.string.due_date))
Expand All @@ -378,7 +376,6 @@ public static class DateFragment extends DialogFragment {
private DatePickerDialog.OnClickListener _extraListener;
private String _extraLabel;

private Activity _activity;
private int _year;
private int _month;
private int _day;
Expand All @@ -404,11 +401,6 @@ public DateFragment setExtraLabel(String label) {
return this;
}

public DateFragment setActivity(Activity activity) {
_activity = activity;
return this;
}

public DateFragment setYear(int year) {
_year = year;
return this;
Expand Down Expand Up @@ -438,10 +430,10 @@ public DateFragment setCalendar(Calendar calendar) {

@NonNull
@Override
public DatePickerDialog onCreateDialog(Bundle savedInstanceState) {
public DatePickerDialog onCreateDialog(final Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);

DatePickerDialog dialog = new DatePickerDialog(_activity, _listener, _year, _month, _day);
final DatePickerDialog dialog = new DatePickerDialog(getContext(), _listener, _year, _month, _day);

if (_message != null && !_message.isEmpty()) {
dialog.setMessage(_message);
Expand All @@ -453,5 +445,14 @@ public DatePickerDialog onCreateDialog(Bundle savedInstanceState) {

return dialog;
}

@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Do not auto-recreate
if (savedInstanceState != null) {
dismiss();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package net.gsantner.markor.frontend;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Editable;
Expand All @@ -22,7 +21,6 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import net.gsantner.markor.ApplicationObject;
import net.gsantner.markor.R;
Expand All @@ -32,6 +30,7 @@
import net.gsantner.markor.frontend.textview.TextViewUtils;
import net.gsantner.markor.model.AppSettings;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.frontend.GsAudioRecordOmDialog;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions;
import net.gsantner.opoc.util.GsFileUtils;
Expand Down Expand Up @@ -231,7 +230,7 @@ private static void insertItem(

// Title, path to be written when the user hits accept
final GsCallback.a2<String, String> insertLink = (title, path) -> {
if (TextViewUtils.isNullOrEmpty(path)) {
if (GsTextUtils.isNullOrEmpty(path)) {
return;
}

Expand Down Expand Up @@ -259,46 +258,56 @@ private static void insertItem(
}
};

final GsCallback.a1<File> insertFileLink = (file) -> {
// Pull dialog elements
final EditText nameEdit, pathEdit;
if (dialog != null) {
nameEdit = dialog.findViewById(R.id.ui__select_path_dialog__name);
pathEdit = dialog.findViewById(R.id.ui__select_path_dialog__url);
} else {
nameEdit = pathEdit = null;
}

// Defensive checks to make sure file has not changed
// Can happen if the callback is triggered after a long delay
final long hash = GsFileUtils.crc32(text);

final GsCallback.a1<String> insertFileLink = (path) -> {
if (GsFileUtils.crc32(text) != hash) {
return;
}

// If path is not under notebook, copy it to the res folder
File file = new File(path);
if (!GsFileUtils.isChild(_appSettings.getNotebookDirectory(), file)) {
final File local = GsFileUtils.findNonConflictingDest(attachmentDir, file.getName());
attachmentDir.mkdirs();
GsFileUtils.copyFile(file, local);
file = local;
}
final String title = GsFileUtils.getFilenameWithoutExtension(file);
final String path = GsFileUtils.relativePath(currentFile, file);
insertLink.callback(title, path);
};

final MarkorContextUtils shu = new MarkorContextUtils(activity);
final BroadcastReceiver br = shu.receiveResultFromLocalBroadcast(
activity,
(intent, _br) -> insertFileLink.callback(new File(intent.getStringExtra(MarkorContextUtils.EXTRA_FILEPATH))),
true,
"" + MarkorContextUtils.REQUEST_CAMERA_PICTURE,
"" + MarkorContextUtils.REQUEST_PICK_PICTURE,
"" + MarkorContextUtils.REQUEST_RECORD_AUDIO
);
// Pull the appropriate title
String title = "";
if (nameEdit != null) {
title = nameEdit.getText().toString();
}

final EditText nameEdit, pathEdit;
if (dialog != null) {
nameEdit = dialog.findViewById(R.id.ui__select_path_dialog__name);
pathEdit = dialog.findViewById(R.id.ui__select_path_dialog__url);
dialog.setOnDismissListener(d -> LocalBroadcastManager.getInstance(activity).unregisterReceiver(br));
} else {
nameEdit = pathEdit = null;
}
if (GsTextUtils.isNullOrEmpty(title)) {
title = GsFileUtils.getFilenameWithoutExtension(file);
}

insertLink.callback(title, GsFileUtils.relativePath(currentFile, file));
};

final MarkorContextUtils cu = new MarkorContextUtils(activity);

// Do each thing as necessary
switch (action) {
case IMAGE_CAMERA: {
shu.requestCameraPicture(activity);
cu.requestCameraPicture(activity, insertFileLink);
break;
}
case IMAGE_GALLERY: {
shu.requestGalleryPicture(activity);
cu.requestGalleryPicture(activity, insertFileLink);
break;
}
case IMAGE_EDIT: {
Expand All @@ -307,19 +316,19 @@ private static void insertItem(

final File abs = new File(path).getAbsoluteFile();
if (abs.isFile()) {
shu.requestFileEdit(activity, abs);
cu.requestFileEdit(activity, abs);
break;
}

final File rel = new File(currentFile.getParentFile(), path).getAbsoluteFile();
if (rel.isFile()) {
shu.requestFileEdit(activity, rel);
cu.requestFileEdit(activity, rel);
}
}
break;
}
case AUDIO_RECORDING: {
if (!shu.requestAudioRecording(activity)) {
if (!cu.requestAudioRecording(activity, insertFileLink)) {
GsAudioRecordOmDialog.showAudioRecordDialog(activity, R.string.record_audio, insertFileLink);
}
break;
Expand All @@ -333,7 +342,7 @@ private static void insertItem(
public void onFsViewerSelected(final String request, final File file, final Integer lineNumber) {
pathEdit.setText(GsFileUtils.relativePath(currentFile, file));

if (TextViewUtils.isNullOrEmpty(nameEdit.getText())) {
if (GsTextUtils.isNullOrEmpty(nameEdit.getText())) {
nameEdit.setText(GsFileUtils.getFilenameWithoutExtension(file));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import net.gsantner.markor.R;
import net.gsantner.markor.frontend.textview.TextViewUtils;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.model.GsSharedPreferencesPropertyBackend;

import org.json.JSONArray;
Expand Down Expand Up @@ -244,7 +245,7 @@ private Pattern makePattern() {
}

private String getReplacePattern() {
return TextViewUtils.unescapeString(replaceText.getText().toString());
return GsTextUtils.unescapeString(replaceText.getText().toString());
}

private void updateUI() {
Expand Down
Loading

0 comments on commit e6f9d83

Please sign in to comment.