Let's assume that I have
Right now I have copied the content of snippet B into snippet A. This has the disadvantage, that whenever I change snippet B, I have to additionally change snippet A. Therefore, my question is whether there is some kind of statement to embed one snippet into another?
e.g.<externalsnippet src=".\snippetB.snippet" />
or something similar.
Code Blocks To write longer or more detailed snippets of code, it is often better to place them inside a code block. Code blocks allow you to use multiple lines, and markdown will render it inside its own box and with code type font.
An inline code snippet can be copied by clicking anywhere on the snippet itself. A single line code snippet can be copied by clicking on the “copy” icon. The browser also provides an ability to manually highlight the text and choose “copy” from the context menu (right click).
This is quick and easy to do using a tool like: http://htmlencode.net/ Use <pre><code> tags to surround your code. For the <pre> tag you can optionally add class=”line-numbers”. This will add line numbers to your code and these line numbers will not be copied if students copy and paste snippets.
You could use an external parsed general entity to declare an entity reference for snippet B and then use it n number of times inside of snippet A.
When snippet A is parsed, the entity references will be expanded and the content from snippet B will be included at each spot where the entity was used.
For example, assume that you had a file called snipppetB.xml:
<snippetB>
<foo>Content goes here</foo>
</snippetB>
And a file for snippet A declared an entity called snippetB
referencing snippetB.xml and used it four times:
<!DOCTYPE snippetA [
<!ENTITY snippetB SYSTEM "./snippetB.xml">
]>
<snippetA>
<a>&snippetB;</a>
<b>&snippetB;</b>
<c>&snippetB;</c>
<d>&snippetB;</d>
</snippetA>
When snippetA.xml is parsed, the XML content would look like this:
<snippetA>
<a>
<snippetB>
<foo>Content goes here</foo>
</snippetB>
</a>
<b>
<snippetB>
<foo>Content goes here</foo>
</snippetB>
</b>
<c>
<snippetB>
<foo>Content goes here</foo>
</snippetB>
</c>
<d>
<snippetB>
<foo>Content goes here</foo>
</snippetB>
</d>
</snippetA>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With