Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Descriptiosn and a comment
  • Loading branch information
RunDevelopment committed May 17, 2020
commit 959543b4871b0d20d6120f87b76884bafc172cdb
13 changes: 12 additions & 1 deletion scripts/download-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
*
* @typedef StringOptionItem
* @property {string} title
* @property {string} [desc]
* @property {"string"} type
* @property {string} [value]
* @property {string} [default='']
* @property {Validator<string>} [validate]
*
* @typedef NumberOptionItem
* @property {string} title
* @property {string} [desc]
* @property {"number"} type
* @property {number} [value]
* @property {number} [default=0]
* @property {Validator<number>} [validate]
*
* @typedef BooleanOptionItem
* @property {string} title
* @property {string} [desc]
* @property {"boolean"} type
* @property {boolean} [value]
* @property {boolean} [default=false]
Expand Down Expand Up @@ -60,6 +63,7 @@ var downloadOptions = [];
items: {
manual: {
title: 'Manual highlighting',
desc: 'Manual highlighting means that Prism will not highlight all code snippets and code blocks automatically. To highlight elements, you have to explicitly call Prism\'s highlight functions.',
type: 'boolean'
}
},
Expand All @@ -76,7 +80,8 @@ var downloadOptions = [];
require: 'custom-class',
items: {
prefix: {
title: 'Theme prefix',
title: 'Class prefix',
desc: 'The classes of all tokens produced by Prism will have the given prefix.',
type: 'string',
validate: matchRegExp(/^(?:[a-z][\w-]*)?$/)
}
Expand All @@ -97,6 +102,12 @@ var downloadOptions = [];
if (t.type === 'selector') {
var selector = stringify(t.content);

// The idea behind this regex is as follows:
// We have to detect all elements that have a `.token` class and change all classes of any such
// element. To do this, we search for all `.token` classes and include all surrounding component
// selectors as well. I.e. For the selector `code.style #id.token.foo:not(.bar)`, the text
// `#id.token.foo:not(.bar)` will be matched. We can then trivially detect all classes by the `.`
// prefix.
selector = selector.replace(/[-\w.#:()]*\.token(?![-\w])[-\w.#:()]*/g, function (m) {
return m.replace(/\.([\w-]+)/g, function (m, g1) {
return '.' + prefix + g1;
Expand Down
6 changes: 6 additions & 0 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ function addDownloadOptionsToDOM() {
contents: [
{
tag: 'span',
attributes: {
'title': item.desc || ''
},
contents: item.title
},
{
Expand All @@ -772,6 +775,9 @@ function addDownloadOptionsToDOM() {
contents.push(
{
tag: 'span',
attributes: {
'title': item.desc || ''
},
contents: item.title
},
{
Expand Down