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

directly inserting skipText into js #58

Merged
merged 8 commits into from
Feb 5, 2020
Merged

directly inserting skipText into js #58

merged 8 commits into from
Feb 5, 2020

Conversation

choldgraf
Copy link
Member

@choldgraf choldgraf commented Feb 1, 2020

This is an attempt at directly inserting the copybutton skip text into the javascript via templating, rather than manually inserting it on the python side.

Right now, it doesn't seem to work for reasons I can't figure out. The rendered javascript file doesn't have the correct config value inserted into it. I've opened up sphinx-doc/sphinx#7086 to try and debug.

I think I figured out how to do this, the answer was in updating the html_context at the "config-ready" event rather than the "page-html-context" event.

It also does the following:

  • Adds some logic to only copy the lines that have the prompt
  • Adds the option to choose whether the prompts are stripped
  • Applies the patch that I suggested to @tzach's PR in Remove the last newline from the copied text #57 (after applying their commit from the PR so they're in the commit history!)
  • Fixes the ability to customize the image used by the copybutton so it's much less hacky
  • Sets the default prompt behavior to "no prompt text", making the user need to explicit set it

This should now be ready to go...

@choldgraf
Copy link
Member Author

I'd also love to hear what @s-weigand thinks about this, as he was concerned about this behavior in different themes etc and I don't want to re-break this. My hope is that this is a more simple way to achieve the same thing. What do you think?

(also note that this PR pins the minimal Sphinx theme needed to be 1.8, because that's when the event config-inited was added)

@s-weigand
Copy link
Contributor

Just tested it with the problematic themes from #54 (sphinx==2.3.0) and it works like a charm 😄

@choldgraf
Copy link
Member Author

cool! OK then gonna merge this one after merging #57

@choldgraf choldgraf closed this Feb 3, 2020
@choldgraf choldgraf reopened this Feb 3, 2020
@choldgraf
Copy link
Member Author

this one now has a lot more functionality packed into it, I updated the top comment in case others have thoughts on it...

@choldgraf
Copy link
Member Author

OK I'm gonna merge this one and we'll see how it goes!

@choldgraf choldgraf merged commit 2a83aa2 into master Feb 5, 2020
@choldgraf choldgraf deleted the template_static branch February 5, 2020 23:28
@choldgraf
Copy link
Member Author

hmmm, readthedocs seems to be doing weird things with generating the static files from the _t template, and I'm not sure why...

@mgeier
Copy link
Contributor

mgeier commented Feb 6, 2020

I guess you'll have to add _t there?

https://github.com/choldgraf/sphinx-copybutton/blob/3acd1eb63a61d467a769b163f4a95ffa4b0de337/setup.py#L33

@s-weigand
Copy link
Contributor

s-weigand commented Feb 6, 2020

My guess is that the template didn't get bundled.
For local development you most likely used pip install -e ., which uses the source directory as package directory. On RTD you install it with pip install ., which does a python setup.py sdist(or bdist not sure about that) first and installs the dist.
But the package_data in setup.py still tryes to bundle copybutton.js, which was renamed to copybutton.js_t.

@choldgraf
Copy link
Member Author

ohh that's a good point - I'll try updating that and see what happens

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

Successfully merging this pull request may close these issues.

None yet

4 participants