Merge branch 'master' of https://github.com/lbryio/lbry-android
This commit is contained in:
commit
c344b80e85
5 changed files with 36 additions and 21 deletions
|
@ -40,6 +40,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
@ -76,8 +77,12 @@ import com.google.android.material.button.MaterialButton;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import org.commonmark.node.Code;
|
||||
import org.commonmark.node.Node;
|
||||
import org.commonmark.parser.Parser;
|
||||
import org.commonmark.renderer.html.AttributeProvider;
|
||||
import org.commonmark.renderer.html.AttributeProviderContext;
|
||||
import org.commonmark.renderer.html.AttributeProviderFactory;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -2176,7 +2181,14 @@ public class FileViewFragment extends BaseFragment implements
|
|||
private String buildMarkdownHtml(String markdown) {
|
||||
Parser parser = Parser.builder().build();
|
||||
Node document = parser.parse(markdown);
|
||||
HtmlRenderer renderer = HtmlRenderer.builder().build();
|
||||
HtmlRenderer renderer = HtmlRenderer.builder()
|
||||
.attributeProviderFactory(new AttributeProviderFactory() {
|
||||
@Override
|
||||
public AttributeProvider create(AttributeProviderContext context) {
|
||||
return new CodeAttributeProvider();
|
||||
}
|
||||
})
|
||||
.build();
|
||||
String markdownHtml = renderer.render(document);
|
||||
|
||||
return "<!doctype html>\n" +
|
||||
|
@ -3204,4 +3216,20 @@ public class FileViewFragment extends BaseFragment implements
|
|||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
class CodeAttributeProvider implements AttributeProvider {
|
||||
|
||||
@Override
|
||||
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
|
||||
if (node instanceof Code) {
|
||||
Context context = getContext();
|
||||
String colorCodeText = "#".concat(Integer.toHexString(ContextCompat.getColor(context, R.color.codeTagText) & 0x00ffffff));
|
||||
String colorCodeBg = "#".concat(Integer.toHexString(ContextCompat.getColor(context, R.color.codeTagBackground) & 0x00ffffff));
|
||||
String codeStyle = "display: inline-block; border-radius: 0.2rem" +
|
||||
"; color: " + colorCodeText + "; background-color: " + colorCodeBg +
|
||||
"; font-size: 0.8571rem; padding: calc(2rem/5 - 4px) calc(2rem/5) calc(2rem/5 - 5px);";
|
||||
attributes.put("style", codeStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,4 +58,7 @@
|
|||
|
||||
<color name="caption">#CAEDB9</color>
|
||||
<color name="overlay">#CC333333</color>
|
||||
|
||||
<color name="codeTagText">#E8B692</color>
|
||||
<color name="codeTagBackground">#464B50</color>
|
||||
</resources>
|
|
@ -58,4 +58,7 @@
|
|||
|
||||
<color name="caption">#CAEDB9</color>
|
||||
<color name="overlay">#CC333333</color>
|
||||
|
||||
<color name="codeTagText">#2E3439</color>
|
||||
<color name="codeTagBackground">#D0E8FF</color>
|
||||
</resources>
|
|
@ -1,17 +0,0 @@
|
|||
package io.lbry.browser;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package io.lbry.browser.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class HelperTest extends TestCase {
|
||||
public class HelperTest {
|
||||
|
||||
}
|
Loading…
Reference in a new issue