diff --git a/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeActionButtons.java b/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeActionButtons.java index bb2f7b9cce..a69b4d14ba 100644 --- a/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeActionButtons.java +++ b/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeActionButtons.java @@ -30,7 +30,12 @@ public List getFormatActionList() { new ActionItem(R.string.abid_common_deindent, R.drawable.ic_format_indent_decrease_black_24dp, R.string.deindent), new ActionItem(R.string.abid_common_insert_link, R.drawable.ic_link_black_24dp, R.string.insert_link), new ActionItem(R.string.abid_common_insert_image, R.drawable.ic_image_black_24dp, R.string.insert_image), - new ActionItem(R.string.abid_common_insert_audio, R.drawable.ic_keyboard_voice_black_24dp, R.string.audio) + new ActionItem(R.string.abid_common_insert_audio, R.drawable.ic_keyboard_voice_black_24dp, R.string.audio), + new ActionItem(R.string.abid_orgmode_bold, R.drawable.ic_format_bold_black_24dp, R.string.bold), + new ActionItem(R.string.abid_orgmode_italic, R.drawable.ic_format_italic_black_24dp, R.string.italic), + new ActionItem(R.string.abid_orgmode_strikeout, R.drawable.ic_format_strikethrough_black_24dp, R.string.strikeout), + new ActionItem(R.string.abid_orgmode_underline, R.drawable.ic_format_underlined_black_24dp, R.string.underline), + new ActionItem(R.string.abid_orgmode_code_inline, R.drawable.ic_code_black_24dp, R.string.inline_code) ); } @@ -45,4 +50,33 @@ protected void renumberOrderedList() { // Use markdown format for orgmode too AutoTextFormatter.renumberOrderedList(_hlEditor.getText(), MarkdownReplacePatternGenerator.formatPatterns); } + + @Override + public boolean onActionClick(final @StringRes int action) { + switch (action) { + case R.string.abid_orgmode_bold: { + runSurroundAction("*"); + return true; + } + case R.string.abid_orgmode_italic: { + runSurroundAction("/"); + return true; + } + case R.string.abid_orgmode_strikeout: { + runSurroundAction("+"); + return true; + } + case R.string.abid_orgmode_underline: { + runSurroundAction("_"); + return true; + } + case R.string.abid_orgmode_code_inline: { + runSurroundAction("="); + return true; + } + default: { + return runCommonAction(action); + } + } + } } diff --git a/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeSyntaxHighlighter.java b/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeSyntaxHighlighter.java index 02eaf15da4..22586b4de8 100644 --- a/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeSyntaxHighlighter.java +++ b/app/src/main/java/net/gsantner/markor/format/orgmode/OrgmodeSyntaxHighlighter.java @@ -1,6 +1,8 @@ package net.gsantner.markor.format.orgmode; +import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Typeface; import net.gsantner.markor.frontend.textview.SyntaxHighlighterBase; import net.gsantner.markor.model.AppSettings; @@ -8,7 +10,12 @@ import java.util.regex.Pattern; public class OrgmodeSyntaxHighlighter extends SyntaxHighlighterBase { - + public final static String COMMON_EMPHASIS_PATTERN = "(?<=(\\n|^|\\s|\\{|\\())([%s])(?=\\S)(.*?)\\S\\2(?=(\\n|$|\\s|\\.|,|:|;|-|\\}|\\)))"; + public final static Pattern BOLD = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "*")); + public final static Pattern ITALICS = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "/")); + public final static Pattern STRIKETHROUGH = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "+")); + public final static Pattern UNDERLINE = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "_")); + public final static Pattern CODE_INLINE = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "=~")); 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|$)"); @@ -44,6 +51,12 @@ protected void generateSpans() { createColorSpanForMatches(PREAMBLE, ORG_COLOR_DIM); createColorSpanForMatches(COMMENT, ORG_COLOR_DIM); createColorBackgroundSpan(BLOCK, ORG_COLOR_BLOCK); + + createStyleSpanForMatches(BOLD, Typeface.BOLD); + createStyleSpanForMatches(ITALICS, Typeface.ITALIC); + createStrikeThroughSpanForMatches(STRIKETHROUGH); + createColoredUnderlineSpanForMatches(UNDERLINE, Color.BLACK); + createMonospaceSpanForMatches(CODE_INLINE); } } diff --git a/app/src/main/res/values/string-not_translatable.xml b/app/src/main/res/values/string-not_translatable.xml index 5722b3ccb0..b94b958639 100644 --- a/app/src/main/res/values/string-not_translatable.xml +++ b/app/src/main/res/values/string-not_translatable.xml @@ -348,6 +348,13 @@ work. If not, see . abid_todotxt_due_date abid_todotxt_sort_todo + + abid_orgmode_bold + abid_orgmode_italic + abid_orgmode_strikeout + abid_orgmode_underline + abid_orgmode_code_inline + Jekyll Post Wikitext / Zim