You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe
The beforeParse hook provides access to the raw Markdown body, while afterParse provides access to parsed content.
Since adding custom properties to the file object is not allowed in beforeParse, it would be helpful to optionally make the raw Markdown body accessible from file object in afterParse.
For example, when implementing a word count functionality (as discussed here), the ideal solution would have been to count the words of the raw Markdown text inside the beforeParse hook and add the value to a file.wordCount property. But, adding a property to file is not allowed, so the workaround is to add the value to the file.body as a plain Markdown text, and get the value from the parsed body inside afterParse hook. Then a custom wordCount property can be added to the file object. (Workaround solution)
Describe the solution you'd like
For scenarios like the one described above, it would be useful to add a rawBody property to the file argument of the afterParse hook callback.
exportdefaultdefineNitroPlugin((nitroApp)=>{nitroApp.hooks.hook("content:file:afterParse",(file)=>{if(file._id.endsWith(".md")){// Currently raw body is not accessible from the afterParse hookconstwordCount=countWords(file.rawBody);file.wordCount=wordCount;}});});
Describe alternatives you've considered
An alternative solution for such a case would be to allow developers to add custom properties to the file argument of the beforeParse hook callback.
exportdefaultdefineNitroPlugin((nitroApp)=>{nitroApp.hooks.hook("content:file:beforeParse",(file)=>{if(file._id.endsWith(".md")){constwordCount=countWords(file.body);// Currently not allowed in the beforeParse hookfile.wordCount=wordCount;}});});
I came looking for the exact same thing. I also wanted to count the words in my .md files but found that the doc prop is already parsed and not the raw markdown content.
My suggestion would be to simply provide the raw content like so:
<template>
------------> like this 👇
<ContentDocv-slot="{ doc, rawMarkdownContents }">
<WordCloud :words="rawMarkdownContents" />
</ContentDoc/>
</template>
Is your feature request related to a problem? Please describe
The
beforeParse
hook provides access to the raw Markdown body, whileafterParse
provides access to parsed content.Since adding custom properties to the
file
object is not allowed inbeforeParse
, it would be helpful to optionally make the raw Markdown body accessible fromfile
object inafterParse
.For example, when implementing a word count functionality (as discussed here), the ideal solution would have been to count the words of the raw Markdown text inside the
beforeParse
hook and add the value to afile.wordCount
property. But, adding a property tofile
is not allowed, so the workaround is to add the value to thefile.body
as a plain Markdown text, and get the value from the parsed body insideafterParse
hook. Then a customwordCount
property can be added to thefile
object. (Workaround solution)Describe the solution you'd like
For scenarios like the one described above, it would be useful to add a
rawBody
property to thefile
argument of theafterParse
hook callback.Describe alternatives you've considered
An alternative solution for such a case would be to allow developers to add custom properties to the
file
argument of thebeforeParse
hook callback.Additional context
If implemented, the feature would solve problems like this one - Get amount of words in an article (#2795)
The text was updated successfully, but these errors were encountered: