Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#3311 closed enhancement (fixed)

Enable loading JS globally when inside the info annotation of package.mo

Reported by: Dietmar Winkler Owned by: Adeel Asghar
Priority: high Milestone: 1.9.4
Component: OMEdit Version: trunk
Keywords: MathJax Cc:

Description

I have the use case that I like to use MathJax in the documentation of my models. Now this functionality was implemented as part of #1809 and the request for a global <script>...</script> was part of #2490 but unfortunately overlooked.

What I think would be ideal is that if one has some <script>...</script> inside the top-level package.mo then that script would be loaded for the rendering of all documentation annotations of all the classes in that package.

That we I could define

annotation(Documentation(info="<html>
<script type=\"text/javascript\"
 src=\"https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\">
 </script>
</html>"));

once and be done with it.

Change History (16)

comment:1 by Dietmar Winkler, 10 years ago

Keywords: MathJax added

comment:2 by Martin Sjölund, 10 years ago

Owner: set to Adeel Asghar
Status: newassigned

Or possibly some other way, like Documentation(__OpenModelica_infoHeader=...). Or just allowing OMEdit to specify it globally in a config setting.

comment:3 by Dietmar Winkler, 10 years ago

Both solutions would be fine, though the annotation would allow to store the setting with the library rather than the local OMEdit instance. So I would probably prefer that.

comment:4 by Adeel Asghar, 9 years ago

Resolution: fixed
Status: assignedclosed

Done in 8eeaa19/OMEdit.

Now you can create models like this,

package P
  model M
    annotation(Documentation(info="<html>
      <a href=\"javascript:HelloWorld()\">Click here</a>
    </HTML>"));
  end M;
  annotation(Documentation(__OpenModelica_infoHeader="<script type=\"text/javascript\">
    function HelloWorld() {
      alert(\"Hello World!\");
    }
  </script>"));
end P;

Anything defined in __OpenModelica_infoHeader will be added in the <head> section of the nested class html documentation.

comment:5 by Adeel Asghar, 9 years ago

Milestone: Future1.9.4

comment:6 by Dietmar Winkler, 9 years ago

Very nice, thanks!

comment:7 by Dietmar Winkler, 9 years ago

Where would one best document this feature? Any suggestions into which section to add this?

comment:9 by Dietmar Winkler, 9 years ago

Resolution: fixed
Status: closedreopened

Unfortunately the now the functionality of #2490 is broken. Taking your example:

  • hello.js:
    function HelloWorld() {
          alert(\"Hello World!\");
    
  • P.mo:
    package P
      model M
        annotation(Documentation(info="<html>
          <a href=\"javascript:HelloWorld()\">Click here</a>
        </HTML>"));
      end M;
     annotation(Documentation(__OpenModelica_infoHeader="
         <script type=\"text/javascript\" src=\"modelica://P/hello.js\">
         </script>"));
    end P;
    

Now the rendering of the documentation is completely broken. Inlining the script location directly does not help either. It's very important to keep the "load from local resource" functionality for proper independent library packaging.

Version 0, edited 9 years ago by Dietmar Winkler (next)

comment:10 by Dietmar Winkler, 9 years ago

There are actually more problems with the implementation. Even when not relying on load from local resource (#2490) then here is an example that works:

package P_FB
model FallbackTest
annotation(Documentation(info="<html>
  <script type=\"text/javascript\"
  src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\">
  </script>
 
  $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
  
</html>"));
end FallbackTest;
  annotation(Documentation(__OpenModelica_infoHeader=""));
end P_FB;

and one that does not work:

package P_FB
model FallbackTest
annotation(Documentation(info="<html>
  
  $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
  
</html>"));
end FallbackTest;
  annotation(Documentation(__OpenModelica_infoHeader="
   <script type=\"text/javascript\"
  src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\">
  </script>"));
end P_FB;

with the error message:

[46] 13:23:29 Scripting Notification
QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.
Last edited 9 years ago by Dietmar Winkler (previous) (diff)

in reply to:  9 comment:11 by Adeel Asghar, 9 years ago

Replying to dietmarw:

Unfortunately the now the functionality of #2490 is broken. Taking your example:

  • hello.js:
    function HelloWorld() {
          alert(\"Hello World!\");
    

There are problems with hello.js. The function's closing bracket is missing and there is no need to escaspe quotes here.

  • P.mo:
    package P
      model M
        annotation(Documentation(info="<html>
          <a href=\"javascript:HelloWorld()\">Click here</a>
        </html>"));
      end M;
     annotation(Documentation(__OpenModelica_infoHeader="
         <script type=\"text/javascript\" src=\"modelica://P/hello.js\">
         </script>"));
    end P;
    

Now the rendering of the documentation is completely broken. Inlining the script location directly does not help either. It's very important to keep the "load from local resource" functionality for proper independent library packaging.

comment:12 by Adeel Asghar, 9 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in c6988d4/OMEdit.

All the above three examples are working now.

comment:13 by Dietmar Winkler, 9 years ago

Resolution: fixed
Status: closedreopened

Sorry but loading from file still does not work :-( (I corrected my hello.js file).

I tried boths structures:

P
├── hello.js
└── package.mo

and

.
├── hello.js
└── P.mo

BTW shouldn't there be a function in OMEdit that one can save a single file lib into folder structure?

comment:14 by Dietmar Winkler, 9 years ago

Resolution: fixed
Status: reopenedclosed

My bad. Seems I was still running an older version. Fix confirmed.

comment:15 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:16 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.