Skip to content

Commit

Permalink
Merge pull request #432 from ikarasz/disable-html-processing
Browse files Browse the repository at this point in the history
feat(js-examples): remove support of js examples written in html
  • Loading branch information
Schalk Neethling authored Apr 1, 2020
2 parents 7234d4c + 2be6bc6 commit 2d187a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
20 changes: 18 additions & 2 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ function preprocessJSExample(exampleCode) {
return `<pre><code id="static-js" data-height="${height}">${exampleCode}</code></pre>`;
}

/**
* Process JS example which has written in HTML.
* @param {String} exampleCode - The example source code itself
* @param {String} path - path of the example code
*
* @returns {String} jsExample - The example wrapped into code tag
*
* @deprecated
*/
function handleDeprecatedJSExampleFormat(exampleCode, path) {
console.warn(
`MDN-BOB: (processor.js/processExampleCode) HTML source files are deprecated for JS examples. (${path})`
);
return exampleCode
}

/**
* Process the example source code, based on its type.
* @param {String} type - `html`, `js`, or `css`
Expand All @@ -124,8 +140,8 @@ function processExampleCode(type, sourcePath) {
return exampleCode;
case 'js':
return sourcePath.endsWith('.js')
? preprocessJSExample(exampleCode)
: exampleCode;
? preprocessJSExample(exampleCode)
: handleDeprecatedJSExampleFormat(exampleCode, sourcePath);
default:
return '';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<pre>
<code id="static-js">var array1 = [1, 2, 3, 4, 5];
var array1 = [1, 2, 3, 4, 5];

// place at position 0 the element between position 3 and 4
console.log(array1.copyWithin(0, 3, 4));
Expand All @@ -8,5 +7,3 @@
// place at position 1 the elements after position 3
console.log(array1.copyWithin(1, 3));
// expected output: Array [4, 4, 5, 4, 5]
</code>
</pre>
32 changes: 16 additions & 16 deletions live-examples/js-examples/array/meta.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"pages": {
"arrayConcat": {
"exampleCode": "live-examples/js-examples/array/array-concat.html",
"fileName": "array-concat.html",
"title": "JavaScript Demo: Array.concat()",
"type": "js"
},
"arrayCopyWithin": {
"exampleCode": "live-examples/js-examples/array/array-copywithin.html",
"fileName": "array-copywithin.html",
"title": "JavaScript Demo: Array.copyWithin()",
"type": "js"
}
}
}
{
"pages": {
"arrayConcat": {
"exampleCode": "live-examples/js-examples/array/array-concat.html",
"fileName": "array-concat.html",
"title": "JavaScript Demo: Array.concat()",
"type": "js"
},
"arrayCopyWithin": {
"exampleCode": "live-examples/js-examples/array/array-copywithin.js",
"fileName": "array-copywithin.html",
"title": "JavaScript Demo: Array.copyWithin()",
"type": "js"
}
}
}

0 comments on commit 2d187a9

Please sign in to comment.