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

Feat: add raw import (Mode.RAW) #400

Closed
wants to merge 3 commits into from

Conversation

stefanvanherwijnen
Copy link
Contributor

This adds a raw export to .md files which returns the raw Markdown content.

#342

@hmsk
Copy link
Owner

hmsk commented Feb 24, 2023

Thanks for your contribution! For raw mode, I'd prefer to rely on Vite's ?raw importing over implementing by the plugin's end. https://vitejs.dev/guide/assets.html#importing-asset-as-string
I will have some impl to unblock that sooner or later.

@hmsk
Copy link
Owner

hmsk commented Feb 24, 2023

Confirmed ?raw is working even with the current version. Hope it covers what you need!
ee8768c

@hmsk hmsk closed this Feb 24, 2023
@stefanvanherwijnen
Copy link
Contributor Author

I understand your point, but ?raw does not provide the parsed frontmatter. In my case I use a Vue component which has raw markdown as input, but I also need to import attributes for meta data.

Is there a solution for this with ?raw? Otherwise, could you reconsider this?

@hmsk
Copy link
Owner

hmsk commented Feb 24, 2023

icic that makes sense. let me consider API/naming.

@stefanvanherwijnen
Copy link
Contributor Author

A workaround is to import a .md file twice, once normally and once as raw and stripping the frontmatter:

const YAMLFrontMatterRegex = /---(.|\n)*---/
const markdown =  rawViteImport.replace(YAMLFrontMatterRegex, '')

I'd prefer a single import with { attributes, raw } 😄 .

@hmsk
Copy link
Owner

hmsk commented Feb 25, 2023

@stefanvanherwijnen what do you feel if the plugin export raw markdown string via markdown key? "raw" may sound like whole file content as ?raw gives.

@stefanvanherwijnen
Copy link
Contributor Author

Sounds good to me 👍

hmsk added a commit that referenced this pull request Feb 27, 2023
@trandaison
Copy link

This shout be mention in the docs.

@hmsk
Copy link
Owner

hmsk commented Jul 1, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants