The Trans Directory
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: use regex flag instead of string in regexp ctor

+11 -16
+11 -16
quartz/plugins/transformers/ofm.ts
··· 98 98 99 99 export const externalLinkRegex = /^https?:\/\//i 100 100 101 - export const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/, "g") 101 + export const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/g) 102 102 103 103 // !? -> optional embedding 104 104 // \[\[ -> open brace ··· 106 106 // (#[^\[\]\|\#]+)? -> # then one or more non-special characters (heading link) 107 107 // (\\?\|[^\[\]\#]+)? -> optional escape \ then | then one or more non-special characters (alias) 108 108 export const wikilinkRegex = new RegExp( 109 - /!?\[\[([^\[\]\|\#\\]+)?(#+[^\[\]\|\#\\]+)?(\\?\|[^\[\]\#]+)?\]\]/, 110 - "g", 109 + /!?\[\[([^\[\]\|\#\\]+)?(#+[^\[\]\|\#\\]+)?(\\?\|[^\[\]\#]+)?\]\]/g, 111 110 ) 112 111 113 112 // ^\|([^\n])+\|\n(\|) -> matches the header row 114 113 // ( ?:?-{3,}:? ?\|)+ -> matches the header row separator 115 114 // (\|([^\n])+\|\n)+ -> matches the body rows 116 - export const tableRegex = new RegExp( 117 - /^\|([^\n])+\|\n(\|)( ?:?-{3,}:? ?\|)+\n(\|([^\n])+\|\n?)+/, 118 - "gm", 119 - ) 115 + export const tableRegex = new RegExp(/^\|([^\n])+\|\n(\|)( ?:?-{3,}:? ?\|)+\n(\|([^\n])+\|\n?)+/gm) 120 116 121 117 // matches any wikilink, only used for escaping wikilinks inside tables 122 - export const tableWikilinkRegex = new RegExp(/(!?\[\[[^\]]*?\]\])/, "g") 118 + export const tableWikilinkRegex = new RegExp(/(!?\[\[[^\]]*?\]\])/g) 123 119 124 - const highlightRegex = new RegExp(/==([^=]+)==/, "g") 125 - const commentRegex = new RegExp(/%%[\s\S]*?%%/, "g") 120 + const highlightRegex = new RegExp(/==([^=]+)==/g) 121 + const commentRegex = new RegExp(/%%[\s\S]*?%%/g) 126 122 // from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts 127 123 const calloutRegex = new RegExp(/^\[\!(\w+)\|?(.+?)?\]([+-]?)/) 128 - const calloutLineRegex = new RegExp(/^> *\[\!\w+\|?.*?\][+-]?.*$/, "gm") 124 + const calloutLineRegex = new RegExp(/^> *\[\!\w+\|?.*?\][+-]?.*$/gm) 129 125 // (?:^| ) -> non-capturing group, tag should start be separated by a space or be the start of the line 130 126 // #(...) -> capturing group, tag itself must start with # 131 127 // (?:[-_\p{L}\d\p{Z}])+ -> non-capturing group, non-empty string of (Unicode-aware) alpha-numeric characters and symbols, hyphens and/or underscores 132 128 // (?:\/[-_\p{L}\d\p{Z}]+)*) -> non-capturing group, matches an arbitrary number of tag strings separated by "/" 133 129 const tagRegex = new RegExp( 134 - /(?:^| )#((?:[-_\p{L}\p{Emoji}\p{M}\d])+(?:\/[-_\p{L}\p{Emoji}\p{M}\d]+)*)/, 135 - "gu", 130 + /(?:^| )#((?:[-_\p{L}\p{Emoji}\p{M}\d])+(?:\/[-_\p{L}\p{Emoji}\p{M}\d]+)*)/gu, 136 131 ) 137 - const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/, "g") 132 + const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/g) 138 133 const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ 139 134 const ytPlaylistLinkRegex = /[?&]list=([^#?&]*)/ 140 135 const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/) ··· 185 180 // replace all wikilinks inside a table first 186 181 src = src.replace(tableRegex, (value) => { 187 182 // escape all aliases and headers in wikilinks inside a table 188 - return value.replace(tableWikilinkRegex, (value, ...capture) => { 189 - const [raw]: (string | undefined)[] = capture 183 + return value.replace(tableWikilinkRegex, (_value, raw) => { 184 + // const [raw]: (string | undefined)[] = capture 190 185 let escaped = raw ?? "" 191 186 escaped = escaped.replace("#", "\\#") 192 187 // escape pipe characters if they are not already escaped