Skip to content

Commit

Permalink
Add Markdown support as an entry point (issue #2274) (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjmhart authored and devongovett committed Mar 6, 2019
1 parent f562ce6 commit 03fdcfd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,5 @@
# heading1

content content content

[image](./100x100.png)
33 changes: 33 additions & 0 deletions packages/core/integration-tests/test/markdown.js
@@ -0,0 +1,33 @@
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const {bundle, run, assertBundleTree} = require('./utils');

describe('markdown', function() {
it('should support bundling Markdown', async function() {
let b = await bundle(
path.join(__dirname, '/integration/markdown/index.md')
);

await assertBundleTree(b, {
name: 'index.html',
assets: ['index.md'],
childBundles: [
{
type: 'png',
assets: ['100x100.png'],
childBundles: []
}
]
});

let files = await fs.readdir(path.join(__dirname, '/dist'));
let html = await fs.readFile(path.join(__dirname, '/dist/index.html'));
for (let file of files) {
let ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0];
if (file !== 'index.html' && ext !== '.map') {
assert(html.includes(file));
}
}
});
});
1 change: 1 addition & 0 deletions packages/core/parcel-bundler/src/Parser.js
Expand Up @@ -51,6 +51,7 @@ class Parser {

this.registerExtension('jade', './assets/PugAsset');
this.registerExtension('pug', './assets/PugAsset');
this.registerExtension('md', './assets/MarkdownAsset');

let extensions = options.extensions || {};
for (let ext in extensions) {
Expand Down
1 change: 0 additions & 1 deletion packages/core/parcel-bundler/src/Pipeline.js
Expand Up @@ -50,7 +50,6 @@ class Pipeline {

let inputType = path.extname(asset.name).slice(1);
let generated = [];

for (let rendition of this.iterateRenditions(asset)) {
let {type, value} = rendition;
if (typeof value !== 'string' || rendition.final) {
Expand Down
15 changes: 15 additions & 0 deletions packages/core/parcel-bundler/src/assets/MarkdownAsset.js
@@ -0,0 +1,15 @@
const localRequire = require('../utils/localRequire');
const Asset = require('../Asset');

class MarkdownAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'html';
this.hmrPageReload = true;
}
async generate() {
let marked = await localRequire('marked', this.name);
return marked(this.contents);
}
}
module.exports = MarkdownAsset;

0 comments on commit 03fdcfd

Please sign in to comment.