Skip to content

Commit

Permalink
Move front page highlighting to the build script and cleanup web-buil…
Browse files Browse the repository at this point in the history
…d scripts.
  • Loading branch information
kildom committed Mar 5, 2024
1 parent a143b15 commit b96f887
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 509 deletions.
81 changes: 76 additions & 5 deletions docs/tmpl/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:[email protected]&display=swap');

body {
Expand Down Expand Up @@ -197,9 +196,9 @@ a.try-it-button:hover {

.benefits {
display: flex;
justify-content: space-evenly;
align-items: stretch;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: stretch;
flex-wrap: wrap;
align-content: flex-start;
gap: 30px 60px;
padding: 50px 0px 20px;
Expand Down Expand Up @@ -258,7 +257,7 @@ code {
background-color: #ffffff41;
}

pre > code {
pre>code {
border: unset;
padding: 0px;
border-radius: 0.3em;
Expand All @@ -278,3 +277,75 @@ a:hover {
text-decoration: underline;
color: #2a4b7e;
}

/*---------------------------------------------------------------- HLJS
*/

pre code.hljs {
display: block;
overflow-x: auto;
padding: 1em
}

.hljs {
color: #abb2bf;
background: #282c34
}

.hljs-comment,
.hljs-quote {
color: #5c6370;
font-style: italic
}

.hljs-doctag,
.hljs-keyword,
.hljs-formula {
color: #c678dd
}

.hljs-section,
.hljs-name,
.hljs-selector-tag,
.hljs-deletion,
.hljs-subst {
color: #e06c75
}

.hljs-literal {
color: #56b6c2
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
color: #98c379
}

.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-type,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-number {
color: #d19a66
}

.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-meta,
.hljs-selector-id,
.hljs-title {
color: #61aeee
}

.hljs-built_in,
.hljs-title.class_,
.hljs-class .hljs-title {
color: #e6c07b
}
152 changes: 1 addition & 151 deletions docs/tmpl/index.js
Original file line number Diff line number Diff line change
@@ -1,157 +1,7 @@

/*hljs.configure({
languages: ['javascript'],
cssSelector: 'pre.highlight'
});*/

window.onload = function () {
hljs.registerLanguage('cre', (hljs) => {
return {
name: 'cre',
aliases: [],
case_insensitive: false,
keywords: {
$pattern: /[a-zA-Z0-9\\-]+/,
keyword: ['or', "match", "not"],
literal: [
"any", "digit", "white-space", "whitespace", "word-char", "word-character",
"nl", "new-line", "lf", "line-feed", "cr", "carriage-return", "tab", "tabulation",
"nul", "null", "sp", "space", "nbsp", "term", "terminator", "line-term", "line-terminator",
"prop", "property",
],
},
contains: [
hljs.COMMENT(/\/\*/, /\*\//),
hljs.COMMENT(/\/\//, /$/),
{
scope: 'literal',
begin: cre.ignoreCase`"\\", [rnt0]`,
},
{
scope: 'keyword',
begin: cre.ignoreCase`
optional ("lazy-" or "non-greedy-");
{
optional "repeat-";
{
optional "at-";
"least-" or "most-";
at-least-1 digit;
} or {
at-least-1 digit;
optional ("-to-", at-least-1 digit);
}
optional ("-time", optional "s");
} or {
"optional";
} or {
"repeat";
}`,
},
{
scope: 'name',
begin: cre`[a-zA-Z_], repeat [a-zA-Z0-9_], ":"`,
},
{
scope: 'string',
begin: /"/,
end: /"/,
contains: [
{ begin: cre`"\\", any` },
{ scope: 'subst', begin: /\${/, end: /}/ },
],
},
{
scope: 'string',
begin: /'/,
end: /'/,
contains: [
{ begin: cre`"\\", any` },
{ scope: 'subst', begin: /\${/, end: /}/ },
],
},
{
scope: 'text',
begin: /</,
end: />/,
},
{
scope: 'regexp',
begin: /\[/,
end: /\]/,
contains: [
{ begin: cre`"\\", any` },
{ scope: 'subst', begin: /\${/, end: /}/ },
],
},
{
scope: 'subst',
begin: /\${/,
end: /}/,
},
{
scope: 'type',
begin: cre.ignoreCase`
{
("end" or "start" or "begin"), "-of-", ("text" or "line");
} or {
"word-bound", optional "ary";
} or {
"look", optional "-", ("ahead" or "behind");
}
`,
}
]
}
});
let js = hljs.getLanguage('javascript').rawDefinition();
console.log(js);
let jscre = {
...js,
aliases: [],
name: 'javascriptwithcre',
contains: [
{
begin: /cre(?:\.[a-zA-Z0-9_.]+)?`/,
end: /\B|\b/,
starts: {
begin: /\B|\b/,
end: '`',
terminatorEnd: "`",
subLanguage: "cre",
},
},
{
scope: 'regexp',
begin: cre`"/", lookahead not "/"`,
end: /\/[gimuvsy]*/,
contains: [
{ begin: cre`"\\", any` },
{
begin: /\[/,
end: /\]/,
contains: [
{ begin: cre`"\\", any` },
],
},
],
},
...js.contains,
],
}
hljs.registerLanguage('javascriptwithcre', () => jscre);
for (let element of document.getElementsByClassName('language-javascriptwithcre')) {
hljs.highlightElement(element);
}
for (let element of document.getElementsByClassName('language-bash')) {
hljs.highlightElement(element);
}
for (let element of document.getElementsByClassName('language-html')) {
hljs.highlightElement(element);
}
nextScript();
}

function nextScript() {
let x = 0;
function updateFeature() {
x++;
Expand Down
8 changes: 3 additions & 5 deletions docs/tmpl/index.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<script src="docs.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="index.js"></script>
<link rel="stylesheet" href="index.css">
</head>
Expand All @@ -34,13 +32,13 @@
<div class="swiper-slide">
<div class="sample">
<a href="<%- sample.demoURL %>" target="cre-web-demo" class="try-it-button">▶&nbsp;&nbsp;Try it</a>
<pre class="sample-title language-javascriptwithcre">// <%- sample.title %></pre>
<pre class="sample-title language-javascriptwithcre"><%= removeTopLevelTag(sample.title) %></pre>
<div class="sample-part">Classic</div>
<pre
class="sample-code language-javascriptwithcre"><%- sample.regexp %></pre>
class="sample-code language-javascriptwithcre"><%= removeTopLevelTag(sample.regexp) %></pre>

<div class="sample-part">Convenient Regular Expressions</div>
<pre class="sample-code language-javascriptwithcre"><%- sample.code %></pre>
<pre class="sample-code language-javascriptwithcre"><%= removeTopLevelTag(sample.code) %></pre>
</div>
</div>
<% } %>
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"prebuild": "npx esbuild --target=chrome62,edge79,firefox53,safari11 --bundle --global-name=GtEa1M6 --sourcemap=linked --minify src/con-reg-exp.ts --outfile=dist/browser/con-reg-exp.min.js && npx esbuild --target=chrome62,edge79,firefox53,safari11 --bundle --global-name=GtEa1M6 --sourcemap=linked src/con-reg-exp.ts --outfile=dist/browser/con-reg-exp.js",
"build": "npx tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json",
"postbuild": "npx ts-node --swc scripts/postbuild.ts",
"prebuild-web": "npx ts-node --swc scripts/build-docs.ts",
"build-web": "npx ts-node --swc scripts/build-web-index.ts",
"build-web": "npx tsx scripts/build-web/build.ts",
"test": "npm run test-unit run && npm run test-imports",
"test-unit": "npx vitest",
"test-imports": "npx ts-node --swc test/test-imports/run-test.ts"
Expand Down
Loading

0 comments on commit b96f887

Please sign in to comment.