Skip to content

Commit 181f264

Browse files
author
Nikos M
committed
v.2.6.0, minor changes
1 parent 69cc551 commit 181f264

File tree

6 files changed

+49
-26
lines changed

6 files changed

+49
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ var xml_mode = PrismGrammar.getMode( xml_grammar );
128128
// output escaped html code, to work properly (Prism.version 1.2.0+)
129129
xml_mode.escapeHtml = true;
130130

131-
// 3. use it with Prism for
132-
xml_mode.hook( Prism, "xml" );
131+
// 3. use it with Prism
132+
xml_mode.hook( "xml", Prism );
133133

134134
// mode can be unhooked also
135135
// xml_mode.unhook();

build/prism_grammar.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,16 +3224,19 @@ var PrismParser = Class(Parser, {
32243224
}
32253225
});
32263226

3227-
function get_mode( grammar )
3227+
3228+
function esc_token( i, tokens )
3229+
{
3230+
var t = tokens[i];
3231+
if ( t.content ) t.content = esc_html( t.content, 1 );
3232+
else t = esc_html( t, 1 );
3233+
tokens[i] = t;
3234+
}
3235+
3236+
function get_mode( grammar, Prism )
32283237
{
3229-
var prism_highlighter, is_hooked = 0, $Prism$,
3238+
var prism_highlighter, is_hooked = 0, $Prism$ = Prism,
32303239

3231-
esc_token = function( i, tokens ) {
3232-
var t = tokens[i];
3233-
if ( t.content ) t.content = esc_html( t.content, 1 );
3234-
else t = esc_html( t, 1 );
3235-
tokens[i] = t;
3236-
},
32373240
highlighter$ = {
32383241
'before-highlight': function( env ) {
32393242
// use the custom parser for the grammar to highlight
@@ -3268,16 +3271,24 @@ function get_mode( grammar )
32683271
,$parser: new PrismGrammar.Parser( parse_grammar( grammar ) )
32693272

32703273
,$lang: null
3274+
32713275
// have escapeHtml flag true by default
32723276
,escapeHtml: true
32733277

32743278
// TODO: a way to highlight in worker (like default prism async flag)
32753279
// post a request to prism repository?????
32763280
,$async: false
32773281

3278-
,hook: function( Prism, language ) {
3282+
,hook: function( language, Prism ) {
32793283
if ( is_hooked ) prism_highlighter.unhook();
3280-
$Prism$ = Prism;
3284+
if ( T_STR & get_type(Prism) )
3285+
{
3286+
// arguments given in different order
3287+
var tmp = language;
3288+
language = Prism;
3289+
Prism = tmp;
3290+
}
3291+
$Prism$ = Prism || $Prism$;
32813292
prism_highlighter.$lang = language;
32823293
for (var hook in highlighter$ )
32833294
{

build/prism_grammar.min.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ var PrismParser = Class(Parser, {
5353
}
5454
});
5555

56-
function get_mode( grammar )
56+
57+
function esc_token( i, tokens )
58+
{
59+
var t = tokens[i];
60+
if ( t.content ) t.content = esc_html( t.content, 1 );
61+
else t = esc_html( t, 1 );
62+
tokens[i] = t;
63+
}
64+
65+
function get_mode( grammar, Prism )
5766
{
58-
var prism_highlighter, is_hooked = 0, $Prism$,
67+
var prism_highlighter, is_hooked = 0, $Prism$ = Prism,
5968

60-
esc_token = function( i, tokens ) {
61-
var t = tokens[i];
62-
if ( t.content ) t.content = esc_html( t.content, 1 );
63-
else t = esc_html( t, 1 );
64-
tokens[i] = t;
65-
},
6669
highlighter$ = {
6770
'before-highlight': function( env ) {
6871
// use the custom parser for the grammar to highlight
@@ -97,16 +100,24 @@ function get_mode( grammar )
97100
,$parser: new PrismGrammar.Parser( parse_grammar( grammar ) )
98101

99102
,$lang: null
103+
100104
// have escapeHtml flag true by default
101105
,escapeHtml: true
102106

103107
// TODO: a way to highlight in worker (like default prism async flag)
104108
// post a request to prism repository?????
105109
,$async: false
106110

107-
,hook: function( Prism, language ) {
111+
,hook: function( language, Prism ) {
108112
if ( is_hooked ) prism_highlighter.unhook();
109-
$Prism$ = Prism;
113+
if ( T_STR & get_type(Prism) )
114+
{
115+
// arguments given in different order
116+
var tmp = language;
117+
language = Prism;
118+
Prism = tmp;
119+
}
120+
$Prism$ = Prism || $Prism$;
110121
prism_highlighter.$lang = language;
111122
for (var hook in highlighter$ )
112123
{

test/demo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function prism_grammar_demo(code, lang, grammar, escapeHtml)
33
document.getElementById('editor-version').innerHTML = '1.2.0';
44
document.getElementById('grammar-version').innerHTML = PrismGrammar.VERSION;
55
var mode = PrismGrammar.getMode( grammar );
6-
mode.escapeHtml = !!escapeHtml; // whether to escape html code to output properly, Prism.version 1.2.0+
7-
mode.hook( Prism, lang );
6+
mode.escapeHtml = true; // whether to escape html code to output properly, Prism.version 1.2.0+
7+
mode.hook( lang, Prism );
88
Prism.highlightElement( code );
99
}

test/grammar-xml.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h3>Prism (v.<span id="editor-version">0</span>) Grammar (v.<span id="grammar-ve
6565

6666
<script>
6767
// <![CDATA[
68-
prism_grammar_demo(document.getElementById('code'), "markup", xml_grammar, true /*html-ecsape output code*/);
68+
prism_grammar_demo(document.getElementById('code'), "markup", xml_grammar);
6969
// ]]>
7070
</script>
7171
</body>

0 commit comments

Comments
 (0)