mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 18:05:50 +01:00
Remove extension point to add text decorators. We need more consideration.
This commit is contained in:
@@ -149,16 +149,6 @@ abstract class Plugin {
|
|||||||
*/
|
*/
|
||||||
def dashboardTabs(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Context) => Option[Link]] = Nil
|
def dashboardTabs(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Context) => Option[Link]] = Nil
|
||||||
|
|
||||||
/**
|
|
||||||
* Override to add text decorators.
|
|
||||||
*/
|
|
||||||
val textDecorators: Seq[TextDecorator] = Nil
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override to add text decorators.
|
|
||||||
*/
|
|
||||||
def textDecorators(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[TextDecorator] = Nil
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is invoked in initialization of plugin system.
|
* This method is invoked in initialization of plugin system.
|
||||||
* Register plugin functionality to PluginRegistry.
|
* Register plugin functionality to PluginRegistry.
|
||||||
@@ -203,9 +193,6 @@ abstract class Plugin {
|
|||||||
(dashboardTabs ++ dashboardTabs(registry, context, settings)).foreach { dashboardTab =>
|
(dashboardTabs ++ dashboardTabs(registry, context, settings)).foreach { dashboardTab =>
|
||||||
registry.addDashboardTab(dashboardTab)
|
registry.addDashboardTab(dashboardTab)
|
||||||
}
|
}
|
||||||
(textDecorators ++ textDecorators(registry, context, settings)).foreach { textDecorator =>
|
|
||||||
registry.addTextDecorator(textDecorator)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ class PluginRegistry {
|
|||||||
private val systemSettingMenus = new ListBuffer[(Context) => Option[Link]]
|
private val systemSettingMenus = new ListBuffer[(Context) => Option[Link]]
|
||||||
private val accountSettingMenus = new ListBuffer[(Context) => Option[Link]]
|
private val accountSettingMenus = new ListBuffer[(Context) => Option[Link]]
|
||||||
private val dashboardTabs = new ListBuffer[(Context) => Option[Link]]
|
private val dashboardTabs = new ListBuffer[(Context) => Option[Link]]
|
||||||
private val textDecorators = new ListBuffer[TextDecorator]
|
|
||||||
textDecorators += new EmojiDecorator()
|
|
||||||
|
|
||||||
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
||||||
plugins += pluginInfo
|
plugins += pluginInfo
|
||||||
@@ -161,12 +159,6 @@ class PluginRegistry {
|
|||||||
|
|
||||||
def getDashboardTabs: Seq[(Context) => Option[Link]] = dashboardTabs.toSeq
|
def getDashboardTabs: Seq[(Context) => Option[Link]] = dashboardTabs.toSeq
|
||||||
|
|
||||||
def addTextDecorator(textDecorator: TextDecorator): Unit = {
|
|
||||||
textDecorators += textDecorator
|
|
||||||
}
|
|
||||||
|
|
||||||
def getTextDecorators: Seq[TextDecorator] = textDecorators.toSeq
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package gitbucket.core.plugin
|
|
||||||
|
|
||||||
import gitbucket.core.controller.Context
|
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
|
||||||
import gitbucket.core.util.EmojiUtil
|
|
||||||
|
|
||||||
trait TextDecorator {
|
|
||||||
|
|
||||||
def decorate(text: String)(implicit context: Context): String
|
|
||||||
|
|
||||||
def decorate(text: String, repositoryInfo: RepositoryInfo)(implicit context: Context): String = decorate(text)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class EmojiDecorator extends TextDecorator {
|
|
||||||
|
|
||||||
override def decorate(text: String)(implicit context: Context): String = EmojiUtil.convertEmojis(text)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ object Markdown {
|
|||||||
val renderer = new GitBucketMarkedRenderer(options, repository,
|
val renderer = new GitBucketMarkedRenderer(options, repository,
|
||||||
enableWikiLink, enableRefsLink, enableAnchor, enableTaskList, hasWritePermission, pages)
|
enableWikiLink, enableRefsLink, enableAnchor, enableTaskList, hasWritePermission, pages)
|
||||||
|
|
||||||
helpers.decorateHtml(Marked.marked(source, options, renderer))
|
helpers.decorateHtml(Marked.marked(source, options, renderer), repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import java.util.{Date, Locale, TimeZone}
|
|||||||
import gitbucket.core.controller.Context
|
import gitbucket.core.controller.Context
|
||||||
import gitbucket.core.model.CommitState
|
import gitbucket.core.model.CommitState
|
||||||
import gitbucket.core.plugin.{PluginRegistry, RenderRequest}
|
import gitbucket.core.plugin.{PluginRegistry, RenderRequest}
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service.{RepositoryService, RequestCache}
|
import gitbucket.core.service.{RepositoryService, RequestCache}
|
||||||
import gitbucket.core.util.{FileUtil, JGitUtil, StringUtil}
|
import gitbucket.core.util.{EmojiUtil, FileUtil, JGitUtil, StringUtil}
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.{Element, Node}
|
import org.jsoup.nodes.{Element, Node}
|
||||||
import play.twirl.api.{Html, HtmlFormat}
|
import play.twirl.api.{Html, HtmlFormat}
|
||||||
@@ -152,7 +153,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
* Converts commit id, issue id and username to the link.
|
* Converts commit id, issue id and username to the link.
|
||||||
*/
|
*/
|
||||||
def link(value: String, repository: RepositoryService.RepositoryInfo)(implicit context: Context): Html =
|
def link(value: String, repository: RepositoryService.RepositoryInfo)(implicit context: Context): Html =
|
||||||
Html(decorateHtml(convertRefsLinks(value, repository)))
|
Html(decorateHtml(convertRefsLinks(value, repository), repository))
|
||||||
|
|
||||||
def cut(value: String, length: Int): String =
|
def cut(value: String, length: Int): String =
|
||||||
if(value.length > length){
|
if(value.length > length){
|
||||||
@@ -342,16 +343,17 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
*
|
*
|
||||||
* TODO Move to the other place.
|
* TODO Move to the other place.
|
||||||
*/
|
*/
|
||||||
def decorateHtml(text: String)(implicit context: Context): String = {
|
def decorateHtml(text: String, repository: RepositoryInfo)(implicit context: Context): String = {
|
||||||
val textDecorators = PluginRegistry().getTextDecorators
|
// val textDecorators = PluginRegistry().getTextDecorators
|
||||||
|
|
||||||
def processNode(n: Node): Unit = {
|
def processNode(n: Node): Unit = {
|
||||||
n match {
|
n match {
|
||||||
case x: Element => {
|
case x: Element => {
|
||||||
if(x.hasText && x.ownText.nonEmpty){
|
if(x.hasText && x.ownText.nonEmpty){
|
||||||
val text = textDecorators.foldLeft(x.ownText){ case (text, textDecorator) =>
|
val text = EmojiUtil.convertEmojis(x.ownText)
|
||||||
textDecorator.decorate(text)
|
// val text = textDecorators.foldLeft(x.ownText){ case (text, textDecorator) =>
|
||||||
}
|
// textDecorator.decorate(text, repository)
|
||||||
|
// }
|
||||||
x.html(text)
|
x.html(text)
|
||||||
}
|
}
|
||||||
x.children.toArray.foreach { c =>
|
x.children.toArray.foreach { c =>
|
||||||
|
|||||||
Reference in New Issue
Block a user