File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { getImages } from "./image" ;
22import type { Config } from "../types/config" ;
3- import { titleCase } from "./strings" ;
3+ import { removeImages , titleCase } from "./strings" ;
44
55const hasHeader = ( content : string ) => content . match ( / ^ # \s + / ) ;
66
7- const cleanUp = ( content : string ) : string =>
8- content
9- . replace ( / ^ ( # \s + .+ [ \n \s ] + ) \s * < p i c t u r e > [ . \w \W ] + < \/ p i c t u r e > [ \n \s ] * / , "$1" )
10- . replace ( / ^ ( # \s + .+ [ \n \s ] + ) ( ! \[ .+ ] \( .* \) \n ? ) { 1 , 2 } [ \n \s ] * / , "$1" )
11- . replace ( / ^ ( # \s + .+ [ \n \s ] + ) ( < i m g \s .* \/ > \n ? ) { 1 , 2 } [ \n \s ] * / , "$1" ) ;
12-
137export const setPreview = ( content : string , config : Config ) => {
148 if ( ! hasHeader ( content ) ) {
159 const title = titleCase ( config . image . parameters . title ) ;
@@ -21,7 +15,7 @@ export const setPreview = (content: string, config: Config) => {
2115
2216 const replace = "$1" ;
2317
24- return cleanUp ( content ) . replace (
18+ return removeImages ( content ) . replace (
2519 / ^ ( # \s + .+ [ \n \s ] + ) / ,
2620 `${ replace } ${ images } \n\n` ,
2721 ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ export const titleCase = (title: string | undefined) => {
1010 . replace ( / [ - _ ] / g, " " ) ;
1111} ;
1212
13+ export const removeImages = ( content : string ) : string =>
14+ content
15+ . replace ( / ^ ( # \s + .+ [ \n \s ] + ) \s * < p i c t u r e > [ . \w \W ] + < \/ p i c t u r e > [ \n \s ] * / , "$1" )
16+ . replace ( / ^ ( # \s + .+ [ \n \s ] + ) ( ! \[ .+ ] \( .* \) \n ? ) { 1 , 2 } [ \n \s ] * / , "$1" )
17+ . replace ( / ^ ( # \s + .+ [ \n \s ] + ) ( < i m g \s .* \/ > \n ? ) { 1 , 2 } [ \n \s ] * / , "$1" ) ;
18+
1319export const encodeUri = ( value : string | undefined ) : string => {
1420 if ( value === "" || value === undefined ) {
1521 return "" ;
You can’t perform that action at this time.
0 commit comments