-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Feature request: config to add wrapping div #77
Comments
Would love this. I've just jumped through so many hoops to make a code block appear full bleed with some truly horrific css that could have been avoided with one extra wrapping div. |
In the meantime, I came up with a workaround. It’s clunky, but it does the job.
{# START, divs around Prism `pre``code` stuff #}
{% set Content = content %}
{% set withoutDivStart = '<pre class="language-' %}
{% set withDivStart = '<div class="highlight"><pre class="language-' %}
{% set withoutDivEnd = '</code></pre>' %}
{% set withDivEnd = '</code></pre></div>' %}
{% if withoutDivStart in content %}
{% set Content = content | replace (withoutDivStart, withDivStart) %}
{% set Content = Content | replace (withoutDivEnd, withDivEnd) %}
{% endif %}
{# END, divs around Prism `pre``code` stuff #}
{{ Content | safe }} (Note the capitalization or lack thereof for “Content”/“content” above.)
div.highlight {
position: relative;
}
const pre = codeBlock.parentNode;
pre.parentNode.insertBefore(button, pre); Now, if you have to scroll horizontally through a long-width code block, the “copy code” button stays affixed to the right end of the Mind you, this doesn’t cancel my feature request 😄 — but it does work in the interim, so there ya go. |
For having things like absolute-position
Copy Code
buttons that won’t move when you’re horizontally scrolling a highlighted code block, it would be nice to have a config-level option of wrapping this plugin’s output within adiv
.Just so it’s clear what I’m suggesting: I don’t mean to replace the current
pre class="language-[whatever]"
wrapper, but rather to be able to wrap all of that within a div. This would therefore be similar to, e.g., how Hugo wraps its syntax highlighting indiv class="highlight"
followed by thepre
.I am making the naïve assumption that there is nothing about Prism.js itself that would preclude this. I looked through the Prism docs and couldn’t find any way to implement it within Prism itself, including suggested Prism plugins (most if not all of which are presumably assuming client-side use of Prism rather than static-site-building), so I hoped that this plugin could provide a workaround such as what I’m suggesting.
Thanks in advance for whatever consideration this may receive.
The text was updated successfully, but these errors were encountered: