@@ -54,9 +54,12 @@ var defaults = {
54
54
xmlns : "mml" , // the namespace to use for MathML
55
55
56
56
html : false , // return HTML output?
57
+ htmlNode : false , // DOM element for HTML output?
57
58
css : false , // return CSS for HTML output?
58
59
mml : false , // return mml output?
60
+ mmlNode : false , // DOM element for MML output?
59
61
svg : false , // return svg output?
62
+ svgNode : false , // DOM element for SVG output?
60
63
61
64
speakText : false , // add spoken annotations to svg output?
62
65
speakRuleset : "mathspeak" , // set speech ruleset (default (chromevox rules), mathspeak)
@@ -517,9 +520,12 @@ function AddError(message,nopush) {
517
520
// into account)
518
521
//
519
522
function GetMML ( result ) {
520
- if ( ! data . mml && ! data . speakText && ! data . semantic ) return ;
523
+ if ( ! data . mml && ! data . mmlNode && ! data . speakText && ! data . semantic ) return ;
521
524
var jax = MathJax . Hub . getAllJax ( ) [ 0 ] ;
522
- try { result . mml = jax . root . toMathML ( '' , jax ) } catch ( err ) {
525
+ try {
526
+ if ( data . mml ) result . mml = jax . root . toMathML ( '' , jax ) ;
527
+ if ( data . mmlNode ) result . mmlNode = jsdom ( result . mml ) . body . firstChild ;
528
+ } catch ( err ) {
523
529
if ( ! err . restart ) { throw err ; } // an actual error
524
530
return MathJax . Callback . After ( window . Array ( GetMML , result ) , err . restart ) ;
525
531
}
@@ -557,7 +563,7 @@ function GetSemantic(result) {
557
563
// Create HTML and CSS output, if requested
558
564
//
559
565
function GetHTML ( result ) {
560
- if ( ! data . html ) return ;
566
+ if ( ! data . html && ! data . htmlNode ) return ;
561
567
var jax = MathJax . Hub . getAllJax ( ) [ 0 ] ; if ( ! jax ) return ;
562
568
var script = jax . SourceElement ( ) , html = script . previousSibling ;
563
569
@@ -584,15 +590,16 @@ function GetHTML(result) {
584
590
// otherwise (inline-mode) the frame is the root element
585
591
html . removeAttribute ( "id" ) ;
586
592
}
587
- result . html = html . outerHTML ;
593
+ if ( data . html ) result . html = html . outerHTML ;
594
+ if ( data . htmlNode ) result . htmlNode = html ;
588
595
if ( data . css ) result . css = CHTMLSTYLES ;
589
596
}
590
597
591
598
//
592
599
// Create SVG output, if requested
593
600
//
594
601
function GetSVG ( result ) {
595
- if ( ! data . svg ) return ;
602
+ if ( ! data . svg && ! data . svgNode ) return ;
596
603
var jax = MathJax . Hub . getAllJax ( ) [ 0 ] ; if ( ! jax ) return ;
597
604
var script = jax . SourceElement ( ) ,
598
605
svg = script . previousSibling . getElementsByTagName ( "svg" ) [ 0 ] ;
@@ -613,22 +620,24 @@ function GetSVG(result) {
613
620
svg . insertBefore ( node , svg . firstChild ) ;
614
621
}
615
622
616
- //
617
- // SVG data is modified to add linebreaks for readability,
618
- // and to put back the xlink namespace that is removed in HTML5
619
- //
620
- var svgdata = svg . outerHTML . replace ( / > < ( [ ^ / ] ) / g, ">\n<$1" )
621
- . replace ( / ( < \/ [ a - z ] * > ) (? = < \/ ) / g, "$1\n" )
622
- . replace ( / ( < (?: u s e | i m a g e ) [ ^ > ] * ) ( h r e f = ) / g, ' $1xlink:$2' ) ;
623
+ if ( data . svg ) {
624
+ //
625
+ // SVG data is modified to add linebreaks for readability,
626
+ // and to put back the xlink namespace that is removed in HTML5
627
+ //
628
+ var svgdata = svg . outerHTML . replace ( / > < ( [ ^ / ] ) / g, ">\n<$1" )
629
+ . replace ( / ( < \/ [ a - z ] * > ) (? = < \/ ) / g, "$1\n" )
630
+ . replace ( / ( < (?: u s e | i m a g e ) [ ^ > ] * ) ( h r e f = ) / g, ' $1xlink:$2' ) ;
623
631
624
- //
625
- // Add the requested data to the results
626
- //
627
- result . svg = svgdata ;
632
+ //
633
+ // Add the requested data to the results
634
+ //
635
+ result . svg = svgdata ;
636
+ }
637
+ if ( data . svgNode ) result . svgNode = svg ;
628
638
result . width = svg . getAttribute ( "width" ) ;
629
639
result . height = svg . getAttribute ( "height" ) ;
630
640
result . style = svg . style . cssText ;
631
-
632
641
}
633
642
634
643
/********************************************************************/
0 commit comments