// The new file overrides the search path
free(search_folder);
- // First, calculate path to this source file
- char * temp_path = path_from_dir_base(search_path, source_path);
-
- // Then, calculate new search path relative to source
- search_folder = path_from_dir_base(temp_path, temp);
-
- free(temp_path);
+ // Calculate new search path relative to source
+ search_folder = path_from_dir_base(source_path, temp);
}
}
parse_stack = stack_new(0);
}
+ // Remember where we currently are in the stack
+ size_t stack_depth = parse_stack->size;
+
// Iterate through source text, looking for `{{foo}}`
start = strstr(source->str, "{{");
}
// Prevent infinite recursive loops
- for (int i = 0; i < parse_stack->size; ++i)
+ for (int i = 0; i < stack_depth; ++i)
{
temp = stack_peek_index(parse_stack, i);
if (strcmp(file_path->str, temp) == 0) {
if (parsed == NULL) {
// Free temp stack
stack_free(parse_stack);
+ } else {
+ // Reset stack depth
+ parse_stack->size = stack_depth;
}
free(search_folder);
char * folder = dirname((char *) a_file->filename[i]);
if (extensions & EXT_TRANSCLUDE) {
-
mmd_transclude_source(buffer, folder, "", format, NULL, NULL);
// Don't free folder -- owned by dirname
if ((extensions & EXT_TRANSCLUDE) && (a_file->count == 1)) {
// Perform transclusion(s)
-
mmd_transclude_source(buffer, folder, "", format, NULL, NULL);
// Don't free folder -- owned by dirname
<text:p text:style-name="Standard">This text is included in <text:span text:style-name="Source_20_Text">bar.txt</text:span>.</text:p>
-<text:p text:style-name="Standard">This can be transcluded without causing an infinite loop – {{foo.txt}}</text:p>
+<text:p text:style-name="Standard">This can be transcluded without causing an infinite loop –
+This text is included in <text:span text:style-name="Source_20_Text">foo.txt</text:span>.</text:p>
+
+<text:p text:style-name="Standard">This should not be transcluded to avoid an infinite loop – {{foo.txt}}</text:p>
<text:p text:style-name="Preformatted Text">This is a file with no metadata.<text:line-break/></text:p>
<text:p text:style-name="Standard">This text is included in <text:span text:style-name="Source_20_Text">bar.txt</text:span>.</text:p>
-<text:p text:style-name="Standard">This can be transcluded without causing an infinite loop – {{foo.txt}}</text:p>
+<text:p text:style-name="Standard">This can be transcluded without causing an infinite loop –
+This text is included in <text:span text:style-name="Source_20_Text">foo.txt</text:span>.</text:p>
+
+<text:p text:style-name="Standard">This should not be transcluded to avoid an infinite loop – {{foo.txt}}</text:p>
<text:p text:style-name="Preformatted Text">This is a file with no metadata.<text:line-break/></text:p>
<p>This text is included in <code>bar.txt</code>.</p>
-<p>This can be transcluded without causing an infinite loop – {{foo.txt}}</p>
+<p>This can be transcluded without causing an infinite loop –
+This text is included in <code>foo.txt</code>.</p>
+
+<p>This should not be transcluded to avoid an infinite loop – {{foo.txt}}</p>
<pre><code>This is a file with no metadata.
</code></pre>
<p>This text is included in <code>bar.txt</code>.</p>
-<p>This can be transcluded without causing an infinite loop – {{foo.txt}}</p>
+<p>This can be transcluded without causing an infinite loop –
+This text is included in <code>foo.txt</code>.</p>
+
+<p>This should not be transcluded to avoid an infinite loop – {{foo.txt}}</p>
<pre><code>This is a file with no metadata.
</code></pre>
This text is included in \texttt{bar.txt}.
-This can be transcluded without causing an infinite loop -- \{\{foo.txt\}\}
+This can be transcluded without causing an infinite loop --
+This text is included in \texttt{foo.txt}.
+
+This should not be transcluded to avoid an infinite loop -- \{\{foo.txt\}\}
\begin{verbatim}
This is a file with no metadata.
This text is included in \texttt{bar.txt}.
-This can be transcluded without causing an infinite loop -- \{\{foo.txt\}\}
+This can be transcluded without causing an infinite loop --
+This text is included in \texttt{foo.txt}.
+
+This should not be transcluded to avoid an infinite loop -- \{\{foo.txt\}\}
\begin{verbatim}
This is a file with no metadata.
This text is included in `bar.txt`.
-This can be transcluded without causing an infinite loop -- {{foo.txt}}
+This can be transcluded without causing an infinite loop -- {{../foo.txt}}
```
{{nometa.txt}}