#3311 closed enhancement (fixed)
Enable loading JS globally when inside the info annotation of package.mo
Reported by: | dietmarw | Owned by: | adeas31 |
---|---|---|---|
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 Changed 9 years ago by dietmarw
- Keywords MathJax added
comment:2 Changed 9 years ago by sjoelund.se
- Owner set to adeas31
- Status changed from new to assigned
comment:3 Changed 9 years ago by dietmarw
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 Changed 9 years ago by adeas31
- Resolution set to fixed
- Status changed from assigned to closed
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 Changed 9 years ago by adeas31
- Milestone changed from Future to 1.9.4
comment:6 Changed 9 years ago by dietmarw
Very nice, thanks!
comment:7 Changed 9 years ago by dietmarw
Where would one best document this feature? Any suggestions into which section to add this?
comment:8 Changed 9 years ago by adeas31
comment:9 follow-up: ↓ 11 Changed 9 years ago by dietmarw
- Resolution fixed deleted
- Status changed from closed to reopened
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.
comment:10 Changed 9 years ago by dietmarw
There are actually more problems with the implementation. Even when not relying on load from local resource (#2499) 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.
comment:11 in reply to: ↑ 9 Changed 9 years ago by adeas31
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 Changed 9 years ago by adeas31
- Resolution set to fixed
- Status changed from reopened to closed
Fixed in c6988d4/OMEdit.
All the above three examples are working now.
comment:13 Changed 9 years ago by dietmarw
- Resolution fixed deleted
- Status changed from closed to reopened
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 Changed 9 years ago by dietmarw
- Resolution set to fixed
- Status changed from reopened to closed
My bad. Seems I was still running an older version. Fix confirmed.
comment:15 Changed 8 years ago by sjoelund.se
- Milestone changed from 1.9.4 to 1.9.4-1.9.x
Milestone renamed
comment:16 Changed 8 years ago by sjoelund.se
- Milestone changed from 1.9.4-1.9.x to 1.9.4
Milestone renamed
Or possibly some other way, like Documentation(__OpenModelica_infoHeader=...). Or just allowing OMEdit to specify it globally in a config setting.