Skip to content

Commit

Permalink
migrate from vweb to veb
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Sep 18, 2024
1 parent 5001da5 commit 704ec38
Show file tree
Hide file tree
Showing 68 changed files with 878 additions and 937 deletions.
2 changes: 1 addition & 1 deletion git/libgit.v
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn new_repo(path string) &Repo {
println('ff ${ret}')
// git_reference_free(head_ref);
return &Repo{
obj: repo_obj
obj: repo_obj
path: path
}
}
Expand Down
2 changes: 1 addition & 1 deletion git/util.v
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn check_git_repo_url(url string) bool {
headers.add_custom('User-Agent', 'git/2.30.0') or {}
headers.add_custom('Git-Protocol', 'version=2') or {}
config := http.FetchConfig{
url: refs_url
url: refs_url
header: headers
}
response := http.fetch(config) or { return false }
Expand Down
12 changes: 6 additions & 6 deletions highlight/c.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_c() Lang {
return Lang{
name: 'C'
name: 'C'
lang_extensions: ['c']
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#555555'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#555555'
keywords: [
'auto',
'double',
'int',
Expand Down
12 changes: 6 additions & 6 deletions highlight/cpp.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_cpp() Lang {
return Lang{
name: 'C++'
name: 'C++'
lang_extensions: ['cpp', 'cc', 'hh', 'h']
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#f34b7d'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#f34b7d'
keywords: [
'int',
'float',
'while',
Expand Down
12 changes: 6 additions & 6 deletions highlight/d.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_d() Lang {
return Lang{
name: 'D'
name: 'D'
lang_extensions: ['d']
line_comments: '//'
mline_comments: ['/*', '*/', '/+', '+/']
string_start: ['"', "'"]
color: '#ba595e'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/', '/+', '+/']
string_start: ['"', "'"]
color: '#ba595e'
keywords: [
'abstract',
'alias',
'align',
Expand Down
12 changes: 6 additions & 6 deletions highlight/go.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_go() Lang {
return Lang{
name: 'Go'
name: 'Go'
lang_extensions: ['go']
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', '`']
color: '#00add8'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', '`']
color: '#00add8'
keywords: [
'break',
'chan',
'const',
Expand Down
6 changes: 2 additions & 4 deletions highlight/highlight.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module highlight

const (
tab = ' ' // '
)
const tab = ' ' // '

// returns HTML code, number of lines, number of lines with source code
pub fn highlight_text(st string, file_path string, commit bool) (string, int, int) {
Expand Down Expand Up @@ -69,7 +67,7 @@ pub fn highlight_text(st string, file_path string, commit bool) (string, int, in
continue
}
if c == `\t` {
res << highlight.tab.bytes()
res << tab.bytes()
continue
}
if in_comment {
Expand Down
12 changes: 6 additions & 6 deletions highlight/javascript.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_js() Lang {
return Lang{
name: 'JavaScript'
name: 'JavaScript'
lang_extensions: ['js', 'mjs', 'jsx']
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#f1e05a'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#f1e05a'
keywords: [
'break',
'do',
'instanceof',
Expand Down
10 changes: 3 additions & 7 deletions highlight/langs.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module highlight

const (
lang_path = 'langs'
)
const lang_path = 'langs'

const (
langs = init_langs()
)
const langs = init_langs()

pub struct Lang {
keywords []string
Expand All @@ -28,7 +24,7 @@ fn is_source(ext string) bool {

pub fn extension_to_lang(ext string) !Lang {
ending := ext.split('.').last()
for lang in highlight.langs {
for lang in langs {
if ending in lang.lang_extensions {
return lang
}
Expand Down
12 changes: 6 additions & 6 deletions highlight/lua.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_lua() Lang {
return Lang{
name: 'Lua'
name: 'Lua'
lang_extensions: ['lua']
line_comments: '--'
mline_comments: ['--[[', ']]']
string_start: ['"', "'"]
color: '#00007d'
keywords: [
line_comments: '--'
mline_comments: ['--[[', ']]']
string_start: ['"', "'"]
color: '#00007d'
keywords: [
'and',
'break',
'do',
Expand Down
138 changes: 68 additions & 70 deletions highlight/markdown.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,71 @@ module highlight
import markdown
import pcre

const (
allowed_tags = [
'a',
'abbr',
'b',
'blockquote',
'body',
'br',
'center',
'code',
'dd',
'details',
'div',
'dl',
'dt',
'em',
'font',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hr',
'i',
'img',
'kbd',
'label',
'li',
'ol',
'p',
'pre',
'small',
'source',
'span',
'strong',
'sub',
'summary',
'sup',
'table',
'tbody',
'tr',
'td',
'th',
'thead',
'ul',
'u',
'video',
]
allowed_attributes = [
'align',
'color',
'controls',
'height',
'href',
'id',
'src',
'style',
'target',
'title',
'type',
'width',
]
unallowed_schemas = [
'javascript:',
]
)
const allowed_tags = [
'a',
'abbr',
'b',
'blockquote',
'body',
'br',
'center',
'code',
'dd',
'details',
'div',
'dl',
'dt',
'em',
'font',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hr',
'i',
'img',
'kbd',
'label',
'li',
'ol',
'p',
'pre',
'small',
'source',
'span',
'strong',
'sub',
'summary',
'sup',
'table',
'tbody',
'tr',
'td',
'th',
'thead',
'ul',
'u',
'video',
]
const allowed_attributes = [
'align',
'color',
'controls',
'height',
'href',
'id',
'src',
'style',
'target',
'title',
'type',
'width',
]
const unallowed_schemas = [
'javascript:',
]

pub fn convert_markdown_to_html(code string) string {
markdown_code := sanitize_markdown_code(code)
Expand Down Expand Up @@ -121,7 +119,7 @@ fn sanitize_html_tags_with_re(re string, code string) string {
tag_name := tag_parts[0].trim_space().to_lower()
tag_attributes := tag_parts[1].trim_space()
tag_content := tag_parts[2].trim_space()
is_allowed_tag := highlight.allowed_tags.contains(tag_name)
is_allowed_tag := allowed_tags.contains(tag_name)

if !is_allowed_tag {
result = result.replace(tag, '')
Expand Down Expand Up @@ -174,8 +172,8 @@ fn sanitize_html_attributes(attributes string) string {
attribute_name := attribute_parts[0].trim_space().to_lower()
attribute_value := attribute_parts[1].trim_space()

is_allowed_attribute := highlight.allowed_attributes.contains(attribute_name)
is_unallowed_schemas := highlight.unallowed_schemas.any(attribute_value.starts_with(it))
is_allowed_attribute := allowed_attributes.contains(attribute_name)
is_unallowed_schemas := unallowed_schemas.any(attribute_value.starts_with(it))

if !is_allowed_attribute || is_unallowed_schemas {
result = result.replace(attribute, '')
Expand Down
8 changes: 3 additions & 5 deletions highlight/markdown_test.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module highlight

const (
markdown = '<script> alert(true) </script> <!-- comment -->test'
html = '<p>test</p>'
)
const markdown = '<script> alert(true) </script> <!-- comment -->test'
const html = '<p>test</p>'

fn test_convert_markdown_to_html() {
assert convert_markdown_to_html(highlight.markdown) == highlight.html
assert convert_markdown_to_html(markdown) == html
}
10 changes: 5 additions & 5 deletions highlight/python.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module highlight

fn init_py() Lang {
return Lang{
name: 'Python'
name: 'Python'
lang_extensions: ['py', 'ipynb']
line_comments: '#'
string_start: ['"', "'", '"""', "'''"]
color: '#3572A5'
keywords: [
line_comments: '#'
string_start: ['"', "'", '"""', "'''"]
color: '#3572A5'
keywords: [
'None',
'True',
'and',
Expand Down
12 changes: 6 additions & 6 deletions highlight/typescript.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module highlight

fn init_ts() Lang {
return Lang{
name: 'TypeScript'
name: 'TypeScript'
lang_extensions: ['ts', 'tsx']
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#2b7489'
keywords: [
line_comments: '//'
mline_comments: ['/*', '*/']
string_start: ['"', "'"]
color: '#2b7489'
keywords: [
'any',
'as',
'boolean',
Expand Down
Loading

0 comments on commit 704ec38

Please sign in to comment.