Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/lib/markbind/src/preprocessors/componentPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,10 @@ function _isHtmlIncludingMarkdown(node, context, filePath) {
return isIncludeSrcMd;
}

function _preprocessDynamicInclude(node, context, parser, hash, filePath, actualFilePath) {
const element = node;
element.name = 'panel';
element.attribs.src = filePath;

element.attribs['no-close'] = true;
element.attribs['no-switch'] = true;
element.attribs.header = element.attribs.name || '';

if (hash) {
element.attribs.fragment = hash.substring(1);
}

parser.dynamicIncludeSrc.push({ from: context.cwf, to: actualFilePath, asIfTo: element.attribs.src });
delete element.attribs.dynamic;

return element;
}

/**
* PreProcesses includes.
* Replaces it with an error node if the specified src is invalid,
* or an empty node if the src is invalid but optional.
* Replaces it with a panel with the appropriate content if the dynamic attribute is specified.
*/
function _preprocessInclude(node, context, config, parser) {
const element = node;
Expand Down Expand Up @@ -295,14 +275,10 @@ function _preprocessInclude(node, context, config, parser) {

const isInline = _.has(element.attribs, 'inline');
const isTrim = _.has(element.attribs, 'trim');
const isDynamic = _.has(element.attribs, 'dynamic');

element.name = isInline ? 'span' : 'div';
element.attribs[ATTRIB_INCLUDE_PATH] = filePath;

// Use a 'plain' panel for a dynamic include
if (isDynamic) return _preprocessDynamicInclude(element, context, parser, hash, filePath, actualFilePath);

// No need to process url contents
if (isUrl) return element;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Path within the boilerplate folder is separately specified

This is dynamically included.
# Path within the boilerplate folder is separately specified

Like static include, pages within the site should be able to use files located in folders within boilerplate.

Expand Down
18 changes: 11 additions & 7 deletions test/functional/test_site/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,22 @@ <h4 id="focus-groups">Focus groups<a class="fa fa-anchor" href="#focus-groups"><
<p>Requirements gathering, requirements elicitation, requirements analysis, requirements capture are some of the terms commonly <strong>and</strong> interchangeably used to represent the activity of understanding what a software product should
do.</p>
</div>
<p><strong>Dynamic include</strong></p>
<p>
<panel src="/test_site/requirements/SpecifyingRequirements._include_.html" name="Dynamic Include" no-close="true" no-switch="true"><template slot="_header"><p>Dynamic Include</p></template></panel>
</p>

<p><strong>Boilerplate include</strong></p>
<div name="Boilerplate Referencing">
<p>
<panel src="/test_site/requirements/UserStories._include_.html" no-close=""><template slot="_header"><p>Boilerplate Includes</p></template></panel>
</p>
</div>
<p>
<panel src="/test_site/requirements/notInside._include_.html" name="Referencing specified path in boilerplate" no-close="true" no-switch="true"><template slot="_header"><p>Referencing specified path in boilerplate</p></template></panel>
</p>
<div name="Referencing specified path in boilerplate">
<h1 id="path-within-the-boilerplate-folder-is-separately-specified">Path within the boilerplate folder is separately specified<a class="fa fa-anchor" href="#path-within-the-boilerplate-folder-is-separately-specified"></a></h1>
<p>Like static include, pages within the site should be able to use files located in folders within boilerplate.</p>
<p>Also, the boilerplate file name (e.g. <code>inside.md</code>) and the file that it is supposed to act as (<code>notInside.md</code>) can be different.</p>
<p>This file should behaves as if it is in the <code>requirements</code> folder:</p>
<panel src="/test_site/requirements/NonFunctionalRequirements._include_.html"><template slot="_header"><p>Tested with the folllowing include</p></template>
<p></p>
</panel>
</div>
<p><strong>Nested include</strong></p>
<div>
<ol>
Expand Down Expand Up @@ -549,6 +552,7 @@ <h6 class="always-index" id="level-6-header-outside-headingsearchindex-with-alwa
<a class="nav-link py-1" href="#focus-groups">Focus groups&#x200E;</a>
</nav>
</nav>
<a class="nav-link py-1" href="#path-within-the-boilerplate-folder-is-separately-specified">Path within the boilerplate folder is separately specified&#x200E;</a>
<nav class="nav nav-pills flex-column my-0 nested no-flex-wrap">
<a class="nav-link py-1" href="#feature-list">Feature list&#x200E;</a>
<a class="nav-link py-1" href="#panel-without-src-header">Panel without src header&#x200E;</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ code.hljs:hover {
header.header-fixed {
position: fixed;
width: 100%;
z-index: 9999;
z-index: 1000;
}

/* #app is treated as the main container */
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions test/functional/test_site/expected/siteData.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"brainstorming": "Brainstorming",
"user-surveys": "User surveys",
"focus-groups": "Focus groups",
"path-within-the-boilerplate-folder-is-separately-specified": "Path within the boilerplate folder is separately specified",
"markbind-plugin-pre-render": "Markbind Plugin Pre-render",
"level-6-header-outside-headingsearchindex-with-always-index-attribute-should-be-indexed": "Level 6 header (outside headingSearchIndex) with always-index attribute should be indexed"
},
Expand Down
6 changes: 1 addition & 5 deletions test/functional/test_site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,11 @@ tags: ["tag-frontmatter-shown", "tag-included-file", "+tag-exp*", "-tag-exp-hidd

<include src="requirements/EstablishingRequirements.md#preview" />

**Dynamic include**

<include src="requirements/SpecifyingRequirements.md" name="Dynamic Include" dynamic />

**Boilerplate include**

<include src="requirements/boilerTest.md" name="Boilerplate Referencing" boilerplate />

<include src="requirements/notInside.md" name="Referencing specified path in boilerplate" boilerplate="folder/inside.md" dynamic/>
<include src="requirements/notInside.md" name="Referencing specified path in boilerplate" boilerplate="folder/inside.md"/>

**Nested include**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ code.hljs:hover {
header.header-fixed {
position: fixed;
width: 100%;
z-index: 9999;
z-index: 1000;
}

/* #app is treated as the main container */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ code.hljs:hover {
header.header-fixed {
position: fixed;
width: 100%;
z-index: 9999;
z-index: 1000;
}

/* #app is treated as the main container */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ code.hljs:hover {
header.header-fixed {
position: fixed;
width: 100%;
z-index: 9999;
z-index: 1000;
}

/* #app is treated as the main container */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ code.hljs:hover {
header.header-fixed {
position: fixed;
width: 100%;
z-index: 9999;
z-index: 1000;
}

/* #app is treated as the main container */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ code.hljs:hover {
header.header-fixed {
position: fixed;
width: 100%;
z-index: 9999;
z-index: 1000;
}

/* #app is treated as the main container */
Expand Down
80 changes: 0 additions & 80 deletions test/unit/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,86 +430,6 @@ test('includeFile detects cyclic references for static cyclic includes', async (
expect(result).toContain(expected);
});

test('includeFile processes successfully for dynamic cyclic includes', async () => {
const indexPath = path.resolve('index.md');
const includePath = path.resolve('include.md');

const index = [
'# Index',
'<include src="include.md" dynamic/>',
'',
].join('\n');

const include = [
'# Include',
'<include src="index.md" dynamic/>',
'',
].join('\n');

const json = {
'index.md': index,
'include.md': include,
};

fs.vol.fromJSON(json, '');
const baseUrlMap = new Set([ROOT_PATH]);

const markbinder = new MarkBind();
const result = await markbinder.includeFile(indexPath, {
baseUrlMap,
rootPath: ROOT_PATH,
userDefinedVariablesMap: DEFAULT_USER_DEFINED_VARIABLES_MAP,
});

const expected = [
'# Index',
`<panel src="${includePath}" cwf="${indexPath}" include-path="${includePath}"`
+ ' no-close="true" no-switch="true" header=""/>',
'',
].join('\n');

expect(result).toEqual(expected);
});

test('includeFile replaces <include dynamic> with <panel>', async () => {
const rootPath = path.resolve('');
const indexPath = path.resolve('index.md');
const includePath = path.resolve('include.md');

const index = [
'# Index',
'<include src="include.md" dynamic />',
'',
].join('\n');

const include = ['# Include'].join('\n');


const json = {
'index.md': index,
'include.md': include,
};

fs.vol.fromJSON(json, '');
const baseUrlMap = new Set([rootPath]);

const markbinder = new MarkBind();
const result = await markbinder.includeFile(indexPath, {
baseUrlMap,
rootPath,
userDefinedVariablesMap: DEFAULT_USER_DEFINED_VARIABLES_MAP,
});

const expected = [
'# Index',
`<panel src="${includePath}" cwf="${indexPath}" include-path="${includePath}"`
+ ' no-close="true" no-switch="true" header=""/>',
'',
].join('\n');

expect(result).toEqual(expected);
});

test('renderFile converts markdown headers to <h1>', async () => {
const markbinder = new MarkBind();
const rootPath = path.resolve('');
Expand Down