Skip to content

Commit

Permalink
Merge branch 'master' into new_folder_in_copy_move_dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner authored Sep 11, 2023
2 parents 5e1ef2c + 3d5ff90 commit aa8a161
Show file tree
Hide file tree
Showing 95 changed files with 2,581 additions and 857 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
_hlEditor.setTextColor(_appSettings.getEditorForegroundColor());
_hlEditor.setGravity(_appSettings.isEditorStartEditingInCenter() ? Gravity.CENTER : Gravity.NO_GRAVITY);
_hlEditor.setHighlightingEnabled(_appSettings.getDocumentHighlightState(_document.getPath(), _hlEditor.getText()));
_hlEditor.setLineNumbersEnabled(_appSettings.getDocumentLineNumbersEnabled(_document.getPath()));
_hlEditor.setAutoFormatEnabled(_appSettings.getDocumentAutoFormatEnabled(_document.getPath()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Do not need to send contents to accessibility
Expand Down Expand Up @@ -458,7 +459,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
if (saveDocument(false)) {
TextConverterBase converter = FormatRegistry.getFormat(_document.getFormat(), activity, _document).getConverter();
_cu.shareText(getActivity(),
converter.convertMarkup(getTextString(), getActivity(), false, _document.getFile()),
converter.convertMarkup(getTextString(), getActivity(), false, _hlEditor.getLineNumbersEnabled(), _document.getFile()),
"text/" + (item.getItemId() == R.id.action_share_html ? "html" : "plain")
);
}
Expand Down Expand Up @@ -561,6 +562,13 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
updateMenuToggleStates(0);
return true;
}
case R.id.action_line_numbers: {
final boolean newState = !_hlEditor.getLineNumbersEnabled();
_appSettings.setDocumentLineNumbersEnabled(_document.getPath(), newState);
_hlEditor.setLineNumbersEnabled(newState);
updateMenuToggleStates(0);
return true;
}
case R.id.action_enable_highlighting: {
final boolean newState = !_hlEditor.getHighlightingEnabled();
_hlEditor.setHighlightingEnabled(newState);
Expand Down Expand Up @@ -626,6 +634,9 @@ private void updateMenuToggleStates(final int selectedFormatActionId) {
if ((mi = _fragmentMenu.findItem(R.id.action_enable_highlighting)) != null) {
mi.setChecked(_hlEditor.getHighlightingEnabled());
}
if ((mi = _fragmentMenu.findItem(R.id.action_line_numbers)) != null) {
mi.setChecked(_hlEditor.getLineNumbersEnabled());
}
if ((mi = _fragmentMenu.findItem(R.id.action_enable_auto_format)) != null) {
mi.setChecked(_hlEditor.getAutoFormatEnabled());
}
Expand Down Expand Up @@ -747,7 +758,7 @@ private boolean isDisplayedAtMainActivity() {

public void updateViewModeText() {
final String text = getTextString();
_format.getConverter().convertMarkupShowInWebView(_document, text, getActivity(), _webView, _nextConvertToPrintMode);
_format.getConverter().convertMarkupShowInWebView(_document, text, getActivity(), _webView, _nextConvertToPrintMode, _hlEditor.getLineNumbersEnabled());
}

public void setViewModeVisibility(boolean show) {
Expand Down
31 changes: 13 additions & 18 deletions app/src/main/java/net/gsantner/markor/format/TextConverterBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.gsantner.markor.model.Document;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.util.GsFileUtils;

import java.io.File;
import java.util.Date;
Expand Down Expand Up @@ -97,19 +98,18 @@ public TextConverterBase() {
* @param webView The WebView content to be shown in
* @return Copy of converted html
*/
public String convertMarkupShowInWebView(Document document, String content, Activity context, WebView webView, boolean isExportInLightMode) {
public String convertMarkupShowInWebView(Document document, String content, Activity context, WebView webView, boolean lightMode, boolean lineNum) {
String html;
try {
html = convertMarkup(content, context, isExportInLightMode, document.getFile());
html = convertMarkup(content, context, lightMode, lineNum, document.getFile());
} catch (Exception e) {
html = "Please report at project issue tracker: " + e.toString();
html = "Please report at project issue tracker: " + e;
}

String baseFolder = ApplicationObject.settings().getNotebookDirectory().getAbsolutePath();
if (document.getFile().getParentFile() != null) {
baseFolder = document.getFile().getParent();
String baseFolder = document.getFile().getParent();
if (baseFolder == null) {
baseFolder = "file://" + baseFolder + "/";
}
baseFolder = "file://" + baseFolder + "/";
webView.loadDataWithBaseURL(baseFolder, html, getContentType(), UTF_CHARSET, null);

// When TOKEN_TEXT_CONVERTER_MAX_ZOOM_OUT_BY_DEFAULT is contained in text zoom out as far possible
Expand All @@ -121,21 +121,16 @@ public String convertMarkupShowInWebView(Document document, String content, Acti
return html;
}

protected String getFileExtension(File file) {
if (file == null) {
return "";
}
return (file.getName().contains(".") ? file.getName().substring(file.getName().lastIndexOf(".")) : "").toLowerCase();
}

/**
* Convert markup text to target format
*
* @param markup Markup text
* @param context Android Context
* @param markup Markup text
* @param context Android Context
* @param lightMode
* @param lineNum
* @return html as String
*/
public abstract String convertMarkup(String markup, Context context, boolean isExportInLightMode, File file);
public abstract String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file);

protected String putContentIntoTemplate(Context context, String content, boolean isExportInLightMode, File file, String onLoadJs, String head) {
final String contentLower = content.toLowerCase();
Expand Down Expand Up @@ -185,7 +180,7 @@ protected String putContentIntoTemplate(Context context, String content, boolean
.replace(TOKEN_ACCENT_COLOR, GsTextUtils.colorToHexString(ContextCompat.getColor(context, R.color.accent)))
.replace(TOKEN_TEXT_DIRECTION, _appSettings.isRenderRtl() ? "right" : "left")
.replace(TOKEN_FONT, font)
.replace(TOKEN_TEXT_CONVERTER_CSS_CLASS, "format-" + getClass().getSimpleName().toLowerCase().replace("textconverter", "").replace("converter", "") + " fileext-" + getFileExtension(file).replace(".", ""))
.replace(TOKEN_TEXT_CONVERTER_CSS_CLASS, "format-" + getClass().getSimpleName().toLowerCase().replace("textconverter", "").replace("converter", "") + " fileext-" + GsFileUtils.getFilenameExtension(file).replace(".", ""))
.replace(TOKEN_POST_TODAY_DATE, DateFormat.getDateFormat(context).format(new Date()))
.replace(TOKEN_FILEURI_VIEWED_FILE, (file != null ? Uri.fromFile(file.getAbsoluteFile()).toString() : "file:///dummy").replace("'", "\\'").replace("\"", "\\\""));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
package net.gsantner.markor.format.asciidoc;

import android.content.Context;

import net.gsantner.markor.format.TextConverterBase;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.util.GsContextUtils;

import java.io.File;
import java.util.Arrays;
Expand All @@ -32,7 +34,7 @@ public class AsciidocTextConverter extends TextConverterBase {
public static final String HTML_ASCIIDOCJS_DARK_CSS_INCLUDE = "file:///android_asset/asciidoc/dark.css";

@Override
public String convertMarkup(String markup, Context context, boolean isExportInLightMode, File file) {
public String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file) {
String converted = "<div id=\"asciidoc_content\"></div>\n";
String onLoadJs = "var textBase64 = `" +
//convert a text to base64 to simplify supporting special characters
Expand All @@ -51,10 +53,10 @@ public String convertMarkup(String markup, Context context, boolean isExportInLi
//standalone : true - to generate header 1 (= title) in the page. if don't do that - title will be absent.
//nofooter: true - to don't generate footer (Last updated ...). if don't do that and use standalone : true - the page will have that footer.
"var html = asciidoctor.convert(utf8PlainText, {standalone : true, attributes : {nofooter: true, stylesheet: \"" +
(isExportInLightMode ? HTML_ASCIIDOCJS_DEFAULT_CSS_INCLUDE : HTML_ASCIIDOCJS_DARK_CSS_INCLUDE)
(!lightMode && GsContextUtils.instance.isDarkModeEnabled(context) ? HTML_ASCIIDOCJS_DARK_CSS_INCLUDE : HTML_ASCIIDOCJS_DEFAULT_CSS_INCLUDE)
+ "\"}});\n" +
"document.getElementById(\"asciidoc_content\").innerHTML = html;";
return putContentIntoTemplate(context, converted, isExportInLightMode, file, onLoadJs, HTML_ASCIIDOCJS_JS_INCLUDE);
return putContentIntoTemplate(context, converted, lightMode, file, onLoadJs, HTML_ASCIIDOCJS_JS_INCLUDE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class EmbedBinaryTextConverter extends TextConverterBase {

@SuppressWarnings({"ConstantConditions", "StringConcatenationInLoop"})
@Override
public String convertMarkup(String markup, Context context, boolean isExportInLightMode, File file) {
public String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file) {
String converted = "", onLoadJs = "", head = "";
if (file == null) {
return "";
Expand Down Expand Up @@ -152,7 +152,7 @@ public String convertMarkup(String markup, Context context, boolean isExportInLi
}

converted += HTML101_BODY_END;
return putContentIntoTemplate(context, converted, isExportInLightMode, file, onLoadJs, head);
return putContentIntoTemplate(context, converted, lightMode, file, onLoadJs, head);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.opencsv.CSVReaderBuilder;
import com.opencsv.ICSVParser;

import net.gsantner.markor.format.TextConverterBase;
import net.gsantner.markor.format.markdown.MarkdownTextConverter;

import java.io.BufferedReader;
Expand All @@ -33,17 +34,17 @@
* Part of Markor-Architecture implementing Preview/Export for csv.
* <p>
* Converts csv to md and let
* {@link MarkdownTextConverter#convertMarkup(String, Context, boolean, File)}
* {@link TextConverterBase#convertMarkup(String, Context, boolean, boolean, File)}
* do the rest.
* <p>
* This way csv columns may contain md expressions like bold text.
*/
@SuppressWarnings("WeakerAccess")
public class CsvTextConverter extends MarkdownTextConverter {
@Override
public String convertMarkup(String csvMarkup, Context context, boolean isExportInLightMode, File file) {
public String convertMarkup(String csvMarkup, Context context, boolean lightMode, boolean lineNum, File file) {
String mdMarkup = Csv2MdTable.toMdTable(csvMarkup);
return super.convertMarkup(mdMarkup, context, isExportInLightMode, file);
return super.convertMarkup(mdMarkup, context, lightMode, lineNum, file);
}

@Override
Expand Down Expand Up @@ -133,7 +134,8 @@ private static void addColumnsLine(StringBuilder mdMarkup, @NonNull String[] col
mdMarkup.append(MD_COL_DELIMITER).append(MD_LINE_DELIMITER);
}

@NonNull private static String getCol(@NonNull String[] columns, int i) {
@NonNull
private static String getCol(@NonNull String[] columns, int i) {
return (i >= 0 && i < columns.length) ? columns[i] : "";
}

Expand Down
Loading

0 comments on commit aa8a161

Please sign in to comment.