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
Let's add a previewText export method to the RDMD engine to loop through the AST and remove any non-paragraph nodes. Then we can transform that to plain-text, and do the truncation in the top-level method. So it'd look something like:
importremarkToPlainTextfrom'remark-plain-text';importvisitfrom'unist-util-flatmap';constpTagFilter=node=>node.type==='paragraph' ? node : null);//^Our custom p tag filter "plugin"; this is all// pseudo code, but it works something like this!exportfunctionpreviewText(text,truncateAt,opts={}){if(!text)returnnull;[text,opts]=setup(text,opts);text=processor(opts).use(tree=>visit(tree,pTagFilter)).use(remarkToPlainText).use(rehypeStringify).processSync(text).contents;returntext.slice(0,truncateAt).trim()+'...';}
Activity
kellyjosephprice commentedon Feb 27, 2023
I believe
astToPlainTextcan be used to accomplish this?build(release): 🚀 v7.8.0 🦉