mirror of
https://github.com/tateisu/SubwayTooter
synced 2025-01-28 01:29:23 +01:00
misskeyでCW警告部分に同じメンションが複数回出現するバグを修正。シンタックスハイライトのバグ修正。
This commit is contained in:
parent
b262645afa
commit
9d5ec0a2dd
@ -37,7 +37,8 @@ object MisskeySyntaxHighlighter {
|
||||
}
|
||||
}
|
||||
|
||||
private val keywords = ArrayList<String>().apply {
|
||||
// 識別子に対して既存の名前と一致するか調べるようになったので、もはやソートの必要はない
|
||||
private val keywords = HashSet<String>().apply {
|
||||
|
||||
val _keywords = arrayOf(
|
||||
"true",
|
||||
@ -130,8 +131,7 @@ object MisskeySyntaxHighlighter {
|
||||
// Snake
|
||||
addAll(_keywords.map { k -> k[0].toUpperCase() + k.substring(1) })
|
||||
|
||||
// 長い順にソート
|
||||
sortWith(Comparator { a, b -> b.length - a.length })
|
||||
add("NaN")
|
||||
}
|
||||
|
||||
private class Token(
|
||||
@ -149,11 +149,10 @@ object MisskeySyntaxHighlighter {
|
||||
|
||||
private val reLineComment = Pattern.compile("""\A//.*""")
|
||||
private val reBlockComment = Pattern.compile("""\A/\*.*?\*/""", Pattern.DOTALL)
|
||||
private val reLabel = Pattern.compile("""\A@[A-Z_-][A-Z0-9_-]*?""", Pattern.CASE_INSENSITIVE)
|
||||
private val reNumber = Pattern.compile("""\A[+-]?[\d.]+""")
|
||||
private val reMethod =
|
||||
Pattern.compile("""\A([A-Z_][A-Z0-9_-]*?)\s*\(""", Pattern.CASE_INSENSITIVE)
|
||||
private val reProperty = Pattern.compile("""\A[a-zA-Z0-9_-]+""")
|
||||
private val reLabel = Pattern.compile("""\A@([A-Z_-][A-Z0-9_-]*)""", Pattern.CASE_INSENSITIVE)
|
||||
private val reKeyword =
|
||||
Pattern.compile("""\A([A-Z_-][A-Z0-9_-]*)([ \t]*\()?""", Pattern.CASE_INSENSITIVE)
|
||||
|
||||
private val elements = arrayOf(
|
||||
|
||||
@ -227,15 +226,25 @@ object MisskeySyntaxHighlighter {
|
||||
|
||||
// label
|
||||
{ env : Env ->
|
||||
// 直前に識別子があればNG
|
||||
val prev = if(env.pos <= 0) null else env.source[env.pos - 1]
|
||||
if(prev?.isLetterOrDigit() == true) return@arrayOf null
|
||||
|
||||
val match = reLabel.matcher(env.remain)
|
||||
if(! match.find()) return@arrayOf null
|
||||
Token(length = match.end(), color = 0xe9003f)
|
||||
|
||||
val end = match.end()
|
||||
when{
|
||||
// @user@host のように直後に@が続くのはNG
|
||||
env.remain.length > end && env.remain[end] =='@' -> null
|
||||
else->Token(length = match.end(), color = 0xe9003f)
|
||||
}
|
||||
},
|
||||
|
||||
// number
|
||||
{ env : Env ->
|
||||
val prev = if(env.pos <= 0) null else env.source[env.pos - 1]
|
||||
if(prev?.isLetter() == true) return@arrayOf null
|
||||
if(prev?.isLetterOrDigit() == true) return@arrayOf null
|
||||
val match = reNumber.matcher(env.remain)
|
||||
when {
|
||||
match.find() -> Token(length = match.end(), color = 0xae81ff)
|
||||
@ -243,56 +252,38 @@ object MisskeySyntaxHighlighter {
|
||||
}
|
||||
},
|
||||
|
||||
// nan
|
||||
// method, property, keyword
|
||||
{ env : Env ->
|
||||
// 直前の文字が識別子に使えるなら識別子の開始とはみなさない
|
||||
val prev = if(env.pos <= 0) null else env.source[env.pos - 1]
|
||||
if(prev?.isLetter() == true) return@arrayOf null
|
||||
if(prev?.isLetterOrDigit() == true || prev == '_') return@arrayOf null
|
||||
|
||||
val match = reKeyword.matcher(env.remain)
|
||||
if(! match.find()) return@arrayOf null
|
||||
val kw = match.group(1)
|
||||
val bracket = match.group(2)
|
||||
|
||||
when {
|
||||
env.remain.safeSubstring(3) == "NaN" ->
|
||||
Token(length = 3, color = 0xae81ff)
|
||||
else ->
|
||||
null
|
||||
}
|
||||
},
|
||||
// メソッド呼び出しは対照が変数かプロパティかに関わらずメソッドの色になる
|
||||
bracket?.isNotEmpty() == true ->
|
||||
Token(length = kw.length, color = 0x8964c1, italic = true)
|
||||
|
||||
// method
|
||||
{ env : Env ->
|
||||
val match = reMethod.matcher(env.remain)
|
||||
when {
|
||||
match.find() -> Token(length = match.end(), color = 0x8964c1, italic = true)
|
||||
else -> null
|
||||
}
|
||||
},
|
||||
// 変数や定数ではなくプロパティならプロパティの色になる
|
||||
prev == '.' ->Token(length = kw.length, color = 0xa71d5d)
|
||||
|
||||
// property
|
||||
{ env : Env ->
|
||||
val prev = if(env.pos <= 0) null else env.source[env.pos - 1]
|
||||
if(prev != '.') return@arrayOf null
|
||||
keywords.contains(kw) -> when(kw) {
|
||||
|
||||
val match = reProperty.matcher(env.remain)
|
||||
when {
|
||||
match.find() -> Token(length = match.end(), color = 0xa71d5d)
|
||||
else -> null
|
||||
}
|
||||
},
|
||||
|
||||
// keyword
|
||||
{ env : Env ->
|
||||
val prev = if(env.pos <= 0) null else env.source[env.pos - 1]
|
||||
if(prev?.isLetter() == true) return@arrayOf null
|
||||
|
||||
val match = keywords.find {
|
||||
env.remain.safeSubstring(it.length) == it
|
||||
} ?: return@arrayOf null
|
||||
|
||||
val kw = env.remain.safeSubstring(match.length)
|
||||
when(kw) {
|
||||
"true", "false", "null", "nil", "undefined" ->
|
||||
// 定数
|
||||
"true", "false", "null", "nil", "undefined" ,"NaN" ->
|
||||
Token(length = kw.length, color = 0xae81ff)
|
||||
else ->
|
||||
Token(length = kw.length, color = 0x2973b7)
|
||||
|
||||
// その他の予約語
|
||||
else ->Token(length = kw.length, color = 0x2973b7)
|
||||
}
|
||||
|
||||
// 強調表示しないが、識別子単位で読み飛ばす
|
||||
else -> Token(length = kw.length)
|
||||
}
|
||||
},
|
||||
|
||||
// symbol
|
||||
@ -404,6 +395,7 @@ object MisskeyMarkdownDecoder {
|
||||
, var pos : Int
|
||||
, var remain : String
|
||||
) {
|
||||
|
||||
internal fun genNode1(
|
||||
type : NodeType,
|
||||
sourceLength : Int,
|
||||
@ -431,7 +423,8 @@ object MisskeyMarkdownDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
private val reLink = Pattern.compile("""^\??\[([^\[\]]+?)]\((https?://[\w/:%#@${'$'}&?!()\[\]~.=+\-]+?)\)""")
|
||||
private val reLink =
|
||||
Pattern.compile("""^\??\[([^\[\]]+?)]\((https?://[\w/:%#@${'$'}&?!()\[\]~.=+\-]+?)\)""")
|
||||
|
||||
private val reCodeInline = Pattern.compile("""^`(.+?)`""")
|
||||
|
||||
@ -837,12 +830,17 @@ object MisskeyMarkdownDecoder {
|
||||
mentions = ArrayList()
|
||||
sb.mentions = mentions
|
||||
}
|
||||
mentions.add(TootMention(
|
||||
|
||||
if(mentions.find { it.acct == shortAcct } == null) {
|
||||
mentions.add(
|
||||
TootMention(
|
||||
EntityIdLong(- 1L)
|
||||
, userUrl
|
||||
, shortAcct
|
||||
, username
|
||||
))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
appendLink(
|
||||
when {
|
||||
|
Loading…
x
Reference in New Issue
Block a user