File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ marked:
4848 dompurify : false
4949 headerIds : true
5050 lazyload : false
51+ figcaption : false
5152 prependRoot : true
5253 postAsset : false
5354 external_link :
@@ -79,6 +80,7 @@ marked:
7980 * Example: `## [foo](#bar)`, id will be set as "bar".
8081 * Requires **headerIds** to be enabled.
8182- **lazyload** - Lazy loading images via `loading="lazy"` attribute.
83+ - **figcaption** - Append `figcaption` element after each image.
8284- **prependRoot** - Prepend root value to (internal) image path.
8385 * Example `_config.yml`:
8486 ` ` ` yml
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ class Renderer extends MarkedRenderer {
118118 image ( href , title , text ) {
119119 const { hexo, options } = this ;
120120 const { relative_link } = hexo . config ;
121- const { lazyload, prependRoot, postPath } = options ;
121+ const { lazyload, figcaption , prependRoot, postPath } = options ;
122122
123123 if ( ! / ^ ( # | \/ \/ | h t t p ( s ) ? : ) / . test ( href ) && ! relative_link && prependRoot ) {
124124 if ( ! href . startsWith ( '/' ) && ! href . startsWith ( '\\' ) && postPath ) {
@@ -137,6 +137,9 @@ class Renderer extends MarkedRenderer {
137137 if ( lazyload ) out += ' loading="lazy"' ;
138138
139139 out += '>' ;
140+ if ( figcaption ) {
141+ if ( text ) out += `<figcaption aria-hidden="true">${ text } </figcaption>` ;
142+ }
140143 return out ;
141144 }
142145}
Original file line number Diff line number Diff line change @@ -791,6 +791,26 @@ describe('Marked renderer', () => {
791791 ] . join ( '\n' ) ) ;
792792 } ) ;
793793
794+ it ( 'figcaption' , ( ) => {
795+ const body = [
796+ '' ,
797+ '' ,
798+ ''
799+ ] . join ( '\n' ) ;
800+
801+ hexo . config . marked . figcaption = true ;
802+
803+ const r = require ( '../lib/renderer' ) . bind ( hexo ) ;
804+
805+ const result = r ( { text : body } ) ;
806+
807+ result . should . eql ( [
808+ '<p><img src="/bar/baz.jpg" title="bar">' ,
809+ '<img src="/bar/baz.jpg" alt="foo" title="bar"><figcaption aria-hidden="true">foo</figcaption>' ,
810+ '<img src="/aaa/bbb.jpg" alt="foo"><figcaption aria-hidden="true">foo</figcaption></p>\n'
811+ ] . join ( '\n' ) ) ;
812+ } ) ;
813+
794814 describe ( 'postAsset' , ( ) => {
795815 const Post = hexo . model ( 'Post' ) ;
796816 const PostAsset = hexo . model ( 'PostAsset' ) ;
You can’t perform that action at this time.
0 commit comments