feat(ofm): parsing all type of arrow (#797)
* feat(ofm): parsing all type of arrow
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
* fix: use html value instead of decimal
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
* fix: skip parsing arrow if it is not a valid supported mapping
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
---------
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
| | |
| | | cite: "quote", |
| | | } as const |
| | | |
| | | const arrowMapping: Record<string, string> = { |
| | | "->": "→", |
| | | "-->": "⇒", |
| | | "=>": "⇒", |
| | | "==>": "⇒", |
| | | "<-": "←", |
| | | "<--": "⇐", |
| | | "<=": "⇐", |
| | | "<==": "⇐", |
| | | } |
| | | |
| | | function canonicalizeCallout(calloutName: string): keyof typeof calloutMapping { |
| | | const normalizedCallout = calloutName.toLowerCase() as keyof typeof calloutMapping |
| | | // if callout is not recognized, make it a custom one |
| | |
| | | |
| | | export const externalLinkRegex = /^https?:\/\//i |
| | | |
| | | export const arrowRegex = new RegExp(/-{1,2}>/, "g") |
| | | export const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/, "g") |
| | | |
| | | // !? -> optional embedding |
| | | // \[\[ -> open brace |
| | |
| | | if (opts.parseArrows) { |
| | | replacements.push([ |
| | | arrowRegex, |
| | | (_value: string, ..._capture: string[]) => { |
| | | (value: string, ..._capture: string[]) => { |
| | | const maybeArrow = arrowMapping[value] |
| | | if (maybeArrow === undefined) return SKIP |
| | | return { |
| | | type: "html", |
| | | value: `<span>→</span>`, |
| | | value: `<span>${maybeArrow}</span>`, |
| | | } |
| | | }, |
| | | ]) |