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
/* Remark plugin to fix trailing whitespace in inline nodes. See: https://github.com/orgs/syntax-tree/discussions/60*/functionremarkTrailingWhitespace(){returnfunction(tree,file){visit(tree,['strong','emphasis'],(node,index,parent)=>{// Remove empty nodesif(!node.children.length){parent.children.splice(index,1);returnSKIP;}constfirst=node.children[0];// Remove image nodes from within emphasis nodesif(first.type==='image'){parent.children.splice(index,1,first);returnSKIP;}// Remove trailing whitespace at the beginningif(first.type==='text'){conststart_match=first.value.match(/^(\s+)(.*)/);if(start_match){const[_,start_ws,start_text]=start_match;parent.children.splice(index,0,{type: 'text',value: start_ws});if(start_text){// has non-whitespace contentfirst.value=start_text;}else{// all-whitespace contentnode.children.shift();}// Re-visit this nodereturn[SKIP,index-1];}}constlast=node.children[node.children.length-1];if(last.type==='text'){constend_match=last.value.match(/(.*?)(\s+)$/);if(end_match){const[_,end_text,end_ws]=end_match;parent.children.splice(index+1,0,{type: 'text',value: end_ws});if(end_text){last.value=end_text;}else{node.children.pop();}}}returnSKIP;});};}
For example, this HTML:
Produces this Markdown:
Add a mdast-level util to shift the trailing whitespace to the outside of inline (emphasis) nodes.
The text was updated successfully, but these errors were encountered: