forked from gsantner/markor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rework_attachments
- Loading branch information
Showing
13 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeActionButtons.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.gsantner.markor.format.orgmode; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.StringRes; | ||
|
||
import net.gsantner.markor.R; | ||
import net.gsantner.markor.format.ActionButtonBase; | ||
import net.gsantner.markor.format.markdown.MarkdownReplacePatternGenerator; | ||
import net.gsantner.markor.frontend.textview.AutoTextFormatter; | ||
import net.gsantner.markor.model.Document; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class OrgmodeActionButtons extends ActionButtonBase { | ||
|
||
public OrgmodeActionButtons(@NonNull Context context, Document document) { | ||
super(context, document); | ||
} | ||
|
||
@Override | ||
public List<ActionItem> getActiveActionList() { | ||
final ActionItem[] TMA_ACTIONS = { | ||
new ActionItem(R.string.abid_common_checkbox_list, R.drawable.ic_check_box_black_24dp, R.string.check_list), | ||
new ActionItem(R.string.abid_common_unordered_list_char, R.drawable.ic_list_black_24dp, R.string.unordered_list), | ||
new ActionItem(R.string.abid_common_ordered_list_number, R.drawable.ic_format_list_numbered_black_24dp, R.string.ordered_list), | ||
new ActionItem(R.string.abid_common_delete_lines, R.drawable.ic_delete_black_24dp, R.string.delete_lines), | ||
new ActionItem(R.string.abid_common_open_link_browser, R.drawable.ic_open_in_browser_black_24dp, R.string.open_link), | ||
new ActionItem(R.string.abid_common_attach_something, R.drawable.ic_attach_file_black_24dp, R.string.attach), | ||
new ActionItem(R.string.abid_common_special_key, R.drawable.ic_keyboard_black_24dp, R.string.special_key), | ||
new ActionItem(R.string.abid_common_time, R.drawable.ic_access_time_black_24dp, R.string.date_and_time), | ||
new ActionItem(R.string.abid_common_indent, R.drawable.ic_format_indent_increase_black_24dp, R.string.indent), | ||
new ActionItem(R.string.abid_common_deindent, R.drawable.ic_format_indent_decrease_black_24dp, R.string.deindent), | ||
new ActionItem(R.string.abid_common_new_line_below, R.drawable.ic_baseline_keyboard_return_24, R.string.start_new_line_below), | ||
new ActionItem(R.string.abid_common_move_text_one_line_up, R.drawable.ic_baseline_arrow_upward_24, R.string.move_text_one_line_up), | ||
new ActionItem(R.string.abid_common_move_text_one_line_down, R.drawable.ic_baseline_arrow_downward_24, R.string.move_text_one_line_down), | ||
new ActionItem(R.string.abid_common_insert_snippet, R.drawable.ic_baseline_file_copy_24, R.string.insert_snippet), | ||
|
||
new ActionItem(R.string.abid_common_web_jump_to_very_top_or_bottom, R.drawable.ic_vertical_align_center_black_24dp, R.string.jump_to_bottom, ActionItem.DisplayMode.VIEW), | ||
new ActionItem(R.string.abid_common_view_file_in_other_app, R.drawable.ic_open_in_browser_black_24dp, R.string.open_with, ActionItem.DisplayMode.ANY), | ||
new ActionItem(R.string.abid_common_rotate_screen, R.drawable.ic_rotate_left_black_24dp, R.string.rotate, ActionItem.DisplayMode.ANY), | ||
}; | ||
|
||
return Arrays.asList(TMA_ACTIONS); | ||
} | ||
|
||
@Override | ||
protected @StringRes | ||
int getFormatActionsKey() { | ||
return R.string.pref_key__orgmode__action_keys; | ||
} | ||
|
||
@Override | ||
protected void renumberOrderedList() { | ||
// Use markdown format for orgmode too | ||
AutoTextFormatter.renumberOrderedList(_hlEditor.getText(), MarkdownReplacePatternGenerator.formatPatterns); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeSyntaxHighlighter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.gsantner.markor.format.orgmode; | ||
|
||
import android.graphics.Paint; | ||
|
||
import net.gsantner.markor.frontend.textview.SyntaxHighlighterBase; | ||
import net.gsantner.markor.model.AppSettings; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class OrgmodeSyntaxHighlighter extends SyntaxHighlighterBase { | ||
|
||
public final static Pattern HEADING = Pattern.compile("(?m)^(\\*+)\\s(.*?)(?=\\n|$)"); | ||
public final static Pattern BLOCK = Pattern.compile("(?m)(?<=#\\+BEGIN_.{1,15}$\\s)[\\s\\S]*?(?=#\\+END)"); | ||
public final static Pattern PREAMBLE = Pattern.compile("(?m)^(#\\+)(.*?)(?=\\n|$)"); | ||
public final static Pattern COMMENT = Pattern.compile("(?m)^(#+)\\s(.*?)(?=\\n|$)"); | ||
public final static Pattern LIST_UNORDERED = Pattern.compile("(\\n|^)\\s{0,16}([*+-])( \\[[ xX]\\])?(?= )"); | ||
public final static Pattern LIST_ORDERED = Pattern.compile("(?m)^\\s{0,16}(\\d+)(:?\\.|\\))\\s"); | ||
public final static Pattern LINK = Pattern.compile("\\[\\[.*?]]|<.*?>|https?://\\S+|\\[.*?]\\[.*?]|\\[.*?]\n"); | ||
private static final int ORG_COLOR_HEADING = 0xffef6D00; | ||
private static final int ORG_COLOR_LINK = 0xff1ea3fe; | ||
private static final int ORG_COLOR_LIST = 0xffdaa521; | ||
private static final int ORG_COLOR_DIM = 0xff8c8c8c; | ||
private static final int ORG_COLOR_BLOCK = 0xdddddddd; | ||
|
||
public OrgmodeSyntaxHighlighter(AppSettings as) { | ||
super(as); | ||
} | ||
|
||
@Override | ||
public SyntaxHighlighterBase configure(Paint paint) { | ||
_delay = _appSettings.getOrgmodeHighlightingDelay(); | ||
return super.configure(paint); | ||
} | ||
|
||
@Override | ||
protected void generateSpans() { | ||
createTabSpans(_tabSize); | ||
createUnderlineHexColorsSpans(); | ||
createSmallBlueLinkSpans(); | ||
createColorSpanForMatches(HEADING, ORG_COLOR_HEADING); | ||
createColorSpanForMatches(LINK, ORG_COLOR_LINK); | ||
createColorSpanForMatches(LIST_UNORDERED, ORG_COLOR_LIST); | ||
createColorSpanForMatches(LIST_ORDERED, ORG_COLOR_LIST); | ||
createColorSpanForMatches(PREAMBLE, ORG_COLOR_DIM); | ||
createColorSpanForMatches(COMMENT, ORG_COLOR_DIM); | ||
createColorBackgroundSpan(BLOCK, ORG_COLOR_BLOCK); | ||
} | ||
|
||
} | ||
|
53 changes: 53 additions & 0 deletions
53
app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeTextConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.gsantner.markor.format.orgmode; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.core.text.TextUtilsCompat; | ||
|
||
import net.gsantner.markor.format.TextConverterBase; | ||
import net.gsantner.opoc.util.GsFileUtils; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public class OrgmodeTextConverter extends TextConverterBase { | ||
private static final String HTML100_BODY_PRE_BEGIN = "<pre style='white-space: pre-wrap;font-family: " + TOKEN_FONT + "' >"; | ||
private static final String HTML101_BODY_PRE_END = "</pre>"; | ||
private static final List<String> EXT_ORG = Arrays.asList(".org"); | ||
private static final List<String> EXT = new ArrayList<>(); | ||
|
||
static { | ||
EXT.addAll(EXT_ORG); | ||
} | ||
|
||
//######################## | ||
//## Methods | ||
//######################## | ||
|
||
@Override | ||
public String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file) { | ||
String converted = "", onLoadJs = "", head = ""; | ||
final String extWithDot = GsFileUtils.getFilenameExtension(file); | ||
|
||
/////////////////////////////////////////// | ||
// Convert | ||
/////////////////////////////////////////// | ||
converted = HTML100_BODY_PRE_BEGIN | ||
+ TextUtilsCompat.htmlEncode(markup) | ||
+ HTML101_BODY_PRE_END; | ||
return putContentIntoTemplate(context, converted, lightMode, file, onLoadJs, head); | ||
} | ||
|
||
@Override | ||
protected String getContentType() { | ||
return CONTENT_TYPE_HTML; | ||
} | ||
|
||
@Override | ||
protected boolean isFileOutOfThisFormat(String filepath, String extWithDot) { | ||
return EXT.contains(extWithDot); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.