Skip to content

Commit

Permalink
Merge pull request #335 from NullVoxPopuli/add-css-highlighting
Browse files Browse the repository at this point in the history
Use Starbeam for the demo app / site
  • Loading branch information
NullVoxPopuli authored Jun 24, 2023
2 parents eb19fe8 + 062be39 commit a25d346
Show file tree
Hide file tree
Showing 17 changed files with 794 additions and 474 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-timers-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'highlightjs-glimmer': minor
---

Support <style> tags
8 changes: 7 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
dist/
vendor/
demo/
highlight
coverage/
node_modules/
.git/
.github/

# All folders
*/
.github/
.changeset/
27 changes: 14 additions & 13 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
// .eslintrc.js
'use strict';

const { configs } = require('@nullvoxpopuli/eslint-configs');
const {
jsBase,
moduleBase,
baseRulesAppliedLast,
} = require('@nullvoxpopuli/eslint-configs/configs/base');
const { configBuilder } = require('@nullvoxpopuli/eslint-configs/configs/node');
const { forFiles } = require('@nullvoxpopuli/eslint-configs/configs/-utils');

const mjs = configs.node();
const config = configBuilder();
const modulesBase = config.modules.js;

module.exports = {
...mjs,
overrides: [
...mjs.overrides,
// pull this in to eslint-configs?
{
...jsBase,
files: ['*.html'],
plugins: [moduleBase.plugins, 'html'].flat(),
plugins: [modulesBase.plugins, 'html'].flat(),
parser: '@babel/eslint-parser',
parserOptions: {
requireConfigFile: false,
sourceType: 'module',
ecmaVersion: 2021,
},
env: {
browser: true,
node: false,
},
extends: ['eslint:recommended', 'prettier'],
rules: {
...jsBase.rules,
...baseRulesAppliedLast,
...modulesBase.rules,
'no-console': 'off',
},
},
forFiles('*.cjs', config.commonjs.js),
],
};
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# All folders
*/
.github/
.changeset/
*.md
*.json5
*.yaml
18 changes: 18 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = {
singleQuote: true,
printWidth: 100,
overrides: [
{
files: ['**/*.hbs'],
options: {
singleQuote: false,
},
},
{
files: ['**/*.gjs', '**/*.gts'],
plugins: ['prettier-plugin-ember-template-tag'],
},
],
};
5 changes: 5 additions & 0 deletions demo/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const { configs } = require('@nullvoxpopuli/eslint-configs');

module.exports = configs.crossPlatform();
18 changes: 18 additions & 0 deletions demo/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = {
singleQuote: true,
printWidth: 100,
overrides: [
{
files: ['**/*.hbs'],
options: {
singleQuote: false,
},
},
{
files: ['**/*.gjs', '**/*.gts'],
plugins: ['prettier-plugin-ember-template-tag'],
},
],
};
21 changes: 21 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "demo",
"private": true,
"type": "module",
"scripts": {
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint:js": "eslint .",
"lint:js:fix": "eslint . --fix",
"lint:prettier": "prettier --check .",
"lint:prettier:fix": "prettier --write ."
},
"devDependencies": {
"@nullvoxpopuli/eslint-configs": "^3.1.3",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"concurrently": "^8.2.0",
"eslint": "^8.43.0",
"prettier": "^2.8.8",
"typescript": "^5.1.3"
}
}
27 changes: 27 additions & 0 deletions demo/samples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
/* eslint-disable no-useless-escape */

/**
* @typedef {Object} Sample
Expand Down Expand Up @@ -84,6 +85,20 @@ export const glimmer = {
{{textarea}}
{{/if}}
{{/block-component}}
<style data-demo="true" data-x={{(foo "bar")}}>
button {
font-weight: bold;
text-decoration: underline;
color: red;
background: #554433;
}
[type="button"] {
border: 1px solid;
}
</style>
`,
};

Expand All @@ -104,6 +119,12 @@ export default class Hello {
<button {{on 'click' @onClick}}>
Hello, <Name @name={{this.name}} />!
</button>
<style scoped>
button {
background: transparent;
}
</style>
</template>
}
`,
Expand All @@ -128,6 +149,12 @@ const setScrollPosition = modifier((element, [position]) => {
Item #{{plusOne index}}: {{item}}
{{/each}}
</div>
<style>
.scroll-container {
border: 1px solid;
}
</style>
</template>
`,
};
Expand Down
32 changes: 32 additions & 0 deletions highlightjs-glimmer/dist/glimmer.cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,39 @@ function glimmer(hljs) {
}
];
STRING.variants.forEach((variant) => variant.contains.push(...MUSTACHE_EXPRESSION));
const STYLE_TAG = {
className: "tag",
/*
The lookahead pattern (?=...) ensures that 'begin' only matches
'<style' as a single word, followed by a whitespace or an
ending bracket.
*/
begin: regex.concat(
/<:?/,
regex.lookahead(regex.concat("style", regex.either(/\/>/, />/, /\s/)))
),
end: /\/?>/,
contains: [
OPERATORS,
ARGUMENTS,
TAG_COMMENT,
BLOCK_PARAMS,
THIS_EXPRESSION,
...MUSTACHE_EXPRESSION,
ATTRIBUTES,
STRING,
ABS_NAME
],
starts: {
className: "tag",
end: /<\/style>/,
returnEnd: true,
excludeEnd: false,
subLanguage: ["css", "glimmer"]
}
};
const ANGLE_BRACKET_BLOCK = [
STYLE_TAG,
{
className: "tag",
begin: regex.concat(
Expand Down
2 changes: 1 addition & 1 deletion highlightjs-glimmer/dist/glimmer.esm.min.js

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

2 changes: 1 addition & 1 deletion highlightjs-glimmer/dist/glimmer.min.js

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

33 changes: 33 additions & 0 deletions highlightjs-glimmer/src/glimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,40 @@ export default function glimmer(hljs) {

STRING.variants.forEach((variant) => variant.contains.push(...MUSTACHE_EXPRESSION));

const STYLE_TAG = {
className: 'tag',
/*
The lookahead pattern (?=...) ensures that 'begin' only matches
'<style' as a single word, followed by a whitespace or an
ending bracket.
*/
begin: regex.concat(
/<:?/,
regex.lookahead(regex.concat('style', regex.either(/\/>/, />/, /\s/)))
),
end: /\/?>/,
contains: [
OPERATORS,
ARGUMENTS,
TAG_COMMENT,
BLOCK_PARAMS,
THIS_EXPRESSION,
...MUSTACHE_EXPRESSION,
ATTRIBUTES,
STRING,
ABS_NAME,
],
starts: {
className: 'tag',
end: /<\/style>/,
returnEnd: true,
excludeEnd: false,
subLanguage: ['css', 'glimmer'],
},
};

const ANGLE_BRACKET_BLOCK = [
STYLE_TAG,
{
className: 'tag',
begin: regex.concat(
Expand Down
Loading

0 comments on commit a25d346

Please sign in to comment.