chore: improve code
This commit is contained in:
parent
59b1d6c116
commit
07dd66ed07
2 changed files with 17 additions and 4 deletions
6
exe/yamd
6
exe/yamd
|
|
@ -110,16 +110,16 @@ class HTMLRenderer < YAMD::Renderer
|
||||||
tag('a', href: to, &blk)
|
tag('a', href: to, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
def code(&blk)
|
def code(lang: YAMD::Code::Lang::DEFAULT, &blk)
|
||||||
tag('pre', class: "language-any") {
|
tag('pre', class: "language-any") {
|
||||||
tag('code', class: "language-any") {
|
tag('code', class: "language-any") {
|
||||||
@buf << YAMD::Code::highlight(blk.())
|
@buf << YAMD::Code::highlight(blk.(), lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def inline_code(text)
|
def inline_code(text)
|
||||||
tag('code') {
|
tag('code', class: "code-inline") {
|
||||||
@buf << YAMD::Code::highlight(text)
|
@buf << YAMD::Code::highlight(text)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ module YAMD::Code
|
||||||
DEFAULT = {
|
DEFAULT = {
|
||||||
/\b(?:[A-Z][a-zA-Z\-_0-9]*)\b*/ => 'type',
|
/\b(?:[A-Z][a-zA-Z\-_0-9]*)\b*/ => 'type',
|
||||||
/#(\s|$)[^\n]*/ => 'comment',
|
/#(\s|$)[^\n]*/ => 'comment',
|
||||||
/\b(?:open|final|class|fn|let|var|if|else|while|loop|return|namespace|new)\b/ => 'kw',
|
/\b(?:open|final|class|struct|enum|fn|let|var|if|else|while|loop|return|namespace|new)\b/ => 'kw',
|
||||||
/\b(?:def|import|from)\b/ => 'kw',
|
/\b(?:def|import|from)\b/ => 'kw',
|
||||||
/\b(?:null|undefined|true|false|this|self)\b/i => 'const',
|
/\b(?:null|undefined|true|false|this|self)\b/i => 'const',
|
||||||
/\b(?:__[a-zA-Z0-9_]+__)\b/i => 'const',
|
/\b(?:__[a-zA-Z0-9_]+__)\b/i => 'const',
|
||||||
|
|
@ -30,6 +30,19 @@ module YAMD::Code
|
||||||
/"(?:\\.|[^\\"])*"/ => 'str',
|
/"(?:\\.|[^\\"])*"/ => 'str',
|
||||||
/'(?:\\.|[^\\'])*'/ => 'str',
|
/'(?:\\.|[^\\'])*'/ => 'str',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GD_SCRIPT = {
|
||||||
|
/\b(?:[A-Z_]+[A-Z_0-9]*)\b/ => 'const',
|
||||||
|
/\b(?:[A-Z][a-zA-Z\-_0-9]*)\b*/ => 'type',
|
||||||
|
/#(\s|$)[^\n]*/ => 'comment',
|
||||||
|
/\b(?:class|struct|enum|var|func|const|if|else|while|return)\b/ => 'kw',
|
||||||
|
/\b(?:class_name|extends)\b/ => 'kw',
|
||||||
|
/\b(?:null|true|false|self)\b/i => 'const',
|
||||||
|
/[:,;()\[\]{}<>]/ => 'punct',
|
||||||
|
/0|(0x[0-9a-fA-F]+)|([1-9][0-9]*(\.[0-9]+)?)/ => 'number',
|
||||||
|
/"(?:\\.|[^\\"])*"/ => 'str',
|
||||||
|
/'(?:\\.|[^\\'])*'/ => 'str',
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.highlight(txt, highlights=Lang::DEFAULT)
|
def self.highlight(txt, highlights=Lang::DEFAULT)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue