Skip to content

Commit

Permalink
Added QML (#2139)
Browse files Browse the repository at this point in the history
This adds support for QML (Qt Modeling Language), a user interface markup language.

https://en.wikipedia.org/wiki/QML
https://doc.qt.io/qt-5/qtqml-index.html
  • Loading branch information
RunDevelopment authored Jan 8, 2020
1 parent 99d979a commit c40d96c
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.

Loading

0 comments on commit c40d96c

Please sign in to comment.