Switched to AndDown for MarkDown processing for performance

This commit is contained in:
William Brawner 2017-07-29 12:42:13 -05:00
parent 61c6f8233f
commit 85b72b757c
3 changed files with 11 additions and 20 deletions

View file

@ -39,7 +39,7 @@ dependencies {
compile 'com.android.support:design:26.+' compile 'com.android.support:design:26.+'
compile 'com.jakewharton:butterknife:8.7.0' compile 'com.jakewharton:butterknife:8.7.0'
compile 'com.android.support:support-v4:26.+' compile 'com.android.support:support-v4:26.+'
compile 'com.vladsch.flexmark:flexmark-all:0.22.16' compile 'com.commonsware.cwac:anddown:0.3.0'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
} }

View file

@ -14,22 +14,12 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.WebView; import android.webkit.WebView;
import com.vladsch.flexmark.ast.Node; import com.commonsware.cwac.anddown.AndDown;
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.parser.ParserEmulationProfile;
import com.vladsch.flexmark.util.options.MutableDataHolder;
import com.vladsch.flexmark.util.options.MutableDataSet;
import java.util.Arrays;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -100,20 +90,18 @@ public class PreviewFragment extends Fragment {
Thread setMarkdown = new Thread() { Thread setMarkdown = new Thread() {
@Override @Override
public void run() { public void run() {
MutableDataHolder options = new MutableDataSet(); AndDown andDown = new AndDown();
options.setFrom(ParserEmulationProfile.MARKDOWN); int hoedownFlags =
options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create())); AndDown.HOEDOWN_EXT_STRIKETHROUGH | AndDown.HOEDOWN_EXT_TABLES |
Parser parser = Parser.builder(options).build(); AndDown.HOEDOWN_EXT_UNDERLINE | AndDown.HOEDOWN_EXT_SUPERSCRIPT;
Node document = parser.parse(iText); String html = andDown.markdownToHtml(iText, hoedownFlags, 0);
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
String html = renderer.render(document);
mMarkdownView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null); mMarkdownView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
timeoutActive = false; timeoutActive = false;
} }
}; };
if (!timeoutActive) { if (!timeoutActive) {
timeoutActive = true; timeoutActive = true;
handler.postDelayed(setMarkdown, 50); handler.postDelayed(setMarkdown, 0);
} }
} }
} }

View file

@ -15,6 +15,9 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
jcenter() jcenter()
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
} }
} }