New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Markdown support as an entry point (issue #2274) #2538
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1cf46d7
WIP
kirillrogovoy b8b4b47
added marked
Benjmhart 99ca23d
Add MarkdownAsset
kirillrogovoy 7c0d812
added dynamic install of marked, + DRYed parse method
Benjmhart ed6c6cf
Add tests
kirillrogovoy e5a00e7
it works goshdanggit
Benjmhart 6c78aca
add needsPipelineProcessing to the Asset
kirillrogovoy 199fe18
Remove needsPipelineProcessing
kirillrogovoy 22cdea0
Merge branch 'master' into master
Benjmhart 93b83be
Merge branch 'master' into master
DeMoorJasper File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+255 Bytes
packages/core/integration-tests/test/integration/markdown/100x100.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
packages/core/integration-tests/test/integration/markdown/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# heading1 | ||
|
||
content content content | ||
|
||
[image](./100x100.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const localRequire = require('../utils/localRequire'); | ||
const Asset = require('../Asset'); | ||
|
||
class MarkdownAsset extends Asset { | ||
constructor(name, options) { | ||
super(name, options); | ||
this.type = 'html'; | ||
this.needsPipelineProcessing = true; | ||
this.hmrPageReload = true; | ||
} | ||
async parse(code) { | ||
let marked = await localRequire('marked', this.name); | ||
this.contents = marked(code); | ||
Benjmhart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this.contents; | ||
} | ||
} | ||
module.exports = MarkdownAsset; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this new property needed? Normally, if the
type
of the asset changes (e.g. from.md
to.html
), the pipeline will automatically pass it through to the next asset type (in this caseHTMLAsset
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment!
Could you, please point out where that happens exactly?
From what we discovered, the only way for an asset to undergo one more processing by another asset type is for this
final
property to befalse
.parcel/packages/core/parcel-bundler/src/Pipeline.js
Lines 55 to 58 in bdc044a
As you can see in the diff, the original code only allows
final
to befalse
for JS.Maybe the right way to go would be to remove those 4 lines above altogether. 😱 But I suppose they are there for a reason.
Please, let me know if I've got it wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh, I've got it!