File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1212< body >
1313 < div id ="input " class ="editor language-mathjs "> </ div >
1414 < div id ="output " class ="editor language-mathjs "> </ div >
15+ < div id ="help " style ="display: none ">
16+ < h1 id ="help_name "> </ h1 >
17+ < p id ="help_description "> </ p >
18+ < h2 > Syntax</ h2 >
19+ < pre > < code id ="help_syntax " class ="language-mathjs "> </ code > </ pre >
20+ < h2 > Examples</ h2 >
21+ < pre > < code id ="help_examples " class ="language-mathjs "> </ code > </ pre >
22+ < h2 > See also</ h2 >
23+ < p id ="help_seealso "> </ p >
24+ </ div >
1525</ body >
1626
1727< script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js "> </ script >
Original file line number Diff line number Diff line change 11const wait = 100 ;
22
3+ function showDoc ( doc ) {
4+ if ( ! doc ) {
5+ help . style . display = 'none' ;
6+ return ;
7+ }
8+
9+ help_name . textContent = doc . name ;
10+ help_description . textContent = doc . description ;
11+ help_syntax . textContent = doc . syntax . join ( "\n" ) ;
12+ hljs . highlightElement ( help_syntax ) ;
13+ help_examples . textContent = doc . examples . join ( "\n" ) ;
14+ hljs . highlightElement ( help_examples ) ;
15+ help_seealso . textContent = doc . seealso . join ( ", " ) ;
16+ help . style . display = 'block' ;
17+ }
18+
319function doMath ( input ) {
420 let output = [ ] ;
521 let scope = { } ;
22+ let doc ;
623
724 for ( const line of input . split ( '\n' ) ) {
825 let output_line = '' ;
@@ -11,7 +28,9 @@ function doMath(input) {
1128 output_line = line ;
1229 } else {
1330 try {
14- output_line = math . format ( math . evaluate ( line , scope ) , 14 ) ;
31+ const r = math . evaluate ( line , scope ) ;
32+ if ( r . doc ) doc = r . doc ;
33+ else output_line = math . format ( r , 14 ) ;
1534 } catch ( e ) {
1635 output_line = e . toString ( ) ;
1736 }
@@ -21,6 +40,7 @@ function doMath(input) {
2140 }
2241
2342 results . updateCode ( output . join ( '\n' ) ) ;
43+ showDoc ( doc ) ;
2444}
2545
2646var timer ;
Original file line number Diff line number Diff line change @@ -21,6 +21,21 @@ body {
2121 background-color : hsl (240 , 6.25% , 12.5% );
2222}
2323
24+ # help {
25+ font-family : sans-serif;
26+ flex : 1 ;
27+ padding : 8px ;
28+ }
29+
30+ h1 , h2 {
31+ font-size : 1.2em ;
32+ margin-top : 1em ;
33+ }
34+
35+ h1 {
36+ font-size : 1.4em ;
37+ }
38+
2439.hljs-class {
2540 font-weight : bold;
2641}
You can’t perform that action at this time.
0 commit comments