Skip to content

Commit

Permalink
ZimWiki: Syntax highlighting for code, global setting (PR #1434 by @f…
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericjacob authored Sep 13, 2021
1 parent 2005fa4 commit 3bc417c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MarkdownHighlighter extends Highlighter {
private final boolean _highlightLineEnding;
private final boolean _highlightCodeChangeFont;
private final boolean _highlightBiggerHeadings;
private final boolean _highlightDisableCodeBlock;
private final boolean _highlightCodeBlock;

private static final int MD_COLOR_HEADING = 0xffef6D00;
private static final int MD_COLOR_LINK = 0xff1ea3fe;
Expand All @@ -38,9 +38,9 @@ public MarkdownHighlighter(HighlightingEditor hlEditor, Document document) {
super(hlEditor, document);
_highlightLinks = false;
_highlightLineEnding = _appSettings.isMarkdownHighlightLineEnding();
_highlightCodeChangeFont = _appSettings.isMarkdownHighlightCodeFontMonospaceAllowed();
_highlightCodeChangeFont = _appSettings.isHighlightCodeMonospaceFont();
_highlightBiggerHeadings = _appSettings.isMarkdownBiggerHeadings();
_highlightDisableCodeBlock = _appSettings.isMarkdownDisableCodeBlockHighlight();
_highlightCodeBlock = _appSettings.isHighlightCodeBlock();
setTextModifier(new ListHandler(_appSettings.isMarkdownAutoUpdateList(), MarkdownAutoFormat.getPrefixPatterns()));
}

Expand Down Expand Up @@ -85,7 +85,7 @@ protected Spannable run(final Spannable spannable) {
createMonospaceSpanForMatches(spannable, MarkdownHighlighterPattern.CODE.pattern);
}
_profiler.restart("Code - bgcolor");
if (!_highlightDisableCodeBlock) {
if (_highlightCodeBlock) {
createColorBackgroundSpan(spannable, MarkdownHighlighterPattern.CODE.pattern, MD_COLOR_CODEBLOCK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static class Colors {
private static final int CHECKLIST_CHECKED_COLOR = 0xff54a309;
private static final int CHECKLIST_CROSSED_COLOR = 0xffa90000;
private static final int ZIMHEADER_COLOR = 0xff808080;
private static final int CODEBLOCK_COLOR = 0xff8c8c8c;
}


Expand Down Expand Up @@ -120,10 +121,20 @@ protected Spannable run(final Spannable spannable) {
createSpanWithStrikeThroughForMatches(spannable, Patterns.STRIKETHROUGH.pattern);

_profiler.restart("Preformatted (monospaced) inline");
createMonospaceSpanForMatches(spannable, Patterns.PREFORMATTED_INLINE.pattern);
if (_appSettings.isHighlightCodeMonospaceFont()) {
createMonospaceSpanForMatches(spannable, Patterns.PREFORMATTED_INLINE.pattern);
}
if (_appSettings.isHighlightCodeBlock()) {
createColorBackgroundSpan(spannable, Patterns.PREFORMATTED_INLINE.pattern, Colors.CODEBLOCK_COLOR);
}

_profiler.restart("Preformatted (monospaced) multiline");
createMonospaceSpanForMatches(spannable, Patterns.PREFORMATTED_MULTILINE.pattern); // TODO: also indent a bit
if (_appSettings.isHighlightCodeMonospaceFont()) {
createMonospaceSpanForMatches(spannable, Patterns.PREFORMATTED_MULTILINE.pattern);
}
if (_appSettings.isHighlightCodeBlock()) {
createColorBackgroundSpan(spannable, Patterns.PREFORMATTED_MULTILINE.pattern, Colors.CODEBLOCK_COLOR);
}

_profiler.restart("Unordered list");
createColorSpanForMatches(spannable, Patterns.LIST_UNORDERED.pattern, Colors.UNORDERED_LIST_BULLET_COLOR);
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/net/gsantner/markor/util/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ public boolean isMarkdownHighlightLineEnding() {
return getBool(R.string.pref_key__markdown__highlight_lineending_two_or_more_space, false);
}

public boolean isMarkdownHighlightCodeFontMonospaceAllowed() {
return getBool(R.string.pref_key__markdown__monospace_some_parts, false);
public boolean isHighlightCodeMonospaceFont() {
return getBool(R.string.pref_key__highlight_code_monospace_font, false);
}

public boolean isMarkdownDisableCodeBlockHighlight() {
return getBool(R.string.pref_key__markdown__disable_code_block_highlight, false);
public boolean isHighlightCodeBlock() {
return !getBool(R.string.pref_key__hightlight_code_block_disabled, false);
}

public boolean isMarkdownAutoUpdateList() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__markdown__hl_delay_v2" translatable="false">pref_key__markdown__hl_delay_v2</string>
<string name="pref_key__quicknote_filepath" translatable="false">pref_key__quicknote_filepath</string>
<string name="pref_key__markdown__highlight_lineending_two_or_more_space" translatable="false">pref_key__markdown__highlight_lineending_two_or_more_space</string>
<string name="pref_key__markdown__monospace_some_parts" translatable="false">pref_key__markdown__monospace_some_parts</string>
<string name="pref_key__markdown__disable_code_block_highlight" translatable="false">pref_key__markdown__disable_code_block_highlight</string>
<string name="pref_key__markdown__auto_renumber_ordered_list" translatable="false">pref_key__markdown__auto_renumber_ordered_list</string>
<string name="pref_key__markdown__reorder_actions" translatable="false">pref_key__markdown__reorder_actions</string>
<string name="pref_key__todotxt__reorder_actions" translatable="false">pref_key__todotxt__reorder_actions</string>
Expand Down Expand Up @@ -182,6 +180,8 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__more_info__copy_build_information" translatable="false">pref_key__more_info__copy_build_information</string>
<string name="pref_key__editor_textaction_bar_item_padding" translatable="false">pref_key__editor_textaction_bar_item_padding</string>
<string name="pref_key__editor_disable_spelling_red_underline" translatable="false">pref_key__editor_disable_spelling_red_underline</string>
<string name="pref_key__highlight_code_monospace_font" translatable="false">pref_key__highlight_code_monospace_font</string>
<string name="pref_key__hightlight_code_block_disabled" translatable="false">pref_key__hightlight_code_block_disabled</string>
<string name="pref_key__editor_markdown_bigger_headings_2" translatable="false">pref_key__editor_markdown_bigger_headings_2</string>
<string name="pref_key__editor_unordered_list_character" translatable="false">pref_key__editor_unordered_list_character</string>
<string name="pref_key__recent_documents" translatable="false">pref_key__recent_documents</string>
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/res/xml/preferences_master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@
android:key="@string/pref_key__editor_disable_spelling_red_underline"
android:summary="@string/spellcheck_keyboard_suggestion_stay_red_underline_vanishes"
android:title="@string/disable_spelling_underline" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_code_black_24dp"
android:key="@string/pref_key__highlight_code_monospace_font"
android:summary="@string/use_different_fonttype_slow_down"
android:title="@string/use_monospace_for_code" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_code_black_24dp"
android:key="@string/pref_key__hightlight_code_block_disabled"
android:title="@string/disable_code_block_highlight" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/miscellaneous">
Expand Down Expand Up @@ -428,22 +439,11 @@
android:key="@string/pref_key__editor_markdown_bigger_headings_2"
android:summary="@string/increase_text_size_of_headings_according_to_level"
android:title="@string/bigger_headings" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_code_black_24dp"
android:key="@string/pref_key__markdown__monospace_some_parts"
android:summary="@string/use_different_fonttype_slow_down"
android:title="@string/use_monospace_for_code" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_baseline_keyboard_return_24"
android:key="@string/pref_key__markdown_newline_newparagraph"
android:title="@string/newline_is_new_paragraph" />
<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_code_black_24dp"
android:key="@string/pref_key__markdown__disable_code_block_highlight"
android:title="@string/disable_code_block_highlight" />
<!-- CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_format_list_numbered_black_24dp"
Expand Down

0 comments on commit 3bc417c

Please sign in to comment.