@@ -15,11 +15,13 @@ function render(data, key, options) {
1515 * @typedef Options
1616 * @property {string[] } [keys] - Key names of file metadata to render to HTML - can be nested
1717 * @property {boolean } [wildcard=false] - Expand `*` wildcards in keypaths
18+ * @property {Object } [engineOptions] Options to pass to the markdown engine (default [marked](https://github.com/markedjs/marked))
1819 **/
1920
2021const defaultOptions = {
2122 keys : [ ] ,
22- wildcard : false
23+ wildcard : false ,
24+ engineOptions : { }
2325}
2426
2527/**
@@ -40,6 +42,15 @@ function markdown(options = defaultOptions) {
4042 const debug = metalsmith . debug ( '@metalsmith/markdown' )
4143 const matches = metalsmith . match ( '**/*.{md,markdown}' , Object . keys ( files ) )
4244
45+ const legacyEngineOptions = Object . keys ( options ) . filter ( ( opt ) => ! Object . keys ( defaultOptions ) . includes ( opt ) )
46+ if ( legacyEngineOptions . length ) {
47+ debug . warn ( 'Starting from version 2.0 marked engine options will need to be specified as options.engineOptions' )
48+ legacyEngineOptions . forEach ( ( opt ) => {
49+ options . engineOptions [ opt ] = options [ opt ]
50+ } )
51+ debug . warn ( 'Moved engine options %s to options.engineOptions' , legacyEngineOptions . join ( ', ' ) )
52+ }
53+
4354 debug ( 'Running with options: %O' , options )
4455 if ( matches . length === 0 ) {
4556 debug . warn ( 'No markdown files found.' )
@@ -54,7 +65,7 @@ function markdown(options = defaultOptions) {
5465 if ( '.' != dir ) html = join ( dir , html )
5566
5667 debug . info ( 'Rendering file "%s" as "%s"' , file , html )
57- const str = marked ( data . contents . toString ( ) , options )
68+ const str = marked ( data . contents . toString ( ) , options . engineOptions )
5869 data . contents = Buffer . from ( str )
5970
6071 let keys = options . keys
@@ -63,7 +74,7 @@ function markdown(options = defaultOptions) {
6374 }
6475 keys . forEach ( ( k ) => {
6576 debug . info ( 'Rendering key "%s" of file "%s"' , k . join ? k . join ( '.' ) : k , file )
66- render ( data , k , options )
77+ render ( data , k , options . engineOptions )
6778 } )
6879
6980 delete files [ file ]
0 commit comments