-
Notifications
You must be signed in to change notification settings - Fork 92
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
Multiple languages within one code block? #176
Comments
This is too much of an edge case to build-in support for.
What are you hoping to accomplish by having |
Thank you for responding so fast. My particular use case is in providing code + output pairs, i.e.:
Where first 2 lines are the code, and last line is the output. This is a minimal example, but it can get more complex. What I want is to provide either different text color or different background for those two contexts. In Pandoc's case for example there is a different solution possible - Pandoc provides an option to transfer After reading the multimarkdown syntax guides, I am not aware of something of this sort available in multimarkdown. Would be very happy to hear about any other possible solution that I might have missed. |
This very easy to solve, just use two independent adjacent code blocks and 'stitch' them together vertically with a bit of CSS. This is exactly what is done on the site you mentioned (taken verbatim from the CSS there, so it possibly has to be tweaked):
Since you can attach multiple CSS classes to any MMD code block the possibilities are nearly unlimited. |
Hello @mn4367 and thank you for the suggestion. However, if I am not missing something - your css example assumes that the class is set for the I don't think I can do this for |
That's correct, I just took the example from their CSS. But nevertheless with
and
you can make it look like one block. They use Highlight.js on the site and I tried the example above with it, it seems to work well here. I don't think that a class for |
@mn4367 thanks! I wasn't aware of the However this solution still doesn't work as intended - in your example you show that the entire background of the second pre (with I know this is becoming a bit out of topic for this issue. But maybe you will have a quick tip about it? One possibility is probably to try turning But I still think having native support for this would be a lot easier and would not require this complex css stylesheet. In addition it would be useful for highlighting parts of code with something like:
Which in markdown then would be:
And things of this nature. |
I don't know which highlighting framework you are using, but I think there is a style applied to However, I'm pretty sure this never will be added to MMD so you could use JavaScript: document.addEventListener("DOMContentLoaded", function (_event) {
function getNextPreElement(element) {
let next = element.nextSibling;
while (next && ((next.nodeType === 3) || (next.nodeType === 8))) {
next = next.nextSibling;
}
if (next && (next.nodeName === "PRE")) {
return next;
}
return null;
}
preElements = document.querySelectorAll("pre");
let i = 0;
while (i < preElements.length) {
let preGroup = [];
preGroup.push(preElements[i]);
let nextPreElement = getNextPreElement(preElements[i]);
while (nextPreElement) {
preGroup.push(nextPreElement);
nextPreElement = getNextPreElement(nextPreElement);
i++;
}
if (preGroup.length > 1) {
// classList.add isn't supported in IE 10!
preGroup[0].classList.add("preGroup");
while (preGroup.length > 1) {
while (preGroup[1].firstChild) {
preGroup[0].appendChild(preGroup[1].firstChild);
}
preGroup[1].parentNode.removeChild(preGroup[1]);
preGroup.splice(1, 1);
}
}
i++;
}
}); As far as I see this does exactly what you want to achieve, plus, it marks the pre+hr {
display:none;
} or something similar to make the ruler 'disappear'. |
As far as I understand it currently it isn't possible to have multiple languages within one code block.
Maybe multimarkdown can support this by differentiating between these scenarios?
Case 1:
Case 2:
In the first case there is no empty line between the code blocks - so they will be placed within the same
pre
with different code classes. In the second case there is a space and so different code blocks would be in their ownpre
elements.The text was updated successfully, but these errors were encountered: