Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline css by "mermaid" #157

Closed
maxmeyer opened this issue Apr 20, 2015 · 19 comments
Closed

Inline css by "mermaid" #157

maxmeyer opened this issue Apr 20, 2015 · 19 comments

Comments

@maxmeyer
Copy link

Hi there,

I'm trying to integrate mermaid into middleman-presentation - a gem which wraps reveal.js.

I'm installed mermaid via bower. Everytime I added the mermaid/dist/mermaid.full.js file to a presentation, the following inline css-styles appear:

/* <![CDATA[ */
#mermaidChart0 .node { fill:#ffa; stroke:#666; stroke-width:3px; }
#mermaidChart0 .node text  { fill:#000; stroke:none; font-weight:300; font-family:"Helvetica Neue",Helvetica,Arial,sans-serf; font-size:14px; }
#mermaidChart0 .edgeLabel text  { fill:#000; stroke:none; font-weight:300; font-family:"Helvetica Neue",Helvetica,Arial,sans-serf; font-size:14px; }
html, body, .reveal div, .reveal span, .reveal applet, .reveal object, .reveal iframe, .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6, .reveal p, .reveal blockquote, .reveal pre, .reveal a, .reveal abbr, .reveal acronym, .reveal address, .reveal big, .reveal cite, .reveal code, .reveal del, .reveal dfn, .reveal em, .reveal img, .reveal ins, .reveal kbd, .reveal q, .reveal s, .reveal samp, .reveal small, .reveal strike, .reveal strong, .reveal sub, .reveal sup, .reveal tt, .reveal var, .reveal b, .reveal u, .reveal center, .reveal dl, .reveal dt, .reveal dd, .reveal ol, .reveal ul, .reveal li, .reveal fieldset, .reveal form, .reveal label, .reveal legend, .reveal table, .reveal caption, .reveal tbody, .reveal tfoot, .reveal thead, .reveal tr, .reveal th, .reveal td, .reveal article, .reveal aside, .reveal canvas, .reveal details, .reveal embed, .reveal figure, .reveal figcaption, .reveal footer, .reveal header, .reveal hgroup, .reveal menu, .reveal nav, .reveal output, .reveal ruby, .reveal section, .reveal summary, .reveal time, .reveal mark, .reveal audio, video { margin: 0px; padding: 0px; border: 0px none; font: inherit; vertical-align: baseline; }
/* ]]> */

The last line of the inline css is a problem for me, because it overwrites my styles for H1, H2 etc.

html, body, .reveal div, .reveal span, .reveal applet, .reveal object, .reveal iframe, .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6, .reveal p, .reveal blockquote, .reveal pre, .reveal a, .reveal abbr, .reveal acronym, .reveal address, .reveal big, .reveal cite, .reveal code, .reveal del, .reveal dfn, .reveal em, .reveal img, .reveal ins, .reveal kbd, .reveal q, .reveal s, .reveal samp, .reveal small, .reveal strike, .reveal strong, .reveal sub, .reveal sup, .reveal tt, .reveal var, .reveal b, .reveal u, .reveal center, .reveal dl, .reveal dt, .reveal dd, .reveal ol, .reveal ul, .reveal li, .reveal fieldset, .reveal form, .reveal label, .reveal legend, .reveal table, .reveal caption, .reveal tbody, .reveal tfoot, .reveal thead, .reveal tr, .reveal th, .reveal td, .reveal article, .reveal aside, .reveal canvas, .reveal details, .reveal embed, .reveal figure, .reveal figcaption, .reveal footer, .reveal header, .reveal hgroup, .reveal menu, .reveal nav, .reveal output, .reveal ruby, .reveal section, .reveal summary, .reveal time, .reveal mark, .reveal audio, video { margin: 0px; padding: 0px; border: 0px none; font: inherit; vertical-align: baseline; }

I'm not sure if this done by mermaid, so maybe you @knsv can help with that? If it is mermaid which adds the line given above, what can I do to prevent that?

Thanks a lot.

@maxmeyer
Copy link
Author

Forget about this... The styles above are added by reveal.js itself.

@maxmeyer maxmeyer reopened this Apr 20, 2015
@maxmeyer
Copy link
Author

The problem is this:

  1. Styles are cloned here
  2. Styles are inserted here

The "insert"-operation overwrites each style which was applied later to H1 etc. Does it make sense to use the "computed" styles instead or use something else instead of insertBefore.

Please also see this screenshot

@maxmeyer
Copy link
Author

Minimal failing example:

Please save the HTML-file to your disk and open it with a browser. I tested the file with Firefox 37.0.1, Chromium 41, Internet Explorer 11 and it's always the same. The first one will show "This is a H1 headline" with a font size of "5rem". The second one only with "1rem". There's only one difference between the files: The later makes use of some embedded stylesheet.

  1. H1 with font-size 5rem

    <html>
      <head>
        <style type="text/css">
          h1 {
            font-size: 5rem;
          }
        </style>
      </head>
      <body>
        <h1>This is a H1 headline</h1>
        <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="56.766983mm" height="34.995556mm" viewBox="0 0 201.14285 124" id="svg2" version="1.1" inkscape:version="0.91 r13725" sodipodi:docname="drawing.svg">
          <defs id="defs4" /> <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="0.35" inkscape:cx="-180.14285" inkscape:cy="-78.000013" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" fit-margin-top="0" fit-margin-left="0" fit-margin-right="0" fit-margin-bottom="0" inkscape:window-width="796" inkscape:window-height="853" inkscape:window-x="800" inkscape:window-y="24" inkscape:window-maximized="0" /> <metadata id="metadata7"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" transform="translate(-226.57143,-336.07648)"> <ellipse style="fill:#ececec;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" id="path3336" cx="327.14285" cy="398.07648" rx="98.571426" ry="60" /> </g>
        </svg>
      </body>
    </html>
  2. H1 with font-size 1rem

    <html>
      <head>
        <style type="text/css">
          h1 {
            font-size: 5rem;
          }
        </style>
      </head>
      <body>
        <h1>This is a H1 headline</h1>
        <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="56.766983mm" height="34.995556mm" viewBox="0 0 201.14285 124" id="svg2" version="1.1" inkscape:version="0.91 r13725" sodipodi:docname="drawing.svg">
          <style type="text/css">
            h1 { font-size: 1rem; }
          </style>
          <defs id="defs4" /> <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="0.35" inkscape:cx="-180.14285" inkscape:cy="-78.000013" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" fit-margin-top="0" fit-margin-left="0" fit-margin-right="0" fit-margin-bottom="0" inkscape:window-width="796" inkscape:window-height="853" inkscape:window-x="800" inkscape:window-y="24" inkscape:window-maximized="0" /> <metadata id="metadata7"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" transform="translate(-226.57143,-336.07648)"> <ellipse style="fill:#ececec;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" id="path3336" cx="327.14285" cy="398.07648" rx="98.571426" ry="60" /> </g>
        </svg>
      </body>
    </html>

@maxmeyer
Copy link
Author

@knsv Do see any chance to make utils.cloneCssStyles optional?

@maxmeyer
Copy link
Author

maxmeyer commented May 8, 2015

What about adding such an interface to mermaid.js?

Mermaid.initialize({
  cloneCssStyles: true | false
})

@knsv
Copy link
Collaborator

knsv commented May 8, 2015

Good idea! Lets add it to the list.

@ghost
Copy link

ghost commented May 8, 2015

Wonderful! 👍 Maybe this is helpful https://github.com/hakimel/reveal.js/blob/master/js/reveal.js. Reveal.js uses the same interface. Maybe you can "borrow" the factory-function from there.

@ghost
Copy link

ghost commented May 8, 2015

Maybe anouther use case for such an interface hakimel/reveal.js#1082

@fehmer

@knsv
Copy link
Collaborator

knsv commented Jun 7, 2015

A fix for this has been released in version 0.5.0

@knsv knsv closed this as completed Jun 7, 2015
@maxmeyer
Copy link
Author

maxmeyer commented Jun 7, 2015

Great! Thanks a lot! 😄 Will integrate mermaid into https://github.com/fedux-org/middleman-presentation then.

@velvia
Copy link

velvia commented Mar 17, 2016

@knsv so I tried this fix (using latest mermaid.js in dist/ from a few days ago, or using mermaid.min.js 0.5.1), and it doesn't seem to work for me.

When I set cloneCssStyles: true, the <svg> element appears, but does not seem to render. What's more the raw mermaid graph text does not get replaced. Some errors appear in JS console:

mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create mermaid.js:556:5
Unexpected value 0 0 -Infinity -Infinity parsing viewBox attribute. mermaid.js:668:6
Unexpected value 0 0 -Infinity -Infinity parsing viewBox attribute.

When I set cloneCssStyles: false, then the <div class="mermaid"> does not get rendered into at all. What am I missing?

To reproduce:

  1. git clone http://github.com/velvia/presentations; check out branch mermaid-0.5.1
  2. npm install / grunt serve
  3. browse to http://localhost:8000/2014-filodb/#/1

Mermaid integration: reveal/plugin/markdown/markdown.js, see line 391, where mermaid.initialize() is called with cloneCssStyles; and also lines 23-32, which is the marked.js integration per your docs.

Any help would be greatly appreciated, thanks.

@knsv
Copy link
Collaborator

knsv commented Mar 17, 2016

Changing the initialization solved the first startup issue:

        if(typeof mermaid !== 'undefined' ) {
            mermaid.initialize({ 
                cloneCssStyles: true,
                logLevel:1   
            });
        }

There is a subsequent syntax error when trying to render the next graph so I suspect then reveal is doing stuff with the DOM during the presentation. Perhaps the more advanced integration path using the mermaid render function would be a better fit for the plugin. See example below:

var res =  mermaidAPI.render('id1','graph TB;\na-->b',function(){console.log('done');});

I hope that helped.

/Knut

@velvia
Copy link

velvia commented Mar 17, 2016

Thanks. Changing the init got rid of the errors, but the svg element no longer shows up….

Would you be able to help a bit with the mermaidAPI.render and how it would integrate? I tried entering this into the Firefox JS console:

mermaidAPI.render('id1','graph TB;\na-->b',function(){console.log('done');})

and it returned “undefined”. Sorry I’m not really a JS developer…

thanks again!

On Mar 17, 2016, at 10:51 AM, Knut Sveidqvist notifications@github.com wrote:

mermaidAPI.render('id1','graph TB;\na-->b',function(){console.log('done');})

@velvia
Copy link

velvia commented Mar 17, 2016

also shouldn’t the config have the mermaid: in it? e.g.
mermaid.initialize( { mermaid: { cloneCssStyles: true }, logLevel: 1 });

On Mar 17, 2016, at 10:51 AM, Knut Sveidqvist notifications@github.com wrote:

Changing the initialization solved the first startup issue:

    if(typeof mermaid !== 'undefined' ) {
        mermaid.initialize({ 
            cloneCssStyles: true,
            logLevel:1   
        });
    }

There is a subsequent syntax error when trying to render the next graph so I suspect then reveal is doing stuff with the DOM during the presentation. Perhaps the more advanced integration path using the mermaid render function would be a better fit for the plugin. See example below:

var res = mermaidAPI.render('id1','graph TB;\na-->b',function(){console.log('done');});
I hope that helped.

/Knut


You are receiving this because you commented.
Reply to this email directly or view it on GitHub #157 (comment)

@knsv
Copy link
Collaborator

knsv commented Mar 17, 2016

1st, make sure you are using a later version of mermaid. The one in you repos was 0.5.1 use 0.5.8 instead. If you don't it will not work in recent Chrome browsers.

And, no intialization should not be with in the mermaid section. More info here:
http://knsv.github.io/mermaid/#initialization

Glad to help!

@velvia
Copy link

velvia commented Mar 21, 2016

Sorry, could you please explain the mermaidAPI.render() call a bit?

mermaidAPI.render('id1','graph TB;\na-->b',function(){console.log('done');})

Is this supposed to return DOM, HTML text, or what? Or does it automagically insert into the DOM element ‘id1’, which must exist already? Any examples would be great, thanks.

On Mar 17, 2016, at 1:20 PM, Knut Sveidqvist notifications@github.com wrote:

1st, make sure you are using a later version of mermaid. The one in you repos was 0.5.1 use 0.5.8 instead. If you don't it will not work in recent Chrome browsers.

And, no intialization should not be with in the mermaid section. More info here:
http://knsv.github.io/mermaid/#initialization http://knsv.github.io/mermaid/#initialization
Glad to help!


You are receiving this because you commented.
Reply to this email directly or view it on GitHub #157 (comment)

@knsv
Copy link
Collaborator

knsv commented Mar 22, 2016

He he!

I can see how this can be unclear. Dont heistate to add a better description in the docs md files when it works (if you feel inspired) :)

mermaidAPI.initialize({
     startOnLoad:false
 });
 $(function(){
     var graphDefinition = 'graph TB\na-->b';
     var cb = function(svgGraph){
         console.log(svgGraph);
     };
     mermaidAPI.render('id1',graphDefinition,cb);
 });

In the example above the code in the $(function, function is run after the page has been loaded. Then the render function is called with a unique id, hardcoded graph string and a callback function.

The id is used for graph generation, the hardcoded graph should be replaced with the graph you want to render and the callback is called after the graph rendering is done with the svg code as as string. This string is also returned from the function.

The reason for the callback is that is required when attaching events like click/on hover to the generated graph. If you are not interested in that you can just as well use the returned string.

Hop that sheds light on thins. Good luck.

@velvia
Copy link

velvia commented Mar 23, 2016

Thanks for the explanation!

So I integrated the mermaidAPI.render as you suggested, in line 30. Something now renders, but it seems the styles are messed up such that you can’t read it. Any ideas?

https://github.com/velvia/presentations/blob/mermaid-0.5.1/reveal/plugin/markdown/markdown.js https://github.com/velvia/presentations/blob/mermaid-0.5.1/reveal/plugin/markdown/markdown.js

Not sure if I can paste the rendering jpg here….

thanks again

On Mar 22, 2016, at 11:56 AM, Knut Sveidqvist notifications@github.com wrote:

He he!

I can see how this can be unclear. Dont heistate to add a better description in the docs md files when it works (if you feel inspired) :)

mermaidAPI.initialize({
startOnLoad:false
});
$(function(){
var graphDefinition = 'graph TB\na-->b';
var cb = function(svgGraph){
console.log(svgGraph);
};
mermaidAPI.render('id1',graphDefinition,cb);
});
In the example above the code in the $(function, function is run after the page has been loaded. Then the render function is called with a unique id, hardcoded graph string and a callback function.

The id is used for graph generation, the hardcoded graph should be replaced with the graph you want to render and the callback is called after the graph rendering is done with the svg code as as string. This string is also returned from the function.

The reason for the callback is that is required when attaching events like click/on hover to the generated graph. If you are not interested in that you can just as well use the returned string.

Hop that sheds light on thins. Good luck.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub #157 (comment)

@QuidamAzerty
Copy link

For info, the cloneCssStyles option has been removed with d430019.
The only issue related I found was #482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants