Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added QML #2139

Merged
merged 2 commits into from Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -810,6 +810,11 @@
"title": "Q (kdb+ database)",
"owner": "Golmote"
},
"qml": {
"title": "QML",
"require": "javascript",
"owner": "RunDevelopment"
},
"qore": {
"title": "Qore",
"require": "clike",
Expand Down
58 changes: 58 additions & 0 deletions components/prism-qml.js
@@ -0,0 +1,58 @@
(function (Prism) {

var jsString = /"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*'/.source;
var jsComment = /\/\/.*|\/\*(?:(?!\*\/)[\s\S])*\*\//.source;

var jsExpr = /(?:[^\\()[\]{}"'/]|<string>|\/(?![*/])|<comment>|\(<expr>*\)|\[<expr>*\]|\{<expr>*\}|\\[\s\S])/
.source.replace(/<string>/g, jsString).replace(/<comment>/g, jsComment);

// the pattern will blow up, so only a few iterations
for (var i = 0; i < 2; i++) {
jsExpr = jsExpr.replace(/<expr>/g, jsExpr);
}
jsExpr = jsExpr.replace(/<expr>/g, '[^\\s\\S]');


Prism.languages.qml = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
greedy: true
},
'javascript-function': {
pattern: RegExp(/((?:^|;)[ \t]*)function\s+[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*\(<js>*\)\s*\{<js>*\}/.source.replace(/<js>/g, jsExpr), 'm'),
lookbehind: true,
greedy: true,
alias: 'language-javascript',
inside: Prism.languages.javascript
},
'class-name': {
pattern: /((?:^|[:;])[ \t]*)(?!\d)\w+(?=[ \t]*\{|[ \t]+on\b)/m,
lookbehind: true
},
'property': [
{
pattern: /((?:^|[;{])[ \t]*)(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
lookbehind: true
},
{
pattern: /((?:^|[;{])[ \t]*)property[ \t]+(?!\d)\w+(?:\.\w+)*[ \t]+(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
lookbehind: true,
inside: {
'keyword': /^property/,
'property': /\w+(?:\.\w+)*/
}
}
],
'javascript-expression': {
pattern: RegExp(/(:[ \t]*)(?![\s;}[])(?:(?!$|[;}])<js>)+/.source.replace(/<js>/g, jsExpr), 'm'),
lookbehind: true,
greedy: true,
alias: 'language-javascript',
inside: Prism.languages.javascript
},
'string': /"(?:\\.|[^\\"\r\n])*"/,
'keyword': /\b(?:as|import|on)\b/,
'punctuation': /[{}[\]:;,]/
};

}(Prism));
1 change: 1 addition & 0 deletions components/prism-qml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions examples/prism-qml.html
@@ -0,0 +1,36 @@
<h2>Full example</h2>
<pre><code>// https://code.qt.io/cgit/qt/qtdeclarative.git/tree/examples/qml/referenceexamples/valuesource/example.qml?h=5.14

import People 1.0
import QtQuick 2.0 // For QColor

BirthdayParty {
HappyBirthdaySong on announcement { name: "Bob Jones" }

onPartyStarted: console.log("This party started rockin' at " + time);


host: Boy {
name: "Bob Jones"
shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
}

Boy {
name: "Leo Hodges"
BirthdayParty.rsvp: "2009-07-06"
shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
}
Boy {
name: "Jack Smith"
shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
}
Girl {
name: "Anne Brown"
BirthdayParty.rsvp: "2009-07-01"
shoe.size: 7
shoe.color: "red"
shoe.brand: "Marc Jacobs"
shoe.price: 699.99
}

}</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -91,6 +91,7 @@
"markup",
"javascript"
],
"qml": "javascript",
"qore": "clike",
"jsx": [
"markup",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -121,6 +121,7 @@
"protobuf": "Protocol Buffers",
"py": "Python",
"q": "Q (kdb+ database)",
"qml": "QML",
"jsx": "React JSX",
"tsx": "React TSX",
"renpy": "Ren'py",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.