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
We can supply linkifyStr with a custom render. Which is quite nice. But if we want to fallback to the default for some reason, that currently requires to copy-paste part of the source code.
For example:
importtype{IntermediateRepresentation}from'linkifyjs';importlinkifyStrfrom'linkify-string';/** * The functions `escapeText`, `escapeAttr`, `attributesToString` * and `defaultRender` are copied from the source code of linkifyjs. */functionescapeText(text: string){returntext.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');}functionescapeAttr(href: string){returnhref.replace(/"/g,'"');}functionattributesToString(attributes: IntermediateRepresentation['attributes']){constresult=[];for(constattrinattributes){constval=attributes[attr]+'';result.push(`${attr}="${escapeAttr(val)}"`);}returnresult.join(' ');}functiondefaultRender({
tagName,
attributes,
content,}: IntermediateRepresentation){return`<${tagName}${attributesToString(attributes)}>${escapeText(content)}</${tagName}>`;}exportfunctionexample(value: string,className: string){returnlinkifyStr(value,{
className,render: {url: (options: IntermediateRepresentation)=>{// some custom logic goes here// ...if(1===1){// some more custom logicreturn'<i>Hello</i>';}returndefaultRender(options);},},});}
It would be nice to do something like this instead:
import{typeIntermediateRepresentation,defaultRender}from'linkifyjs';importlinkifyStrfrom'linkify-string';exportfunctionexample(value: string,className: string){returnlinkifyStr(value,{
className,render: {url: (options: IntermediateRepresentation)=>{// some custom logic goes here// ...if(1===1){// some more custom logicreturn'<i>Hello</i>';}returndefaultRender(options);},},});}
Or maybe even:
import{typeIntermediateRepresentation}from'linkifyjs';importlinkifyStrfrom'linkify-string';exportfunctionexample(value: string,className: string){returnlinkifyStr(value,{
className,render: {url: (options: IntermediateRepresentation)=>{// some custom logic goes here// ...if(1===1){// some more custom logicreturn'<i>Hello</i>';}returnnull;},},});}
The text was updated successfully, but these errors were encountered:
We can supply
linkifyStr
with a customrender
. Which is quite nice. But if we want to fallback to the default for some reason, that currently requires to copy-paste part of the source code.For example:
It would be nice to do something like this instead:
Or maybe even:
The text was updated successfully, but these errors were encountered: