Skip to content

Commit

Permalink
orgmode: add more text styling syntax and textactions (PR #2450)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxkn authored Oct 22, 2024
1 parent fd14805 commit e332c93
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public List<ActionItem> 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)
);
}

Expand All @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
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;

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|$)");
Expand Down Expand Up @@ -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);
}

}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="abid_todotxt_due_date" translatable="false">abid_todotxt_due_date</string>
<string name="abid_todotxt_sort_todo" translatable="false">abid_todotxt_sort_todo</string>


<string name="abid_orgmode_bold" translatable="false">abid_orgmode_bold</string>
<string name="abid_orgmode_italic" translatable="false">abid_orgmode_italic</string>
<string name="abid_orgmode_strikeout" translatable="false">abid_orgmode_strikeout</string>
<string name="abid_orgmode_underline" translatable="false">abid_orgmode_underline</string>
<string name="abid_orgmode_code_inline" translatable="false">abid_orgmode_code_inline</string>


<string name="jekyll_post" translatable="false">Jekyll Post</string>
<string name="wikitext" translatable="false">Wikitext / Zim</string>
Expand Down

0 comments on commit e332c93

Please sign in to comment.