-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 Robot Framework plain text format #2034
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
(function (Prism) { | ||
|
||
var comment = { | ||
pattern: /(^[ \t]*| {2}|\t)#.*/m, | ||
lookbehind: true, | ||
greedy: true | ||
}; | ||
|
||
var variable = { | ||
pattern: /((?:^|[^\\])(?:\\{2})*)[$@&%]\{(?:[^{}\r\n]|\{[^{}\r\n]*\})*\}/, | ||
lookbehind: true, | ||
inside: { | ||
'punctuation': /^[$@&%]\{|\}$/ | ||
} | ||
}; | ||
|
||
function createSection(name, inside) { | ||
var extendecInside = {}; | ||
|
||
extendecInside['section-header'] = { | ||
pattern: /^ ?\*{3}.+?\*{3}/, | ||
alias: 'keyword' | ||
}; | ||
|
||
// copy inside tokens | ||
for (var token in inside) { | ||
extendecInside[token] = inside[token]; | ||
} | ||
|
||
extendecInside['tag'] = { | ||
pattern: /([\r\n](?: |\t)[ \t]*)\[[-\w]+\]/, | ||
lookbehind: true, | ||
inside: { | ||
'punctuation': /\[|\]/ | ||
} | ||
}; | ||
extendecInside['variable'] = variable; | ||
extendecInside['comment'] = comment; | ||
|
||
return { | ||
pattern: RegExp(/^ ?\*{3}[ \t]*<name>[ \t]*\*{3}(?:.|[\r\n](?!\*{3}))*/.source.replace(/<name>/g, name), 'im'), | ||
alias: 'section', | ||
inside: extendecInside | ||
}; | ||
} | ||
|
||
|
||
var docTag = { | ||
pattern: /(\[Documentation\](?: |\t)[ \t]*)(?![ \t]|#)(?:.|[ \t]*(?:\r\n?|\n)[ \t]*\.{3}[ \t]*)+/, | ||
lookbehind: true, | ||
alias: 'string' | ||
}; | ||
|
||
var testNameLike = { | ||
pattern: /([\r\n] ?)(?!#)(?:\S(?:[ \t]\S)*)+/, | ||
lookbehind: true, | ||
alias: 'function', | ||
inside: { | ||
'variable': variable | ||
} | ||
}; | ||
|
||
var testPropertyLike = { | ||
pattern: /([\r\n](?: |\t)[ \t]*)(?!\[|\.{3}|#)(?:\S(?:[ \t]\S)*)+/, | ||
lookbehind: true, | ||
inside: { | ||
'variable': variable | ||
} | ||
}; | ||
|
||
Prism.languages['robot-framework'] = { | ||
'settings': createSection('Settings', { | ||
'documentation': { | ||
pattern: /([\r\n] ?Documentation(?: |\t)[ \t]*)(?![ \t]|#)(?:.|[ \t]*(?:\r\n?|\n)[ \t]*\.{3}[ \t]*)+/, | ||
lookbehind: true, | ||
alias: 'string' | ||
}, | ||
'property': { | ||
pattern: /([\r\n] ?)(?!\.{3}|#)(?:\S(?:[ \t]\S)*)+/, | ||
lookbehind: true | ||
} | ||
}), | ||
'variables': createSection('Variables'), | ||
'test-cases': createSection('Test Cases', { | ||
'test-name': testNameLike, | ||
'documentation': docTag, | ||
'property': testPropertyLike | ||
}), | ||
'keywords': createSection('Keywords', { | ||
'keyword-name': testNameLike, | ||
'documentation': docTag, | ||
'property': testPropertyLike | ||
}), | ||
'tasks': createSection('Tasks', { | ||
'task-name': testNameLike, | ||
'documentation': docTag, | ||
'property': testPropertyLike | ||
}), | ||
'comment': comment | ||
}; | ||
|
||
Prism.languages.robot = Prism.languages['robot-framework']; | ||
|
||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h2>Full example</h2> | ||
<pre><code>*** Settings *** | ||
Documentation Example using the space separated plain text format. | ||
Library OperatingSystem | ||
|
||
*** Variables *** | ||
${MESSAGE} Hello, world! | ||
|
||
*** Test Cases *** | ||
My Test | ||
[Documentation] Example test | ||
Log ${MESSAGE} | ||
My Keyword /tmp | ||
|
||
Another Test | ||
Should Be Equal ${MESSAGE} Hello, world! | ||
|
||
*** Keywords *** | ||
My Keyword | ||
[Arguments] ${path} | ||
Directory Should Exist ${path}</code></pre> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# comment | ||
|
||
*** Keywords *** # comment | ||
Run Program # comment | ||
[Arguments] @{args} # comment | ||
Run Process program.py @{args} # comment | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "# comment"], | ||
["keywords", [ | ||
["section-header", "*** Keywords ***"], | ||
["comment", "# comment"], | ||
["keyword-name", [ | ||
"Run Program" | ||
]], | ||
["comment", "# comment"], | ||
["tag", [ | ||
["punctuation", "["], | ||
"Arguments", | ||
["punctuation", "]"] | ||
]], | ||
["variable", [ | ||
["punctuation", "@{"], | ||
"args", | ||
["punctuation", "}"] | ||
]], | ||
["comment", "# comment"], | ||
["property", [ | ||
"Run Process" | ||
]], | ||
" program.py ", | ||
["variable", [ | ||
["punctuation", "@{"], | ||
"args", | ||
["punctuation", "}"] | ||
]], | ||
["comment", "# comment"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work with the gulp task we have in the build that does the
.source
replace?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Here's the minified version of that line (pulled from
components/prism-robot-framework.min.js
):What made you think it wouldn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't remember how it worked and I was wondering if the dynamic rewrite was an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barely. I used a regex to find all RegExp literals which end with
/.source
and replace those with the optimized source value. I say optimized but it's really just a few things like replace\\t
with\t
to save a few characters. It's technically incorrect as it's not the real source value but it works well for Prism where we never leave the world of regex patterns.I'm planning to drop this as soon as our minifier supports this. With regard to #1578, I opened an issue at Terser which can minify ES6+ code.