-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from urakalee/origin
支持 kotlin, 使用 DayOne 模式的标签操作
- Loading branch information
Showing
24 changed files
with
566 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-Xjvm-default=enable | ||
|
||
androidPluginVersion=3.0.1 | ||
kotlinVersion=1.2.50 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.urakalee.markdown | ||
|
||
/** | ||
* @author Uraka.Lee | ||
*/ | ||
class Indent constructor(c: String?) { | ||
|
||
var indent: Boolean = !c.isNullOrEmpty() | ||
private set | ||
var content: String = c ?: "" | ||
private set | ||
val length: Int | ||
get() = content.length | ||
private val equivalentLength: Int | ||
get() { | ||
var l = 0 | ||
for (c in content) { | ||
if (c == ' ') { | ||
l += 1 | ||
} else if (c == '\t') { | ||
val rem = l.rem(TAB_SIZE) | ||
l += TAB_SIZE - rem | ||
} | ||
|
||
} | ||
return l | ||
} | ||
var level: Int = 0 | ||
|
||
fun indent(): Indent { | ||
var l = equivalentLength | ||
val rem = l.rem(TAB_SIZE) | ||
l += TAB_SIZE - rem | ||
content = " ".repeat(l) | ||
indent = true | ||
return this | ||
} | ||
|
||
fun dedent(): Indent { | ||
if (!indent) return this | ||
var l = equivalentLength | ||
val rem = l.rem(TAB_SIZE) | ||
l -= if (rem == 0) { | ||
TAB_SIZE | ||
} else { | ||
rem | ||
} | ||
content = " ".repeat(l) | ||
indent = content.isNotEmpty() | ||
return this | ||
} | ||
|
||
companion object { | ||
|
||
val TAB_SIZE = 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package me.urakalee.markdown | ||
|
||
import me.urakalee.markdown.handler.* | ||
|
||
/** | ||
* @author Uraka.Lee | ||
*/ | ||
enum class Mark(val pattern: Regex, val defaultMark: String, val handler: MarkHandler) { | ||
|
||
NONE(Regex(""), "", NoneHandler), | ||
H(Regex("#+"), "#", HeaderHandler), | ||
LI(Regex("[-*]"), "-", ListHandler), | ||
LO(Regex("\\d\\."), "1.", ListHandler), | ||
LA(Regex("[a-z]\\."), "a.", ListHandler), | ||
TD(Regex("- \\[[x ]]", RegexOption.IGNORE_CASE), "- [ ]", TodoHandler), | ||
QT(Regex(">"), ">", QuoteHandler); | ||
|
||
companion object { | ||
|
||
private fun fromString(s: String): Mark { | ||
return values().firstOrNull { | ||
s.matches(it.pattern) | ||
} ?: NONE | ||
} | ||
|
||
fun handle(inputMark: Mark, source: String): String { | ||
return Mark.fromString(source).let { | ||
it.handler.handleMark(inputMark, source, it) | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
markdown/src/main/java/me/urakalee/markdown/MarkHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package me.urakalee.markdown | ||
|
||
/** | ||
* @author Uraka.Lee | ||
*/ | ||
interface MarkHandler { | ||
|
||
/** | ||
* @return targetMark on input [Mark.H] | ||
*/ | ||
fun handleHeader(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return defaultMark(inputMark) | ||
} | ||
|
||
/** | ||
* @return targetMark on input [Mark.LI] | ||
*/ | ||
fun handleList(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return defaultMark(inputMark) | ||
} | ||
|
||
/** | ||
* @return targetMark on input [Mark.TD] | ||
*/ | ||
fun handleTodo(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return defaultMark(inputMark) | ||
} | ||
|
||
/** | ||
* @return targetMark on input [Mark.QT] | ||
*/ | ||
fun handleQuote(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return defaultMark(inputMark) | ||
} | ||
|
||
private fun defaultMark(mark: Mark): String { | ||
return mark.defaultMark | ||
} | ||
|
||
/** | ||
* @return targetMark | ||
*/ | ||
fun handleMark(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return when (inputMark) { | ||
Mark.H -> handleHeader(inputMark, source, sourceMark) | ||
Mark.LI -> handleList(inputMark, source, sourceMark) | ||
Mark.TD -> handleTodo(inputMark, source, sourceMark) | ||
Mark.QT -> handleQuote(inputMark, source, sourceMark) | ||
else -> source | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
markdown/src/main/java/me/urakalee/markdown/handler/HeaderHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.urakalee.markdown.handler | ||
|
||
import me.urakalee.markdown.Mark | ||
import me.urakalee.markdown.MarkHandler | ||
|
||
/** | ||
* @author Uraka.Lee | ||
*/ | ||
object HeaderHandler : MarkHandler { | ||
|
||
override fun handleHeader(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return if (source.length < 6) "$source${Mark.H.defaultMark}" else Mark.H.defaultMark | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
markdown/src/main/java/me/urakalee/markdown/handler/ListHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.urakalee.markdown.handler | ||
|
||
import me.urakalee.markdown.Mark | ||
import me.urakalee.markdown.MarkHandler | ||
|
||
/** | ||
* @author Uraka.Lee | ||
*/ | ||
object ListHandler : MarkHandler { | ||
|
||
override fun handleList(inputMark: Mark, source: String, sourceMark: Mark): String { | ||
return when (sourceMark) { | ||
Mark.LI -> { | ||
Mark.LO.defaultMark | ||
} | ||
Mark.LO -> { | ||
Mark.LA.defaultMark | ||
} | ||
Mark.LA -> { | ||
Mark.LI.defaultMark | ||
} | ||
else -> { | ||
super.handleList(inputMark, source, sourceMark) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.