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

Tools global highlighter #12

Merged
merged 2 commits into from
May 19, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const argsRegex = new RegExp(/\-{1,2}[a-zA-Z-]*/, 'ig')
// Make sure the $ part of the command prompt in shell
// examples isn't copiable by making it an 'input' token.
Prism.hooks.add('after-tokenize', env => {
if (['dvc', 'cml'].includes(env.language) && Array.isArray(env.tokens)) {
if (['dvc', 'cli'].includes(env.language) && Array.isArray(env.tokens)) {
for (const token of env.tokens) {
if (token.type === 'line' && /^\$\s+$/.test(token.content[0])) {
const old = token.content[0]
Expand Down
27 changes: 8 additions & 19 deletions packages/gatsby-theme-iterative/config/prismjs/dvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { bash } = Prism.languages

const dvc = require('./dvc-commands')
const cml = require('./cml-commands')
const mlem = require('./mlem-commands')

// Command arrays are intentionally reverse sorted
// to prevent shorter matches before longer ones
Expand All @@ -35,7 +36,7 @@ const git = [

const beforeCommand = String.raw`(\$[\s(]+|;\s*)`

Prism.languages.dvc = {
Prism.languages.cli = {
line: {
pattern: /(?<=(^|\n))\$[\s\S]*?[^\\](:?\n|$)/,
inside: {
Expand All @@ -46,30 +47,16 @@ Prism.languages.dvc = {
greedy: true,
lookbehind: true
},
git: {
cml: {
pattern: new RegExp(
String.raw`${beforeCommand}\b(?:git (?:${git.join('|')}))\b`
String.raw`${beforeCommand}\b(?:cml (?:${cml.join('|')}))\b`
),
greedy: true,
lookbehind: true
},
command: {
pattern: new RegExp(String.raw`${beforeCommand}\b[a-zA-Z0-9\-_]+\b`),
greedy: true,
lookbehind: true
},
...bash
}
},
comment: bash.comment
}
Prism.languages.cml = {
line: {
pattern: /(?<=(^|\n))\$[\s\S]*?[^\\](:?\n|$)/,
inside: {
cml: {
mlem: {
pattern: new RegExp(
String.raw`${beforeCommand}\b(?:cml (?:${cml.join('|')}))\b`
String.raw`${beforeCommand}\b(?:mlem (?:${mlem.join('|')}))\b`
),
greedy: true,
lookbehind: true
Expand All @@ -91,3 +78,5 @@ Prism.languages.cml = {
},
comment: bash.comment
}

Prism.languages.dvc = Prism.languages.cli
14 changes: 14 additions & 0 deletions packages/gatsby-theme-iterative/config/prismjs/mlem-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = [
'init',
'list',
'pprint',
'create',
'serve',
'deploy',
'types',
'link',
'clone',
'import',
'pack',
'apply'
]
4 changes: 4 additions & 0 deletions packages/gatsby-theme-iterative/config/prismjs/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const dvc = require('./dvc-commands')
const cml = require('./cml-commands')
const mlem = require('./mlem-commands')
const Prism = require('prismjs')

Prism.languages.usage = {
Expand All @@ -11,6 +12,9 @@ Prism.languages.usage = {
cml: {
pattern: new RegExp(`cml (?:${cml.join('|')})`)
},
mlem: {
pattern: new RegExp(`mlem (?:${mlem.join('|')})`)
},
usage: {
pattern: /(^|\n)\s*(usage|positional arguments|optional arguments)/
},
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-theme-iterative/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ module.exports = ({
options: {
icon: linkIcon,
// Pathname can also be array of paths. eg: ['docs/command-reference;', 'docs/api']
pathname: ['docs/command-reference', `docs/ref`]
pathname: [
'docs/command-reference',
`docs/ref`,
'docs/cli-reference'
]
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@
}

.token.dvc,
.token.cml {
.token.cml,
.token.mlem {
color: #56b1d0;
font-weight: bold;
}
Expand Down