Skip to content

Commit

Permalink
Auto padding of code blocks (PR #2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
guanglinn authored Dec 3, 2023
1 parent c41e4d0 commit 1fb8f83
Show file tree
Hide file tree
Showing 36 changed files with 179 additions and 185 deletions.
26 changes: 13 additions & 13 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ Where:
* **[Dugite Code](https://github.com/dugite-code)**<br/>~° Artwork
* **[billchenchina](https://github.com/billchenchina)**<br/>~° Simplified Chinese translation
* **[Kanthi Subramanian](https://github.com/subkanthi)**<br/>~° File Info Dialog
* **[Emanuele Petriglia](https://github.com/ema-pe)**<br>~° Italian translation
* **[Emanuele Petriglia](https://github.com/ema-pe)**<br/>~° Italian translation
* **[Tiago Danin](https://tiagodanin.github.io)**<br/>~° Brazilian Portuguese translation
* **[Jesica Chu](https://github.com/jesicachu)**<br/>~° Spanish and Traiditonal Chinese translation
* **[Ankush S Shetkar](https://www.linkedin.com/in/livelycoder/)**<br/>~° Added Chrome custom tabs for urls
* **[Lars Pontoppidan](https://github.com/larpon)**<br/>~° Danish translation
* **[Amaya Lim](https://github.com/nightrainlily)**<br/>~° Improve project description
* **[Jawkwon Im](https://github.com/jakeoneijk)**<br/>~° Add keep screen on
* **[Amaya Lim](https://github.com/nightrainlily)**<br/>~° Improved project description
* **[Jawkwon Im](https://github.com/jakeoneijk)**<br/>~° Added keep screen on
* **[Mark Goldman](https://github.com/goldmanm)**<br/>~° Added sorting for todo.txt, improved wiki
* **[natanelho]([email protected])**<br/>~° Hebrew translation
* **[Alexander Sachse]([email protected])**<br/>~° Added simple word counter
* **[Kyle Phelps]([email protected])**<br/>~° Added functionality to share multiple files from file browser
* **[Vladislav Glinsky](https://github.com/cl0ne)**<br/>~° Ukrainian/Russian translations
* **[David Hebbeker](https://david.hebbeker.info/)**<br/>~° Added tooltips for text actions.
* **[Harshad Srinivasan](https://github.com/harshad1)**<br/>~° Added functionality to handle leading spaces in lists.
* **[Niels](https://stackoverflow.com/users/432115/niels)**<br>~° Added encryption for textfile contents.
* **[Helguli](https://github.com/Helguli)**<br>~° Added fast scroll to editor.
* **[Patricia Heimfarth](https://github.com/PatriciaHeimfarth)**<br>~° Added checkbox for todo completion date
* **[Peter Schwede](https://github.com/pschwede)**<br>~° Added Zim-Wiki support.
* **[Frederic Jacob](https://github.com/fredericjacob)**<br>~° Added Zim-Wiki highlighting, text actions, view mode, page creation.
* **[Winston Feng](https://github.com/tifish)**<br>~° Support spaces in URL.
* **[k3b](https://github.com/k3b)**<br>~° Added CSV-Support.
* **[Ayowel](https://github.com/ayowel)**<br>~° Mermaid update.
* **[David Hebbeker](https://david.hebbeker.info/)**<br/>~° Added tooltips for text actions
* **[Harshad Srinivasan](https://github.com/harshad1)**<br/>~° Added functionality to handle leading spaces in lists
* **[Niels](https://stackoverflow.com/users/432115/niels)**<br/>~° Added encryption for textfile contents
* **[Helguli](https://github.com/Helguli)**<br/>~° Added fast scroll to editor
* **[Patricia Heimfarth](https://github.com/PatriciaHeimfarth)**<br/>~° Added checkbox for todo completion date
* **[Peter Schwede](https://github.com/pschwede)**<br/>~° Added Zim-Wiki support
* **[Frederic Jacob](https://github.com/fredericjacob)**<br/>~° Added Zim-Wiki highlighting, text actions, view mode, page creation
* **[Winston Feng](https://github.com/tifish)**<br/>~° Support spaces in URL
* **[k3b](https://github.com/k3b)**<br/>~° Added CSV-Support
* **[Li Guanglin](https://github.com/guanglinn)**<br/>~° Added line numbers support
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MarkdownSyntaxHighlighter extends SyntaxHighlighterBase {
private static final int MD_COLOR_LINK = 0xff1ea3fe;
private static final int MD_COLOR_LIST = 0xffdaa521;
private static final int MD_COLOR_QUOTE = 0xff88b04c;
private static final int MD_COLOR_CODEBLOCK = 0xff8c8c8c;
private static final int MD_COLOR_CODEBLOCK = 0x448c8c8c;

public MarkdownSyntaxHighlighter(AppSettings as) {
super(as);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

import other.com.vladsch.flexmark.ext.katex.FlexmarkKatexExtension;
import other.de.stanetz.jpencconverter.JavaPasswordbasedCryption;
import other.flexmark.ext.codeblocks.LineNumbersExtension;

@SuppressWarnings({"unchecked", "WeakerAccess"})
public class MarkdownTextConverter extends TextConverterBase {
Expand Down Expand Up @@ -83,7 +82,7 @@ public class MarkdownTextConverter extends TextConverterBase {
//########################
//## Injected CSS / JS / HTML
//########################
public static final String CSS_BODY = CSS_S + "body{margin:0;padding:2.5vw}" + CSS_E;
public static final String CSS_BODY = CSS_S + "body{margin:0;padding:1.25vh 2.5vw}" + CSS_E;
public static final String CSS_HEADER_UNDERLINE = CSS_S + " .header_no_underline { text-decoration: none; color: " + TOKEN_BW_INVERSE_OF_THEME + "; } h1 < a.header_no_underline { border-bottom: 2px solid #eaecef; } " + CSS_E;
public static final String CSS_H1_H2_UNDERLINE = CSS_S + " h1,h2 { border-bottom: 2px solid " + TOKEN_BW_INVERSE_OF_THEME_HEADER_UNDERLINE + "; } " + CSS_E;
public static final String CSS_BLOCKQUOTE_VERTICAL_LINE = CSS_S + "blockquote{padding:0px 14px;border-" + TOKEN_TEXT_DIRECTION + ":3.5px solid #dddddd;margin:4px 0}" + CSS_E;
Expand Down Expand Up @@ -158,28 +157,22 @@ public class MarkdownTextConverter extends TextConverterBase {
//########################

@Override
public String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file) {
public String convertMarkup(String markup, Context context, boolean lightMode, boolean enableLineNumbers, File file) {
String converted = "", onLoadJs = "", head = "";

final MutableDataSet options = new MutableDataSet();

if (lineNum) {
// Add code blocks Line numbers extension
final ArrayList<Extension> extensions = new ArrayList<>(flexmarkExtensions);
extensions.add(LineNumbersExtension.create());
options.set(Parser.EXTENSIONS, extensions);
} else {
options.set(Parser.EXTENSIONS, flexmarkExtensions);
}
options.set(Parser.EXTENSIONS, flexmarkExtensions);

options.set(Parser.SPACE_IN_LINK_URLS, true); // allow links like [this](some filename with spaces.md)
//options.set(HtmlRenderer.SOFT_BREAK, "<br />\n"); // Add linefeed to html break

// options.set(HtmlRenderer.SOFT_BREAK, "<br />\n"); // Add linefeed to HTML break

options.set(EmojiExtension.USE_IMAGE_TYPE, EmojiImageType.UNICODE_ONLY); // Use unicode (OS/browser images)

// GitLab extension
options.set(GitLabExtension.RENDER_BLOCK_MATH, false);

// gfm table parsing
// GFM table parsing
options.set(TablesExtension.WITH_CAPTION, false)
.set(TablesExtension.COLUMN_SPANS, true)
.set(TablesExtension.MIN_HEADER_ROWS, 0)
Expand Down Expand Up @@ -276,7 +269,7 @@ public String convertMarkup(String markup, Context context, boolean lightMode, b
}

// Enable View (block) code syntax highlighting
head += getViewHlPrismIncludes(GsContextUtils.instance.isDarkModeEnabled(context) ? "-tomorrow" : "", lineNum);
head += getViewHlPrismIncludes(GsContextUtils.instance.isDarkModeEnabled(context) ? "-tomorrow" : "", enableLineNumbers);

// Jekyll: Replace {{ site.baseurl }} with ..--> usually used in Jekyll blog _posts folder which is one folder below repository root, for reference to e.g. pictures in assets folder
markup = markup.replace("{{ site.baseurl }}", "..").replace(TOKEN_SITE_DATE_JEKYLL, TOKEN_POST_TODAY_DATE);
Expand Down Expand Up @@ -323,6 +316,15 @@ public String convertMarkup(String markup, Context context, boolean lightMode, b
}
}

if (_appSettings.getDocumentWrapState(file.getAbsolutePath())) {
onLoadJs += "wrapCodeBlockWords();";
}

if (enableLineNumbers) {
// For Prism line numbers plugin
onLoadJs += "enableLineNumbers();adjustLineNumbers();";
}

// Deliver result
return putContentIntoTemplate(context, converted, lightMode, file, onLoadJs, head);
}
Expand Down Expand Up @@ -360,18 +362,22 @@ private String escapeSpacesInLink(final String markup) {
}

@SuppressWarnings({"StringConcatenationInsideStringBufferAppend"})
private String getViewHlPrismIncludes(final String themeName, final boolean lineNum) {
private String getViewHlPrismIncludes(final String themeName, final boolean enableLineNumbers) {
final StringBuilder sb = new StringBuilder(1000);
sb.append(CSS_PREFIX + "prism/themes/prism" + themeName + ".min.css" + CSS_POSTFIX);
sb.append(CSS_PREFIX + "prism/style.css" + CSS_POSTFIX);
sb.append(JS_PREFIX + "prism/prism.js" + JS_POSTFIX);
sb.append(JS_PREFIX + "prism/plugins/autoloader/prism-autoloader.min.js" + JS_POSTFIX);
sb.append(JS_PREFIX + "prism/main.js" + JS_POSTFIX);

if (lineNum) {
sb.append(CSS_PREFIX + "prism/plugins/line-numbers/prism-line-numbers.css" + CSS_POSTFIX);
if (enableLineNumbers) {
sb.append(CSS_PREFIX + "prism/plugins/line-numbers/style.css" + CSS_POSTFIX);
sb.append(JS_PREFIX + "prism/plugins/line-numbers/prism-line-numbers.min.js" + JS_POSTFIX);
sb.append(JS_PREFIX + "prism/plugins/line-numbers/main.js" + JS_POSTFIX);
}
sb.append("\n");

return sb.append("\n").toString();
return sb.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ static class LineNumbersDrawer {
private final Paint _paint = new Paint();

private final int _defaultPaddingLeft;
private static final int LINE_NUMBER_PADDING_LEFT = 12;
private static final int LINE_NUMBER_PADDING_RIGHT = 10;
private static final int LINE_NUMBER_PADDING_LEFT = 20;
private static final int LINE_NUMBER_PADDING_RIGHT = 12;

private final Rect _visibleArea = new Rect();
private final Rect _lineNumbersArea = new Rect();
Expand Down Expand Up @@ -579,7 +579,7 @@ public void draw(final Canvas canvas) {
if (isTextSizeChanged() || isMaxNumberDigitsChanged()) {
_numberX = LINE_NUMBER_PADDING_LEFT + (int) _paint.measureText(String.valueOf(_maxNumber));
_gutterX = _numberX + LINE_NUMBER_PADDING_RIGHT;
_editor.setPadding(_gutterX + 10, _editor.getPaddingTop(), _editor.getPaddingRight(), _editor.getPaddingBottom());
_editor.setPadding(_gutterX + 12, _editor.getPaddingTop(), _editor.getPaddingRight(), _editor.getPaddingBottom());
}

int i = _startLine[0], number = _startLine[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public boolean isFileBrowserFilterShowDotFiles() {
}

public boolean isShowSettingsOptionInMainToolbar() {
return true;//getBool(R.string.pref_key__show_settings_option_in_main_toolbar, true);
return false; // getBool(R.string.pref_key__show_settings_option_in_main_toolbar, true);
}

public boolean isHighlightingHexColorEnabled() {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/drawable/ic_line_numbers_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="32"
android:viewportHeight="32">
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,26h20v4h-20zM12,14h20v4h-20zM12,2h20v4h-20zM6,0v8h-2v-6h-2v-2zM4,16.438v1.563h4v2h-6v-4.563l4,-1.875v-1.563h-4v-2h6v4.563zM8,22v10h-6v-2h4v-2h-4v-2h4v-2h-4v-2z" />
android:pathData="M9,17.938L21,17.938v2.375L9,20.313ZM9,10.813L21,10.813v2.375L9,13.188ZM9,3.688L21,3.688L21,6.063L9,6.063ZM5.4,2.5L5.4,7.25L4.2,7.25L4.2,3.687L3,3.687L3,2.5ZM4.2,12.26v0.928h2.4v1.188L3,14.376v-2.709L5.4,10.553L5.4,9.625L3,9.625L3,8.438h3.6v2.709zM6.6,15.563L6.6,21.5L3,21.5v-1.187h2.4v-1.188L3,19.125v-1.188L5.4,17.938L5.4,16.75L3,16.75v-1.188z"
android:strokeWidth="0.596867" />
</vector>
4 changes: 1 addition & 3 deletions app/src/main/res/raw/licenses_3rd_party.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* asciidoctor.js
~° Copyright asciidoctor.js authors

asciidoctor-skins
* asciidoctor-skins
~° Copyright asciidoctor-skins authors

* flexmark-ext-prism-linenumber
~° Copyright Tom Misawa

`---------------`
<small>Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Empty file.
1 change: 1 addition & 0 deletions app/thirdparty/assets/prism/components/prism-batch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1fb8f83

Please sign in to comment.