Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
bc5752e9
Commit
bc5752e9
authored
May 18, 2018
by
bbaer
Browse files
Syntax highlighting basics
parent
1f34ec9f
Changes
5
Hide whitespace changes
Inline
Side-by-side
javascript/src/CodeCorrection.js
View file @
bc5752e9
...
...
@@ -8,6 +8,7 @@
/* @depend Alert.js */
/* @depend Comment.js */
/* @depend CommentController */
/* @depend SyntaxHighlighter */
/**
* Qfq Namespace
...
...
@@ -41,6 +42,7 @@ var QfqNS = QfqNS || {};
this
.
users
=
[];
this
.
currentUser
=
currentUser
;
this
.
language
=
language
;
this
.
syntaxHighlight
=
{};
};
/**
...
...
@@ -63,16 +65,24 @@ var QfqNS = QfqNS || {};
if
(
this
.
data
.
url
)
{
// Get data of a file and write it to data.text
$
.
get
(
this
.
data
.
url
,
function
(
response
)
{
that
.
data
.
text
=
response
;
that
.
_
buildEditor
();
that
.
data
.
text
=
response
;
that
.
_
prepareBuild
();
});
}
else
if
(
this
.
data
.
text
)
{
this
.
_
buildEditor
();
this
.
_
prepareBuild
();
}
else
{
console
.
error
(
"
[CodeCorrection] No Code to correct passed to the object.
"
);
}
};
n
.
CodeCorrection
.
prototype
.
_prepareBuild
=
function
()
{
var
that
=
this
;
this
.
syntaxHighlight
=
new
n
.
SyntaxHighlighter
();
this
.
syntaxHighlight
.
importInstructions
(
this
.
language
,
function
()
{
that
.
_buildEditor
();
});
};
/**
* Breaks up the String by line and returns it as an Array
* @param text Unix formatted text of the Code File
...
...
@@ -149,6 +159,7 @@ var QfqNS = QfqNS || {};
var
cLine
=
line
.
replace
(
/
\s
/g
,
'
'
)
.
replace
(
'
<
'
,
'
<
'
)
.
replace
(
'
>
'
,
'
>
'
);
cLine
=
this
.
syntaxHighlight
.
highlightLine
(
cLine
);
var
htmlCodeLine
=
$
(
'
<div/>
'
,
{
class
:
'
pull-right qfqCode
'
});
...
...
@@ -169,7 +180,6 @@ var QfqNS = QfqNS || {};
var
commentController
=
new
n
.
CommentController
();
commentController
.
buildContainer
(
$hook
);
commentController
.
setCurrentUser
(
this
.
currentUser
);
console
.
log
(
this
.
currentUser
.
name
);
return
commentController
;
};
...
...
javascript/src/SyntaxHighlighter.js
View file @
bc5752e9
...
...
@@ -20,23 +20,38 @@ var QfqNS = QfqNS || {};
*/
n
.
SyntaxHighlighter
=
function
()
{
this
.
highlightInstructions
=
{};
this
.
uri
=
""
;
this
.
importDone
=
false
;
this
.
waitingForEnd
=
false
;
this
.
multiLineClass
=
""
;
this
.
line
=
''
;
};
n
.
SyntaxHighlighter
.
prototype
.
importInstructions
=
function
(
json
)
{
$
.
getJSON
(
json
,
function
(
data
)
{
this
.
highlightInstructions
=
data
;
});
n
.
SyntaxHighlighter
.
prototype
.
importInstructions
=
function
(
json
,
callbackFn
)
{
var
that
=
this
;
console
.
log
(
"
Import instructions:
"
+
json
);
$
.
getJSON
(
json
,
function
(
data
)
{
that
.
highlightInstructions
=
data
;
that
.
importDone
=
true
;
if
(
callbackFn
&&
typeof
(
callbackFn
)
===
"
function
"
)
{
console
.
log
(
"
callback found
"
);
callbackFn
();
}
});
};
n
.
SyntaxHighlighter
.
prototype
.
setLanguageUri
=
function
(
uri
)
{
this
.
uri
=
uri
;
};
n
.
SyntaxHighlighter
.
prototype
.
highlightLine
=
function
(
line
)
{
this
.
line
=
line
;
if
(
!
this
.
waitingForEnd
)
{
if
(
this
.
_multiLineHighlight
())
{
return
this
.
line
;
}
this
.
_wordHighlight
();
}
else
{
if
(
this
.
_multiLineHighlight
())
{
return
this
.
line
;
...
...
@@ -45,6 +60,16 @@ var QfqNS = QfqNS || {};
return
this
.
line
;
}
}
return
this
.
line
;
};
n
.
SyntaxHighlighter
.
prototype
.
_wordHighlight
=
function
()
{
for
(
var
i
=
0
;
i
<
this
.
highlightInstructions
.
singleWord
.
length
;
i
++
)
{
var
word
=
this
.
highlightInstructions
.
singleWord
[
i
];
var
regex
=
new
RegExp
(
word
.
regex
,
"
g
"
);
var
wrapClass
=
this
.
highlightInstructions
.
classes
[
word
.
styleId
].
name
;
this
.
line
=
this
.
wrapMatch
(
wrapClass
,
regex
,
this
.
line
);
}
};
n
.
SyntaxHighlighter
.
prototype
.
_multiLineHighlight
=
function
()
{
...
...
@@ -59,12 +84,12 @@ var QfqNS = QfqNS || {};
if
(
regex
.
test
(
this
.
line
))
{
if
(
this
.
waitingForEnd
)
{
this
.
endWrap
(
regex
,
this
.
line
);
this
.
line
=
this
.
endWrap
(
this
.
multiLineClass
,
regex
,
this
.
line
);
this
.
waitingForEnd
=
false
;
this
.
multiLineClass
=
""
;
}
else
{
this
.
multiLineClass
=
this
.
highlightInstructions
.
classes
[
multiLine
.
styleId
];
this
.
startWrap
(
this
.
multiLineClass
,
regex
,
this
.
line
);
this
.
multiLineClass
=
this
.
highlightInstructions
.
classes
[
multiLine
.
styleId
]
.
name
;
this
.
line
=
this
.
startWrap
(
this
.
multiLineClass
,
regex
,
this
.
line
);
this
.
waitingForEnd
=
true
;
}
return
true
;
...
...
@@ -79,18 +104,18 @@ var QfqNS = QfqNS || {};
};
n
.
SyntaxHighlighter
.
prototype
.
startWrap
=
function
(
spanClass
,
regex
,
line
)
{
line
.
replace
(
regex
,
"
<span class=
\"
"
+
spanClass
+
"
\"
>$1$2</span>
"
);
return
l
ine
;
var
newLine
=
line
.
replace
(
regex
,
"
<span class=
\"
"
+
spanClass
+
"
\"
>$1$2</span>
"
);
return
newL
ine
;
};
n
.
SyntaxHighlighter
.
prototype
.
endWrap
=
function
(
spanClass
,
regex
,
line
)
{
line
.
replace
(
regex
,
"
<span class=
\"
"
+
spanClass
+
"
\"
>$1</span>$2
"
);
return
l
ine
;
var
newLine
=
line
.
replace
(
regex
,
"
<span class=
\"
"
+
spanClass
+
"
\"
>$1</span>$2
"
);
return
newL
ine
;
};
n
.
SyntaxHighlighter
.
prototype
.
wrapMatch
=
function
(
spanClass
,
regex
,
line
)
{
line
.
replace
(
regex
,
"
$1<span class=
\"
"
+
spanClass
+
"
\"
>$2</span>$3
"
)
return
l
ine
;
var
newLine
=
line
.
replace
(
regex
,
"
$1<span class=
\"
"
+
spanClass
+
"
\"
>$2</span>$3
"
)
;
return
newL
ine
;
};
})(
QfqNS
);
\ No newline at end of file
less/qfq-bs.css.less
View file @
bc5752e9
...
...
@@ -608,4 +608,17 @@ i.@{spinner_class} {
.qfqCodeList {
top: 35px;
}
.qfqSyntaxDoc {
color: #888;
}
.qfqSyntaxWord {
font-weight: bold;
color: #31708f;
}
.qfqSyntaxData {
color: #5cb85c;
}
\ No newline at end of file
mockup/codeCorrection.html
View file @
bc5752e9
...
...
@@ -102,7 +102,7 @@
uid
:
5
,
name
:
"
Definitely not an AI
"
,
avatar
:
"
mockData/avatar1.png
"
},
'
mockData/javascript.json
'
);
},
'
http://localhost:63342/qfq/mockup/
mockData/javascript.json
'
);
codeCorrection
.
initialize
();
});
...
...
mockup/mockData/javascript.json
View file @
bc5752e9
{
"language"
:
"javascript"
,
s
"language"
:
"javascript"
,
"classes"
:
[
{
"position"
:
0
,
"name"
:
"qfqHLComment"
,
"description"
:
"Highlighting for Comments"
"name"
:
"qfqSyntaxDoc"
,
"description"
:
"jsDoc"
},
{
"position"
:
1
,
"name"
:
"qfqSyntaxWord"
,
"description"
:
"Reserved Words"
},
{
"position"
:
2
,
"name"
:
"qfqSyntaxData"
,
"description"
:
"Datatypes"
}
],
"multiLine"
:
[
{
"start"
:
"(
\/\
*
\*
)(.*)$"
,
"end"
:
"(
\*\/
)(.*)$"
,
"start"
:
"(
\/\
\
*
\
\
*)(.*)$"
,
"end"
:
"(
\
\
*
\/
)(.*)$"
,
"styleId"
:
0
}
],
"singleWord"
:
[
{
"regex"
:
"^(.*)(
\\\"
.*
\\\"
)(.*)$"
,
"styleId"
:
2
},
{
"regex"
:
"(.*)(function)(.*)"
,
"styleId"
:
1
},
{
"regex"
:
"^(.*)( if )(.*)$"
,
"styleId"
:
1
},
{
"regex"
:
"^(.*)( for )(.*)$"
,
"styleId"
:
1
},
{
"regex"
:
"^(.*)(this)(.*)$"
,
"styleId"
:
1
},
{
"regex"
:
"^(.*)( var )(/*)$"
,
"styleId"
:
1
},
{
"regex"
:
"^(.*)([0-9]+)(.*)$"
,
"styleId"
:
2
}
]
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment