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

Allowing for reusable content through includes #227

Closed
thelovebug opened this issue Apr 1, 2020 · 9 comments
Closed

Allowing for reusable content through includes #227

thelovebug opened this issue Apr 1, 2020 · 9 comments
Labels
question 🙅 Not issue, just a question (should post to Marp discussion)

Comments

@thelovebug
Copy link

I wasn't sure whether this was a marpit or marp-core question, apologies if I got this wrong.

Is there any plan for an include directive that will allow me to have a separate file which will be imported at render-time?

For example:

---
theme: uncover
size: 4:3
---

# This is my first slide

---

<!-- include: static/content.md -->

---

# This will appear after the content contained within the include

This will permit me to use boilerplate text on all slidedecks, and make it much easier if information contained within the text changes, but also for things like church presentations where song words would need to be included in subsequent slidedecks.

@yhatt
Copy link
Member

yhatt commented Apr 1, 2020

Both of Marpit and Marp Core are designed to work in anywhere, not only the local file system but also web app (Marp Web). So we cannot add the feature depending on local file system as our framework / core.

But you can extend the syntax via markdown-it plugins if you want. markdown-it-include may be helpful in this case.

@yhatt yhatt added the question 🙅 Not issue, just a question (should post to Marp discussion) label Apr 6, 2020
@yhatt yhatt closed this as completed Apr 9, 2020
@yhatt yhatt mentioned this issue Aug 29, 2020
@alanlivio
Copy link

Hi @yhatt.
I just found this issue and I have the same problem. Is it possible use setup this markdown-it-include directly from the md file. Because I am using marp from the VSCode extension? So I would like to avoid using the CLI.
Many thanks in advance for you reply.

@yhatt
Copy link
Member

yhatt commented Aug 22, 2024

No, Marp for VS Code does not allow any plugins for users safety. You can use features only defined in Marp Core.

@alanlivio
Copy link

Thank you so much @yhatt.

What do you think about a solution based on JavaScript?
My scenario is that I have some code samples that I want to show in the presentation that want to be in separate files. So I need to get the code and highlight it. Something like discussed here or here.

It would be something similar to use mermaid inside markdown only, which works in VSCode.

@alanlivio
Copy link

I tried the follow code, but did not work.

---
map: true
theme: default
class: lead
backgroundColor: white
paginate: true
---

<pre><code class="language-java" data-src="./code/test.java"></code></pre>

---
<!-- Load Prism.js and the required languages -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-java.min.js"></script>

<!-- Fetch and display the external code -->
<script>
window.addEventListener('vscode.markdown.updateContent', function() { 
  document.querySelectorAll('code[data-src]').forEach(codeBlock => {
    const src = codeBlock.getAttribute('data-src');
    fetch(src)
      .then(response => response.text())
      .then(data => {
        codeBlock.textContent = data;
        Prism.highlightElement(codeBlock);
      });
  });
});
</script>

@yhatt
Copy link
Member

yhatt commented Aug 22, 2024

That is feasible given the principle of Markdown's transparency for HTML element <script>, but we do not recommend that approach because it may limit Markdown compatibillity with other Marp tools and Markdown as a document.

If you still want that, an inline script should wrap with HTML comment <!-- --> to get work. The common Markdown parser including Marp will sanitize > in Markdown contents by replacing to &gt;, so JavaScript arrow function => will break by replacing =&gt;.

@alanlivio
Copy link

Many thanks @yhatt. It worked for me. For the ones that looking for a solution I can share the code bellow:

---
theme: default
class: lead
backgroundColor: white
paginate: true
marp: true
---

<pre>
<code class="language-java" data-src="code//Test.java">
</code>
</pre>


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>

<!-------------code load and highlight--------------->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
<!--
function updateCode(){
  document.querySelectorAll('code[data-src]').forEach(codeBlock => {
    const src = codeBlock.getAttribute('data-src');
    fetch(src)
      .then(response => response.text())
      .then(data => {
        codeBlock.textContent = data;
        hljs.highlightBlock(codeBlock);
      });
  });
}
window.addEventListener('vscode.markdown.updateContent', function() { updateCode(); });
updateCode();
-->
</script>
<!-------------code load and highlight--------------->

@calidion
Copy link

calidion commented Dec 8, 2024

Can this feature work in vs code plugin now?

@yhatt
Copy link
Member

yhatt commented Dec 8, 2024

@calidion Accept the situation and use Marp CLI. The reason why Marp/markdown-it plugins cannot be used in the VS Code extension is explained in marp-team/marp#543.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question 🙅 Not issue, just a question (should post to Marp discussion)
Projects
None yet
Development

No branches or pull requests

4 participants