Skip to content
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

[T-290] Markdown transformer #3936

Closed
wants to merge 30 commits into from
Closed

[T-290] Markdown transformer #3936

wants to merge 30 commits into from

Conversation

DeMoorJasper
Copy link
Member

@DeMoorJasper DeMoorJasper commented Dec 22, 2019

↪️ Pull Request

This PR adds a markdown transformer for Parcel 2, the aim of this PR is to get parcel to become a fully functional static site generator from markdown files, by allowing specification of a layout file and metadata through frontmatter.

We can probably use this to generate the Parcel 2 docs site?

For code highlighting this uses highlight.js and for markdown parsing it uses marked.

Loosely based on #2882

Closes #3357

Close T-290

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@DeMoorJasper DeMoorJasper changed the title markdown transformer [T-290] Markdown transformer Dec 22, 2019
@height
Copy link

height bot commented Dec 22, 2019

This pull request has been linked to T-290.

@parcel-benchmark
Copy link

parcel-benchmark commented Dec 22, 2019

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 5.46s -30.00ms
Cached 2.06s -26.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/modern/kitchen-sink.90de237b.js 1.16kb +0.00b 452.00ms +48.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 226.00ms +66.00ms ⚠️
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 227.00ms +66.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 8.21s +58.00ms
Cached 1.98s -78.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/main/index.js 66.80kb +0.00b 241.00ms +21.00ms ⚠️

AtlasKit Editor 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

Three.js x4 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

Click here to view a detailed benchmark overview.

@mischnic
Copy link
Member

Related: #3384, (#3262)

// @flow
import {Transformer} from '@parcel/plugin';
import {promisify} from '@parcel/utils';
import marked from 'marked';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to look into using something like remark for markdown since it supports all kinds of plugins for different things. For example, syntax highlighting could be done by a plugin for remark however people like without needing Parcel to build it into the transformer. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, wouldn't that require a javasrcript based config?

@height
Copy link

height bot commented Mar 14, 2020

This pull request has been linked to and will mark 1 task as "Done" when merged:

💡Tip: You can link multiple Height tasks to a pull request.

@bradenhs
Copy link

The ability to use parcel 2 as a static site generator with code highlighting built in would be awesome! What's the status of this PR?

@DeMoorJasper
Copy link
Member Author

@bradenhs it's ready for a merge just awaiting a review

@mischnic
Copy link
Member

mischnic commented May 3, 2020

  • Using a language (i.e. tsx that is supported with GitHub) fails at buildtime. I think we should rather fallback to plaintext like in the marked docs: https://marked.js.org/#/USING_ADVANCED.md

  • Should the dependencies (especially highlight.js and marked) be installed on demand instead (packageManager.require)? They are quite large given that most users wouldn't process markdown anyway.

  • Relative paths in the template don't work (Failed to resolve 'style.css' from './markdown/src/sub/other.md')
    This makes it somewhat unusable for a SSG usecase.

src/
├── index.md       `template: ./template.html`
├── style.css
├── sub
│   └── other.md   `template: ../template.html`
└── template.html  `<link rel="stylesheet" href="style.css" />`
  • Has @devongovett changed his opinion regarding marked vs remark?

  • (More of a future roadmap: The only thing that is blocking me from using Parcel instead of eleventy is an auto-generated navigation/sitemap...)

@DeMoorJasper
Copy link
Member Author

@mischnic I haven't really found a way around relative paths except running posthtml over the template and rewriting all relative imports to be relative to markdown instead of the template.

I agree with dynamically using the markdown and highlight libraries.

Will refactor everything and hack in the relative support once Devon has reviewed this. My main question about remark vs marked is there no point in changing except for the config but that might require a js config? Which we are actively trying to prevent everywhere.

@mischnic
Copy link
Member

mischnic commented May 3, 2020

My main question about remark vs marked is there no point in changing except for the config but that might require a js config? Which we are actively trying to prevent everywhere.

True, but we could do use a .remarkrc just like .posthtmlrc (remark and PostHTML actually have the exact same node API). It seems like remark don't have an official config file either.

no point in changing

Do you mean "remark doesn't have any benefits" or "remark doesn't have any benefits if we don't allow a config file"

@DeMoorJasper
Copy link
Member Author

DeMoorJasper commented May 3, 2020

@mischnic with no point in changing that I mean it would/should output the same as marked anyway if there's no config. So the only reason I see was the config as it's main selling point is the plugins

@devongovett
Copy link
Member

devongovett commented May 3, 2020

I think we need to come up with something that's extensible, or people will just run into issues pretty quickly. Remark has a great plugin ecosystem around it that people can use to extend it. We just need a way of letting people specify those. I think things like syntax highlighting should also be done in plugins too so it can be customizable. We just need a way to run remark and load plugins inside parcel.

I'm also thinking that maybe part of this should be done in a packager too. As @mischnic said, we'll need a way of generating a list of links between pages and such. If we ran all of the pages through a packager at the end, that could inject the markdown into a template or something to generate the full HTML page with the list of links, which could come from the bundle graph. We're doing something similar at work for our docs website, except using MDX and React.

I think we'd want a way to specify layouts at the page level along with other metadata like title, description, etc. This could be done using frontmatter perhaps, or however plugins wanted, and stored in asset.meta. Then the packager could read the metadata for each bundle in the bundle graph while its generating the list of pages.

I'm not saying all that has to happen in this PR, but I think we should move in this direction. In my experience so far it's been awesome to use Parcel as a static site generator, so I'd like for it to be as extensible as possible.

@DeMoorJasper
Copy link
Member Author

Might recreate this PR at some point in the future, for now gonna close it

@mischnic mischnic deleted the v2-marked branch September 26, 2023 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parcel 2: Markdown transformer
5 participants