wpilibsuite / sphinxext-opengraph

Sphinx extension to generate unique OpenGraph metadata
https://sphinxext-opengraph.readthedocs.io
Other
74 stars 27 forks source link

og:description picks up <script... if text is short #22

Closed cranmer closed 3 years ago

cranmer commented 3 years ago

It seems that if the text of a page is very short that the og:description may pick up HTML tags in the header that aren't properly escaped, and the og:description text will be displayed on the web page.

I am using jupyterbook, which uses sphinx. My jupyterbook has this in the _config.yml file

  extra_extensions:
  - sphinxext.opengraph

Here's an example source page https://github.com/cranmer/stats-ds-book/blob/master/book/statistics/cramer-rao-bound.md

This gets compiled into https://cranmer.github.io/stats-ds-book/statistics/cramer-rao-bound.html

The problematic part seems to be

  <meta property="og:description" content="coming soon<script type="text/x-thebe-config"> { requestKernel: true, binderOptions: { repo: "binder-examples/jupyter-stacks-datascience", ref: "master", }, codeMirrorConfig: { theme: "abcdef", mod..." />

As the webpage will display (not always visible, but you can see it on a phone or wide screen

{ requestKernel: true, binderOptions: { repo: "binder-examples/jupyter-stacks-datascience", ref: "master", }, codeMirrorConfig: { theme: "abcdef", mod..." />

It seems this was picked up from the HTML

  <div class="section" id="cramer-rao-bound">
<h1>Cramer-Rao Bound<a class="headerlink" href="#cramer-rao-bound" title="Permalink to this headline">¶</a></h1>
<p>coming soon</p>
</div>

    <script type="text/x-thebe-config">
    {
        requestKernel: true,
        binderOptions: {
            repo: "binder-examples/jupyter-stacks-datascience",
            ref: "master",
        },
        codeMirrorConfig: {
            theme: "abcdef",
            mode: "python"
        },
        kernelOptions: {
            kernelName: "python3",
            path: "./statistics"
        },
        predefinedOutput: true
    }
    </script>

Example:

Screen Shot 2020-10-01 at 9 08 54 AM

IMG_7466

cranmer commented 3 years ago

related issue in jupyterbook https://github.com/executablebooks/jupyter-book/issues/1008

cranmer commented 3 years ago

I will probably want to update the example page I sent with more text, which may hide the problem. So here's another page with the same issue that I will leave alone for testing: https://cranmer.github.io/stats-ds-book/test-sphinxext-opengraph.html

TheTripleV commented 3 years ago

After building your repo, I have noticed this issue occurring on many of the pages. The issue seems to lie in raw tags. sphinxext-opengraph does not currently ignore raw tags. Once raw tags are excluded, the description is created correctly.

TheTripleV commented 3 years ago

The latest release contains the fix for this issue, @cranmer .