Skip to content

Commit

Permalink
Add markdown-it-anchor for automatic heading id tags
Browse files Browse the repository at this point in the history
  • Loading branch information
infinitymdm committed Aug 12, 2023
1 parent 5e2ffac commit 654b47d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 46 deletions.
98 changes: 53 additions & 45 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
const { nunjucks } = require("nunjucks");

module.exports = function(eleventyConfig) {
const markdownIt = require('markdown-it')
const markdownItAttrs = require('markdown-it-attrs')
const markdownItOptions = {
html: true,
breaks: true,
linkify: true
}
eleventyConfig.addTemplateFormats('svg');
eleventyConfig.addExtension('svg', {
outputFileExtension: 'svg',
key: 'html'
/*compile: async (inputContent) => {
let output = nunjucks.renderString(inputContent)
return async () => {
return output;
};
}*/
});
const markdownLib = markdownIt(markdownItOptions).use(markdownItAttrs)

eleventyConfig.addPassthroughCopy('halfmoonui');
eleventyConfig.addPassthroughCopy('jsonpath-0.8.0.js');
eleventyConfig.addPassthroughCopy('custom-variables.css');

eleventyConfig.addPassthroughCopy('character-sheets/*.pdf');

eleventyConfig.addPassthroughCopy({'_data/parts.json': 'mechdb/parts.json'});
eleventyConfig.addPassthroughCopy({'_data/planets.json': 'lore/planets.json'});

eleventyConfig.addPassthroughCopy('images/*.svg');
eleventyConfig.addPassthroughCopy('images/planets/*.svg');

eleventyConfig.setNunjucksEnvironmentOptions({
throwOnUndefined: true
});
eleventyConfig.setLibrary('md', markdownLib);
eleventyConfig.addShortcode('keyword', function(word, glossary) {
return '<b class="keyword" onclick="halfmoon.initStickyAlert({content: \'' + glossary[word] + '\', title: \'' + word + '\', hasDismissButton: true, timeShown: 5000});">' + word + '</b>'
});
eleventyConfig.addFilter('getObjectsByAttribute', function(objects, attribute, value) {
return objects.filter((obj) => obj[attribute] == value);
});
return {
htmlTemplateEngine: 'njk'
}
// Configure markdown-it plugins
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const markdownItAttrs = require('markdown-it-attrs')
const markdownItOptions = {
html: true,
breaks: true,
linkify: true
}
const mdLib = markdownIt(markdownItOptions).use(markdownItAttrs).use(markdownItAnchor)
eleventyConfig.setLibrary('md', mdLib);

// Enable SVG templating
eleventyConfig.addTemplateFormats('svg');
eleventyConfig.addExtension('svg', {
outputFileExtension: 'svg',
key: 'html'
});

// Export css and js artifacts
eleventyConfig.addPassthroughCopy('halfmoonui');
eleventyConfig.addPassthroughCopy('jsonpath-0.8.0.js');
eleventyConfig.addPassthroughCopy('custom-variables.css');

// Export character sheets
eleventyConfig.addPassthroughCopy('character-sheets/*.pdf');

// Export MechDB artifacts
eleventyConfig.addPassthroughCopy({'_data/parts.json': 'mechdb/parts.json'});
eleventyConfig.addPassthroughCopy({'_data/planets.json': 'lore/planets.json'});

// Export images
eleventyConfig.addPassthroughCopy('images/*.svg');
eleventyConfig.addPassthroughCopy('images/planets/*.svg');

// ???
eleventyConfig.setNunjucksEnvironmentOptions({
throwOnUndefined: true
});

// Custom shortcodes
eleventyConfig.addShortcode('keyword', function(word, glossary) {
return '<b class="keyword" onclick="halfmoon.initStickyAlert({content: \'' + glossary[word] + '\', title: \'' + word + '\', hasDismissButton: true, timeShown: 5000});">' + word + '</b>'
});

// Custom filters
eleventyConfig.addFilter('getObjectsByAttribute', function(objects, attribute, value) {
return objects.filter((obj) => obj[attribute] == value);
});

return {
htmlTemplateEngine: 'njk'
}
};
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default: serve

# Install dependencies
setup:
npm i @11ty/eleventy markdown-it markdown-it-attrs
npm i @11ty/eleventy markdown-it markdown-it-attrs markdown-it-anchor

build: clean setup
#!/usr/bin/env bash
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"@11ty/eleventy": "^2.0.1",
"markdown-it": "^13.0.1",
"markdown-it-anchor": "^8.6.7",
"markdown-it-attrs": "^4.1.6"
}
}

0 comments on commit 654b47d

Please sign in to comment.