1
1
import slugify from "slugify" ;
2
- import markdownIt from "markdown-it" ;
3
2
import markdownItToc from "markdown-it-table-of-contents" ;
4
3
import { IdAttributePlugin } from "@11ty/eleventy" ;
5
- import { decodeHTML } from "entities" ;
6
4
7
5
function markdownItSlugify ( s ) {
8
6
return slugify ( removeExtraText ( s ) , { lower : true , remove : / [ \= \" : ’ ' ` , ] / g } ) ;
@@ -27,17 +25,15 @@ export default function (eleventyConfig) {
27
25
eleventyConfig . addPlugin ( IdAttributePlugin , {
28
26
// custom slugify function, otherwise we use Eleventy’s built-in `slugify` filter.
29
27
slugify : function ( textContent ) {
30
- // TODO Eleventy 3.0.0-beta.2 will handle decodeHTML automatically
31
- return markdownItSlugify ( decodeHTML ( textContent ) ) ;
28
+ return markdownItSlugify ( textContent ) ;
32
29
} ,
33
30
selector : "h1,h2,h3,h4,h5,h6" , // default
34
31
} ) ;
35
32
36
- let mdIt = markdownIt ( {
37
- html : true ,
38
- breaks : true ,
39
- linkify : true ,
40
- } ) . use ( markdownItToc , {
33
+ let mdIt ;
34
+ eleventyConfig . amendLibrary ( "md" , ( mdLib ) => {
35
+ mdIt = mdLib ;
36
+ mdLib . use ( markdownItToc , {
41
37
includeLevel : [ 2 , 3 ] ,
42
38
slugify : markdownItSlugify ,
43
39
format : function ( heading ) {
@@ -52,10 +48,9 @@ export default function (eleventyConfig) {
52
48
} ,
53
49
} ) ;
54
50
55
- // opt out of linkification for .io TLD, e.g. 11ty.io
56
- mdIt . linkify . tlds ( ".io" , false ) ;
57
-
58
- eleventyConfig . setLibrary ( "md" , mdIt ) ;
51
+ // opt out of linkification for .io TLD, e.g. 11ty.io
52
+ mdLib . linkify . tlds ( ".io" , false ) ;
53
+ } ) ;
59
54
60
55
eleventyConfig . addPairedShortcode ( "markdown" , function ( content ) {
61
56
return mdIt . renderInline ( content ) ;
0 commit comments