Basic Plugin Support - Syntax Highlighter Added - WIP

This commit is contained in:
Daniel Szabo 2022-05-22 19:26:43 +01:00
parent 1c873d23b5
commit a6a56a11c7
8 changed files with 367 additions and 7 deletions

View file

@ -0,0 +1,78 @@
module MBP
module BasicSyntaxHighlighter
# Plugin Properties
def self.get_id()
"BasicSyntaxHighlighter"
end
def self.get_name()
"Basic Syntax Highlighter Plugin"
end
def self.get_version()
"1.0.0"
end
def self.get_author()
"Daniel Szabo"
end
def self.get_webpage()
"https://github.com/szabodanika/microbin"
end
def self.get_description()
"This plugin will simply color keywords and special characters in four different colors based on some very basic RegEx - it is meant to univesally make code pastas more readable but is not a robust syntax highlighter solution."
end
# Plugin Event Hooks
def self.init()
# Ignore event
"OK"
end
def self.on_pasta_created(content)
# We do not modify stored content
return content
end
def self.on_pasta_read(content)
tokens = {
"orchid" => [/([0-9])/, /([t|T][r|R][u|U][e|E]|[f|F][a|A][l|L][s|S][e|E])/],
"palevioletred" => ['(', ')', '{', '}', '[', ']'],
"royalblue" => [/(\s(for|while|do|select|async|await|mut|break|continue|in|as|switch|let|fn|async|if|else|elseif|new|switch|match|case|default|public|protected|private|return|class|interface|static|final|const|var|int|integer|boolean|float|double|module|def|end|void))(?![a-z])/],
"mediumorchid" => [/(:|\.|;|=|>|<|\?|!|#|%|@|\^|&|\*|\|)/],
"mediumseagreen" => [/(\".*\")/, /(\'.*\')/]
};
tokens.each { | color, tokens |
for token in tokens do
if(token.class == String)
content.gsub!(token, "$$#{color}$$" + token + "$$/#{color}$$")
elsif
content.gsub!(token, "$$#{color}$$" + '\1' + "$$/#{color}$$")
end
end
};
tokens.each { | color, tokens |
content.gsub!("$$#{color}$$", "<span style='color:#{color}'>");
content.gsub!("$$/#{color}$$", "</span>");
};
return content
end
end
end

78
plugins/MBPlugin.rb Normal file
View file

@ -0,0 +1,78 @@
require 'rutie'
module MB
class MBPlugin
# Plugin Properties
def self.get_id()
"[Enter Plugin ID]"
end
def self.get_name()
"[Eenter Plugin Name]"
end
def self.get_version()
"1.0.0"
end
def self.get_author()
"[Enter Author name]"
end
def self.get_webpage()
"[Enter Web URL]"
end
def self.get_description()
"[Enter Description]"
end
# Plugin Event Hooks
def self.init()
raise "Operation not supported";
end
def self.on_pasta_deleted(id, content, created, expiration, file)
raise "Operation not supported";
end
def self.on_pasta_expired(id, content, created, expiration, file)
raise "Operation not supported";
end
def self.on_pasta_created(id, content, created, expiration, file)
raise "Operation not supported";
end
def self.on_pasta_read(id, content, created, expiration, file)
raise "Operation not supported";
end
# Rust Function Calls
def self.init()
raise "Operation not supported";
end
def self.P=on_pasta_deleted(id, content, created, expiration, file)
raise "Operation not supported";
end
def self.on_pasta_expired(id, content, created, expiration, file)
raise "Operation not supported";
end
def self.on_pasta_created(id, content, created, expiration, file)
raise "Operation not supported";
end
def self.on_pasta_read(id, content, created, expiration, file)
raise "Operation not supported";
end
end
end

42
plugins/helloWorld.rb Normal file
View file

@ -0,0 +1,42 @@
module MBP
class HelloWorld < MBPlugin
def self.get_id()
"HelloWorld"
end
def self.get_name()
"Hello World Plugin"
end
def self.get_version()
"1.0.0"
end
def self.get_description()
"This is just a demo plugin. It does not do anything."
end
def self.get_author()
"Daniel Szabo"
end
def self.get_webpage()
"https://github.com/szabodanika/microbin"
end
def self.init()
# Ignore event
"OK"
end
def self.on_pasta_created(content)
return content
end
def self.on_pasta_read(content)
return content
end
end
end