Comments (6)
it's working well. Thanks a lot!
Glad I could help.
from markwon.
use "font", example:
<font color="#7093DB">your text</font>
<font color="#7093DB" size="5">your text</font>
from markwon.
@ciouti I tried this but it didn't work.
This is my configuration for Markdown. Is there something missing?
return Markwon.builder(context)
.usePlugin(HtmlPlugin.create { plugin -> plugin.excludeDefaults(true) })
.usePlugin(CorePlugin.create())
.usePlugin(CoilImagesPlugin.create(context, coilImageLoader))
.usePlugin(MarkwonInlineParserPlugin.create())
.usePlugin(JLatexMathPlugin.create(binding.markdownTextView.textSize) { mathPluginBuilder ->
mathPluginBuilder.inlinesEnabled(true)
})
.usePlugin(StrikethroughPlugin.create())
.usePlugin(TablePlugin.create(context))
.usePlugin(TaskListPlugin.create(context))
.usePlugin(SimpleExtPlugin.create())
.usePlugin(LinkifyPlugin.create(linkifyMask))
.usePlugin(object : AbstractMarkwonPlugin() {
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
}
})
.build()
from markwon.
Sorry, I forgot this is my own extension of the code. Here is the code :
//HTML
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.addHandler(new FontTagHandler());
}))
FontTagHandler Class :
package utils.markwon;
import static utils.tool.StrUtils.patternStrArr;
import android.graphics.Color;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import io.noties.markwon.MarkwonVisitor;
import io.noties.markwon.html.HtmlTag;
import io.noties.markwon.html.MarkwonHtmlRenderer;
import io.noties.markwon.html.TagHandler;
public class FontTagHandler extends TagHandler {
private final int fontTextSize;
FontTagHandler() {
this.fontTextSize = 15;
}
private static double parsePositionSize(@Nullable String value) {
double position;
if (!TextUtils.isEmpty(value)) {
try {
position = Double.parseDouble(Objects.requireNonNull(value));
} catch (NumberFormatException e) {
e.printStackTrace();
position = 3;
}
} else {
position = 3;
}
return position;
}
private static String parsePositionColor(@Nullable String value) {
String position = "#000000";
if (!TextUtils.isEmpty(value)) {
try {
String[] positions = patternStrArr(Objects.requireNonNull(value), "^#{0,1}[a-fA-F\\d]{6}$");
if (positions != null) {
position = positions[0];
if (!position.startsWith("#")) {
position = String.format("%s%s", "#", position);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
return position;
}
@Override
public void handle(
@NonNull MarkwonVisitor visitor,
@NonNull MarkwonHtmlRenderer renderer,
@NonNull HtmlTag tag) {
//自定义文本大小 <font size="3">This is some text!</font>
final double size = parsePositionSize(tag.attributes().get("size"));
int setTextSize;
try {
if (size > 0) {
setTextSize = Double.valueOf(size * fontTextSize).intValue();
} else {
setTextSize = 3 * fontTextSize;
}
} catch (Exception exception) {
Log.e("MarkdownTAG", String.valueOf(exception));
setTextSize = 3 * fontTextSize;
}
visitor.builder().setSpan(
new AbsoluteSizeSpan(setTextSize),
tag.start(),
tag.end()
);
//自定义文本颜色 <font color="#000000">This is some text!</font>
final String color = parsePositionColor(tag.attributes().get("color"));
visitor.builder().setSpan(
new ForegroundColorSpan(Color.parseColor(color)),
tag.start(),
tag.end()
);
}
@NonNull
@NotNull
@Override
public Collection<String> supportedTags() {
return Collections.singleton("font");
}
}
patternStrArr code :
//正则匹配字符串
public static String[] patternStrArr(@NotNull String str, @NonNull String pattern_split) {
try {
final Pattern p = Pattern.compile(pattern_split);
final Matcher m = p.matcher(str);
ArrayList<String> tempList = new ArrayList<>();
String[] strArr;
while (m.find()) {
tempList.add(m.group());
}
if (tempList.size() > 0) {
strArr = arrListToStr(tempList);//匹配结果保存到strArr
return strArr;
} else {
return null;
}
} catch (Exception exception) {
Log.e("PatternTAG", String.valueOf(exception));
return null;
}
}
from markwon.
size = 3
This is closest to the size of normal text.
My code allows numeric values with fractional parts, but Typora or the browser doesn't support them.
from markwon.
it's working well. Thanks a lot!
from markwon.
Related Issues (20)
- [FR] How to indent images with list indents ?
- Asking questions HOT 1
- How can i change code block text color and background color? HOT 1
- How can i add background color for blockquotes?
- Can i change text align as justify?
- FeatureRequest: Jetpack Compose "native" support HOT 2
- display image from couchDb HOT 1
- Latex matrix not rendered when I enable R8/Progaurd HOT 3
- editor plugin doesn't highlight the '~' syntax
- If the width of the TextView is set to wrap_content, the table cannot be displayed.
- about MarkwonAdapter
- Custom plugin: Asynchronously change text
- Image covering content HOT 2
- How to escape German gender diversity "*" within words? (Without a special escape character!)
- How to disable ListItem (BulletList, OrderedList) HOT 1
- <strong> 解析不了
- Getting Started simple markdown doesn't work
- Color / underline for a text
- How to add vertical margin to an image? HOT 2
- Last paragraph has weird bottom margin
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markwon.