File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ marked:
48
48
dompurify : false
49
49
headerIds : true
50
50
lazyload : false
51
+ figcaption : false
51
52
prependRoot : true
52
53
postAsset : false
53
54
external_link :
@@ -79,6 +80,7 @@ marked:
79
80
* Example: `## [foo](#bar)`, id will be set as "bar".
80
81
* Requires **headerIds** to be enabled.
81
82
- **lazyload** - Lazy loading images via `loading="lazy"` attribute.
83
+ - **figcaption** - Append `figcaption` element after each image.
82
84
- **prependRoot** - Prepend root value to (internal) image path.
83
85
* Example `_config.yml`:
84
86
` ` ` yml
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ class Renderer extends MarkedRenderer {
118
118
image ( href , title , text ) {
119
119
const { hexo, options } = this ;
120
120
const { relative_link } = hexo . config ;
121
- const { lazyload, prependRoot, postPath } = options ;
121
+ const { lazyload, figcaption , prependRoot, postPath } = options ;
122
122
123
123
if ( ! / ^ ( # | \/ \/ | h t t p ( s ) ? : ) / . test ( href ) && ! relative_link && prependRoot ) {
124
124
if ( ! href . startsWith ( '/' ) && ! href . startsWith ( '\\' ) && postPath ) {
@@ -137,6 +137,9 @@ class Renderer extends MarkedRenderer {
137
137
if ( lazyload ) out += ' loading="lazy"' ;
138
138
139
139
out += '>' ;
140
+ if ( figcaption ) {
141
+ if ( text ) out += `<figcaption aria-hidden="true">${ text } </figcaption>` ;
142
+ }
140
143
return out ;
141
144
}
142
145
}
Original file line number Diff line number Diff line change @@ -791,6 +791,26 @@ describe('Marked renderer', () => {
791
791
] . join ( '\n' ) ) ;
792
792
} ) ;
793
793
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
+
794
814
describe ( 'postAsset' , ( ) => {
795
815
const Post = hexo . model ( 'Post' ) ;
796
816
const PostAsset = hexo . model ( 'PostAsset' ) ;
You can’t perform that action at this time.
0 commit comments