-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
const localRequire = require('../utils/localRequire'); | ||
const HTMLAsset = require('./HTMLAsset'); | ||
|
||
class MarkdownAsset extends HTMLAsset { |
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.
I wouldn't recommend extending from another asset type. Instead, we can rely on the pipeline to pass through the generated HTML to the HTMLAsset.
Extend from Asset
here, and return the html from the generate
method. For an example, see how e.g. JSONAsset does it.
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.
Rather the PugAsset:
this.type = 'html'; |
return compiled(config.locals); |
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, I'll take a look this weekend and also see about resolving the pipeline issues
Hi there, So we've adjusted the MarkdownAsset to avoid extending the HTML Asset. We did need to add a flag to make the pipeline behave properly. Thank you for your useful examples in the JS and pug assets @devongovett and @mischnic Please let us know if this is more in line with what you were looking for. Also, we wanted to discuss front matter support. While the marked library appears to include support for basic front matter (mainly styling). the original feature request included mustache/templating specs. We held off on this aspect of the feature because it makes parcel a bit opinionated on exactly how it should be done, and we wanted input from the core team before moving ahead there. Thanks |
@@ -117,7 +116,9 @@ class Pipeline { | |||
type, | |||
value: asset.generated[type], | |||
// for scope hoisting, we need to post process all JS | |||
final: !(type === 'js' && this.options.scopeHoist) | |||
final: asset.hasOwnProperty('needsPipelineProcessing') | |||
? !asset.needsPipelineProcessing |
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 case HTMLAsset
).
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!
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
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 be false
.
parcel/packages/core/parcel-bundler/src/Pipeline.js
Lines 55 to 58 in bdc044a
if (typeof value !== 'string' || rendition.final) { | |
generated.push(rendition); | |
continue; | |
} |
As you can see in the diff, the original code only allows final
to be false
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!
Hey, @devongovett! Just a quick update. Our plan:
Sounds good? |
Shamelessly pinging you guys! 🙂 |
Is there a way to opt out of this or something? I was importing markdown files with a glob import like
Now, instead of file paths for each markdown file, I get the entire contents of the markdown file parsed as HTML which is cool but the meta data for each md file is now in the HTML body. |
Hey @tomfinney, Thanks for reporting this. I'll try to look into this soon.
|
I was using the YAML front matter style to prepend markdown files with some meta data based on: https://jekyllrb.com/docs/front-matter/ I have an example of one of my files here: https://github.com/tomfinney/website/blob/master/src/markdown/blogs/01_new_website.md I'm not really sure if using the YAML style for storing meta data in a file is standard so I guess it would make sense that it would be parsed as HTML. It's just now when I import a markdown file, I have no way of splitting the metadata from the contents unless I add some special delimiter characters around them. Originally, I was fetching the contents of the markdown file and the splitting on the So I guess the perfect interface for my use case would be that if I were to use a glob import, it would still return the keyed object of the file name to the file paths so I can choose how to process the files. |
I see. Would it work for you if I'm planning on adding the front-matter support out of the box. |
I was just writing another comment about how that would actually be the best solution. I'm essentially just replicating front matter at the moment so if that was supported out of the box, it'd be perfect. |
↪️ Pull Request
Markdown Support #2274
💻 Examples
user can now run parcel build index.md, and get an index.html in the /dist folder
🚨 Test instructions
unit test is provided in the integration tests. it confirms that the markdown file is parsed into html, and that image assets are registered/handled correctly.
✔️ PR Todo