Skip to content

Commit

Permalink
More variables for better code compression (#1489)
Browse files Browse the repository at this point in the history
This introduces more variables for better code compression in a few languages.
  • Loading branch information
RunDevelopment authored Mar 10, 2019
1 parent 70a4041 commit bc53e09
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 220 deletions.
81 changes: 21 additions & 60 deletions components/prism-asciidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
'attr-value': /(?!^\s+$).+/
}
};
Prism.languages.asciidoc = {

var asciidoc = Prism.languages.asciidoc = {
'comment-block': {
pattern: /^(\/{4,})(?:\r?\n|\r)(?:[\s\S]*(?:\r?\n|\r))??\1/m,
alias: 'comment'
Expand Down Expand Up @@ -199,75 +200,35 @@

// Allow some nesting. There is no recursion though, so cloning should not be needed.

attributes.inside['interpreted'].inside.rest = {
'macro': Prism.languages.asciidoc['macro'],
'inline': Prism.languages.asciidoc['inline'],
'replacement': Prism.languages.asciidoc['replacement'],
'entity': Prism.languages.asciidoc['entity']
};
function copyFromAsciiDoc(keys) {
keys = keys.split(' ');

Prism.languages.asciidoc['passthrough-block'].inside.rest = {
'macro': Prism.languages.asciidoc['macro']
};
var o = {};
for (var i = 0, l = keys.length; i < l; i++) {
o[keys[i]] = asciidoc[keys[i]];
}
return o;
}

Prism.languages.asciidoc['literal-block'].inside.rest = {
'callout': Prism.languages.asciidoc['callout']
};
attributes.inside['interpreted'].inside.rest = copyFromAsciiDoc('macro inline replacement entity');

Prism.languages.asciidoc['table'].inside.rest = {
'comment-block': Prism.languages.asciidoc['comment-block'],
'passthrough-block': Prism.languages.asciidoc['passthrough-block'],
'literal-block': Prism.languages.asciidoc['literal-block'],
'other-block': Prism.languages.asciidoc['other-block'],
'list-punctuation': Prism.languages.asciidoc['list-punctuation'],
'indented-block': Prism.languages.asciidoc['indented-block'],
'comment': Prism.languages.asciidoc['comment'],
'title': Prism.languages.asciidoc['title'],
'attribute-entry': Prism.languages.asciidoc['attribute-entry'],
'attributes': Prism.languages.asciidoc['attributes'],
'hr': Prism.languages.asciidoc['hr'],
'page-break': Prism.languages.asciidoc['page-break'],
'admonition': Prism.languages.asciidoc['admonition'],
'list-label': Prism.languages.asciidoc['list-label'],
'callout': Prism.languages.asciidoc['callout'],
'macro': Prism.languages.asciidoc['macro'],
'inline': Prism.languages.asciidoc['inline'],
'replacement': Prism.languages.asciidoc['replacement'],
'entity': Prism.languages.asciidoc['entity'],
'line-continuation': Prism.languages.asciidoc['line-continuation']
};
asciidoc['passthrough-block'].inside.rest = copyFromAsciiDoc('macro');

Prism.languages.asciidoc['other-block'].inside.rest = {
'table': Prism.languages.asciidoc['table'],
'list-punctuation': Prism.languages.asciidoc['list-punctuation'],
'indented-block': Prism.languages.asciidoc['indented-block'],
'comment': Prism.languages.asciidoc['comment'],
'attribute-entry': Prism.languages.asciidoc['attribute-entry'],
'attributes': Prism.languages.asciidoc['attributes'],
'hr': Prism.languages.asciidoc['hr'],
'page-break': Prism.languages.asciidoc['page-break'],
'admonition': Prism.languages.asciidoc['admonition'],
'list-label': Prism.languages.asciidoc['list-label'],
'macro': Prism.languages.asciidoc['macro'],
'inline': Prism.languages.asciidoc['inline'],
'replacement': Prism.languages.asciidoc['replacement'],
'entity': Prism.languages.asciidoc['entity'],
'line-continuation': Prism.languages.asciidoc['line-continuation']
};
asciidoc['literal-block'].inside.rest = copyFromAsciiDoc('callout');

asciidoc['table'].inside.rest = copyFromAsciiDoc('comment-block passthrough-block literal-block other-block list-punctuation indented-block comment title attribute-entry attributes hr page-break admonition list-label callout macro inline replacement entity line-continuation');

asciidoc['other-block'].inside.rest = copyFromAsciiDoc('table list-punctuation indented-block comment attribute-entry attributes hr page-break admonition list-label macro inline replacement entity line-continuation');

asciidoc['title'].inside.rest = copyFromAsciiDoc('macro inline replacement entity');

Prism.languages.asciidoc['title'].inside.rest = {
'macro': Prism.languages.asciidoc['macro'],
'inline': Prism.languages.asciidoc['inline'],
'replacement': Prism.languages.asciidoc['replacement'],
'entity': Prism.languages.asciidoc['entity']
};

// Plugin to make entity title show the real entity, idea by Roman Komarov
Prism.hooks.add('wrap', function(env) {
Prism.hooks.add('wrap', function (env) {
if (env.type === 'entity') {
env.attributes['title'] = env.content.replace(/&amp;/, '&');
}
});

Prism.languages.adoc = Prism.languages.asciidoc;
}(Prism));
2 changes: 1 addition & 1 deletion components/prism-asciidoc.min.js

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

136 changes: 71 additions & 65 deletions components/prism-parser.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,73 @@
Prism.languages.parser = Prism.languages.extend('markup', {
'keyword': {
pattern: /(^|[^^])(?:\^(?:case|eval|for|if|switch|throw)\b|@(?:BASE|CLASS|GET(?:_DEFAULT)?|OPTIONS|SET_DEFAULT|USE)\b)/,
lookbehind: true
},
'variable': {
pattern: /(^|[^^])\B\$(?:\w+|(?=[.{]))(?:(?:\.|::?)\w+)*(?:\.|::?)?/,
lookbehind: true,
inside: {
'punctuation': /\.|:+/
(function (Prism) {

var parser = Prism.languages.parser = Prism.languages.extend('markup', {
'keyword': {
pattern: /(^|[^^])(?:\^(?:case|eval|for|if|switch|throw)\b|@(?:BASE|CLASS|GET(?:_DEFAULT)?|OPTIONS|SET_DEFAULT|USE)\b)/,
lookbehind: true
},
'variable': {
pattern: /(^|[^^])\B\$(?:\w+|(?=[.{]))(?:(?:\.|::?)\w+)*(?:\.|::?)?/,
lookbehind: true,
inside: {
'punctuation': /\.|:+/
}
},
'function': {
pattern: /(^|[^^])\B[@^]\w+(?:(?:\.|::?)\w+)*(?:\.|::?)?/,
lookbehind: true,
inside: {
'keyword': {
pattern: /(^@)(?:GET_|SET_)/,
lookbehind: true
},
'punctuation': /\.|:+/
}
},
'escape': {
pattern: /\^(?:[$^;@()\[\]{}"':]|#[a-f\d]*)/i,
alias: 'builtin'
},
'punctuation': /[\[\](){};]/
});

parser = Prism.languages.insertBefore('parser', 'keyword', {
'parser-comment': {
pattern: /(\s)#.*/,
lookbehind: true,
alias: 'comment'
},
'expression': {
// Allow for 3 levels of depth
pattern: /(^|[^^])\((?:[^()]|\((?:[^()]|\((?:[^()])*\))*\))*\)/,
greedy: true,
lookbehind: true,
inside: {
'string': {
pattern: /(^|[^^])(["'])(?:(?!\2)[^^]|\^[\s\S])*\2/,
lookbehind: true
},
'keyword': parser.keyword,
'variable': parser.variable,
'function': parser.function,
'boolean': /\b(?:true|false)\b/,
'number': /\b(?:0x[a-f\d]+|\d+\.?\d*(?:e[+-]?\d+)?)\b/i,
'escape': parser.escape,
'operator': /[~+*\/\\%]|!(?:\|\|?|=)?|&&?|\|\|?|==|<[<=]?|>[>=]?|-[fd]?|\b(?:def|eq|ge|gt|in|is|le|lt|ne)\b/,
'punctuation': parser.punctuation
}
}
},
'function': {
pattern: /(^|[^^])\B[@^]\w+(?:(?:\.|::?)\w+)*(?:\.|::?)?/,
lookbehind: true,
inside: {
'keyword': {
pattern: /(^@)(?:GET_|SET_)/,
lookbehind: true
},
'punctuation': /\.|:+/
});

parser = Prism.languages.insertBefore('inside', 'punctuation', {
'expression': parser.expression,
'keyword': parser.keyword,
'variable': parser.variable,
'function': parser.function,
'escape': parser.escape,
'parser-punctuation': {
pattern: parser.punctuation,
alias: 'punctuation'
}
},
'escape': {
pattern: /\^(?:[$^;@()\[\]{}"':]|#[a-f\d]*)/i,
alias: 'builtin'
},
'punctuation': /[\[\](){};]/
});
Prism.languages.insertBefore('parser', 'keyword', {
'parser-comment': {
pattern: /(\s)#.*/,
lookbehind: true,
alias: 'comment'
},
'expression': {
// Allow for 3 levels of depth
pattern: /(^|[^^])\((?:[^()]|\((?:[^()]|\((?:[^()])*\))*\))*\)/,
greedy: true,
lookbehind: true,
inside: {
'string': {
pattern: /(^|[^^])(["'])(?:(?!\2)[^^]|\^[\s\S])*\2/,
lookbehind: true
},
'keyword': Prism.languages.parser.keyword,
'variable': Prism.languages.parser.variable,
'function': Prism.languages.parser.function,
'boolean': /\b(?:true|false)\b/,
'number': /\b(?:0x[a-f\d]+|\d+\.?\d*(?:e[+-]?\d+)?)\b/i,
'escape': Prism.languages.parser.escape,
'operator': /[~+*\/\\%]|!(?:\|\|?|=)?|&&?|\|\|?|==|<[<=]?|>[>=]?|-[fd]?|\b(?:def|eq|ge|gt|in|is|le|lt|ne)\b/,
'punctuation': Prism.languages.parser.punctuation
}
}
});
Prism.languages.insertBefore('inside', 'punctuation', {
'expression': Prism.languages.parser.expression,
'keyword': Prism.languages.parser.keyword,
'variable': Prism.languages.parser.variable,
'function': Prism.languages.parser.function,
'escape': Prism.languages.parser.escape,
'parser-punctuation': {
pattern: Prism.languages.parser.punctuation,
alias: 'punctuation'
}
}, Prism.languages.parser['tag'].inside['attr-value']);
}, parser['tag'].inside['attr-value']);

}(Prism));
Loading

0 comments on commit bc53e09

Please sign in to comment.