mirror of
https://github.com/element-hq/element-android
synced 2024-12-21 16:55:06 +03:00
Gate LaTeX maths behind labs flag
This commit is contained in:
parent
4c45a69129
commit
2262cd4b6d
4 changed files with 33 additions and 15 deletions
|
@ -20,6 +20,7 @@ import android.content.Context
|
|||
import android.text.Spannable
|
||||
import androidx.core.text.toSpannable
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import io.noties.markwon.AbstractMarkwonPlugin
|
||||
import io.noties.markwon.Markwon
|
||||
import io.noties.markwon.MarkwonPlugin
|
||||
|
@ -34,14 +35,18 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
class EventHtmlRenderer @Inject constructor(htmlConfigure: MatrixHtmlPluginConfigure,
|
||||
context: Context) {
|
||||
context: Context,
|
||||
private val vectorPreferences: VectorPreferences) {
|
||||
|
||||
interface PostProcessor {
|
||||
fun afterRender(renderedText: Spannable)
|
||||
}
|
||||
|
||||
private val markwon = Markwon.builder(context)
|
||||
private val builder = Markwon.builder(context)
|
||||
.usePlugin(HtmlPlugin.create(htmlConfigure))
|
||||
|
||||
private val markwon = if (vectorPreferences.latexMathsIsEnabled()) {
|
||||
builder
|
||||
.usePlugin(object : AbstractMarkwonPlugin() { // Markwon expects maths to be in a specific format: https://noties.io/Markwon/docs/v4/ext-latex
|
||||
override fun processMarkdown(markdown: String): String {
|
||||
return markdown
|
||||
|
@ -54,7 +59,9 @@ class EventHtmlRenderer @Inject constructor(htmlConfigure: MatrixHtmlPluginConfi
|
|||
builder.inlinesEnabled(true)
|
||||
builder.theme().inlinePadding(JLatexMathTheme.Padding.symmetric(24, 8))
|
||||
})
|
||||
.build()
|
||||
} else {
|
||||
builder
|
||||
}.build()
|
||||
|
||||
val plugins: List<MarkwonPlugin> = markwon.plugins
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
private const val SETTINGS_SEND_MESSAGE_WITH_ENTER = "SETTINGS_SEND_MESSAGE_WITH_ENTER"
|
||||
private const val SETTINGS_ENABLE_CHAT_EFFECTS = "SETTINGS_ENABLE_CHAT_EFFECTS"
|
||||
private const val SETTINGS_SHOW_EMOJI_KEYBOARD = "SETTINGS_SHOW_EMOJI_KEYBOARD"
|
||||
private const val SETTINGS_LABS_ENABLE_LATEX_MATHS = "SETTINGS_LABS_ENABLE_LATEX_MATHS"
|
||||
|
||||
// Room directory
|
||||
private const val SETTINGS_ROOM_DIRECTORY_SHOW_ALL_PUBLIC_ROOMS = "SETTINGS_ROOM_DIRECTORY_SHOW_ALL_PUBLIC_ROOMS"
|
||||
|
@ -337,6 +338,10 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
return defaultPrefs.getBoolean(SETTINGS_LABS_UNREAD_NOTIFICATIONS_AS_TAB, false)
|
||||
}
|
||||
|
||||
fun latexMathsIsEnabled(): Boolean {
|
||||
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_LATEX_MATHS, false)
|
||||
}
|
||||
|
||||
fun failFast(): Boolean {
|
||||
return BuildConfig.DEBUG || (developerMode() && defaultPrefs.getBoolean(SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY, false))
|
||||
}
|
||||
|
|
|
@ -3595,4 +3595,5 @@
|
|||
<string name="link_this_email_settings_link">Link this email with your account</string>
|
||||
<!-- %s will be replaced by the value of link_this_email_settings_link and styled as a link -->
|
||||
<string name="link_this_email_with_your_account">%s in Settings to receive invites directly in Element.</string>
|
||||
<string name="labs_enable_latex_maths">Enable LaTeX mathematics</string>
|
||||
</resources>
|
||||
|
|
|
@ -50,6 +50,11 @@
|
|||
android:key="SETTINGS_LABS_USE_RESTRICTED_JOIN_RULE"
|
||||
android:title="@string/labs_use_restricted_join_rule"
|
||||
android:summary="@string/labs_use_restricted_join_rule_desc"/>
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="SETTINGS_LABS_ENABLE_LATEX_MATHS"
|
||||
android:title="@string/labs_enable_latex_maths"/>
|
||||
<!--</im.vector.app.core.preference.VectorPreferenceCategory>-->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue