Skip to content

Commit

Permalink
Markdown: Individual table of contents level options (PR #1427 by @fr…
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericjacob committed Sep 9, 2021
1 parent 129f07e commit 2005fa4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
Expand Up @@ -180,7 +180,7 @@ public String convertMarkup(String markup, Context context, boolean isExportInLi
}

head += CSS_TOC_STYLE;
options.set(TocExtension.LEVELS, TocOptions.getLevels(1, 2, 3))
options.set(TocExtension.LEVELS, TocOptions.getLevels(appSettings.getMarkdownTableOfContentLevels()))
.set(TocExtension.TITLE, context.getString(R.string.table_of_contents))
.set(TocExtension.DIV_CLASS, "markor-table-of-contents")
.set(TocExtension.LIST_CLASS, "markor-table-of-contents-list")
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/net/gsantner/markor/util/AppSettings.java
Expand Up @@ -197,7 +197,16 @@ public boolean isMarkdownNewlineNewparagraphEnabled() {
}

public boolean isMarkdownTableOfContentsEnabled() {
return getBool(R.string.pref_key__markdown_show_toc, false);
return getMarkdownTableOfContentLevels().length > 0;
}

public int[] getMarkdownTableOfContentLevels() {
final List<String> v = getStringSet(R.string.pref_key__markdown_table_of_contents_enabled_levels, Collections.emptyList());
int[] ret = new int[v.size()];
for (int i = 0; i < v.size(); i++) {
ret[i] = Integer.parseInt(v.get(i));
}
return ret;
}

public boolean isEditorStatusBarHidden() {
Expand Down
Expand Up @@ -48,6 +48,7 @@ public boolean isAppCurrentVersionFirstStart(boolean doSet) {
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List;


Expand Down Expand Up @@ -444,6 +445,18 @@ public boolean getBool(String key, boolean defaultValue, final SharedPreferences
}
}

public List<String> getStringSet(@StringRes int keyResourceId, List<String> defaultValue, final SharedPreferences... pref) {
return getStringSet(rstr(keyResourceId), defaultValue);
}

public List<String> getStringSet(String key, List<String> defaultValue, final SharedPreferences... pref) {
try {
return new ArrayList<>(gp(pref).getStringSet(key, new HashSet<>(defaultValue)));
} catch (ClassCastException e) {
return defaultValue;
}
}

//
// Getter & Setter for Color
//
Expand Down Expand Up @@ -478,6 +491,10 @@ public boolean getBool(String key, boolean defaultValue) {
return getBool(key, defaultValue, _prefApp);
}

public List<String> getStringSet(String key, List<String> defaultValue) {
return getStringSet(key, defaultValue, _prefApp);
}

@Override
public float getFloat(String key, float defaultValue) {
return getFloat(key, defaultValue, _prefApp);
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/values/arrays.xml
Expand Up @@ -124,4 +124,21 @@
<item translatable="false">*</item>
<item translatable="false">+</item>
</string-array>

<string-array name="pref_arrdisp__markdown_toc" translatable="false">
<item translatable="false">@string/heading_1</item>
<item translatable="false">@string/heading_2</item>
<item translatable="false">@string/heading_3</item>
<item translatable="false">@string/heading_4</item>
<item translatable="false">@string/heading_5</item>
<item translatable="false">@string/heading_6</item>
</string-array>
<string-array name="arr_one_to_six" translatable="false">
<item translatable="false">1</item>
<item translatable="false">2</item>
<item translatable="false">3</item>
<item translatable="false">4</item>
<item translatable="false">5</item>
<item translatable="false">6</item>
</string-array>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/string-not_translatable.xml
Expand Up @@ -192,7 +192,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__inject_to_body" translatable="false">pref_key__inject_to_body</string>
<string name="pref_key__markdown_render_math" translatable="false">pref_key__markdown_render_math</string>
<string name="pref_key__markdown_newline_newparagraph" translatable="false">pref_key__markdown_newline_newparagraph</string>
<string name="pref_key__markdown_show_toc" translatable="false">pref_key__markdown_show_toc</string>
<string name="pref_key__markdown_table_of_contents_enabled_levels" translatable="false">pref_key__markdown_table_of_contents_enabled_levels</string>
<string name="pref_key__is_launcher_for_special_files_enabled" translatable="false">pref_key__is_launcher_for_special_files_enabled</string>
<string name="pref_key__editor_basic_color_scheme__bg_light" translatable="false">pref_key__editor_basic_color_scheme__bg_light</string>
<string name="pref_key__editor_basic_color_scheme__fg_light" translatable="false">pref_key__editor_basic_color_scheme__fg_light</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -360,6 +360,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="heading_3">Heading 3</string>
<string name="heading_4">Heading 4</string>
<string name="heading_5">Heading 5</string>
<string name="heading_6">Heading 6</string>
<string name="bold">Bold</string>
<string name="italic">Italic</string>
<string name="highlighted">Highlighted</string>
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/xml/preferences_master.xml
Expand Up @@ -458,11 +458,12 @@
android:key="@string/pref_key__markdown_render_math"
android:summary="@string/katex_latex"
android:title="@string/math" />
<CheckBoxPreference
android:defaultValue="false"
<MultiSelectListPreference android:title="@string/table_of_contents"
android:dialogTitle="@string/table_of_contents"
android:entries="@array/pref_arrdisp__markdown_toc"
android:entryValues="@array/arr_one_to_six"
android:icon="@drawable/ic_list_black_24dp"
android:key="@string/pref_key__markdown_show_toc"
android:title="@string/table_of_contents" />
android:key="@string/pref_key__markdown_table_of_contents_enabled_levels" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/textactions">
<Preference
Expand Down

0 comments on commit 2005fa4

Please sign in to comment.