| | |
| | | // \[\[ -> open brace |
| | | // ([^\[\]\|\#]+) -> one or more non-special characters ([,],|, or #) (name) |
| | | // (#[^\[\]\|\#]+)? -> # then one or more non-special characters (heading link) |
| | | // (\|[^\[\]\#]+)? -> | then one or more non-special characters (alias) |
| | | // (\|[^\[\]\#]+)? -> \| then one or more non-special characters (alias) |
| | | export const wikilinkRegex = new RegExp( |
| | | /!?\[\[([^\[\]\|\#]+)?(#+[^\[\]\|\#]+)?(\|[^\[\]\#]+)?\]\]/, |
| | | /!?\[\[([^\[\]\|\#\\]+)?(#+[^\[\]\|\#\\]+)?(\\?\|[^\[\]\#]+)?\]\]/, |
| | | "g", |
| | | ) |
| | | const highlightRegex = new RegExp(/==([^=]+)==/, "g") |
| | |
| | | const anchor = rawHeader?.trim().replace(/^#+/, "") |
| | | const blockRef = Boolean(anchor?.startsWith("^")) ? "^" : "" |
| | | const displayAnchor = anchor ? `#${blockRef}${slugAnchor(anchor)}` : "" |
| | | const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" |
| | | let displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" |
| | | const embedDisplay = value.startsWith("!") ? "!" : "" |
| | | |
| | | if (rawFp?.match(externalLinkRegex)) { |
| | | return `${embedDisplay}[${displayAlias.replace(/^\|/, "")}](${rawFp})` |
| | | } |
| | | |
| | | //transform `[[note#^block_ref|^block_ref]]` to `[[note#^block_ref\|^block_ref]]`, display correctly in table. |
| | | if (displayAlias && displayAlias.startsWith("|")) { |
| | | displayAlias = `\\${displayAlias}` |
| | | } |
| | | |
| | | return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]` |
| | | }) |
| | | } |