markdown-it-fontawesome
markdown-it-fontawesome copied to clipboard
Loads plugins directly into the page without using a package system.
This is a great plugin, is it possible to use it directly like other markdown-it plugins?
Usage with package:
var md = require('markdown-it');
var fa = require('markdown-it-fontawesome');
md().use(fa);
Direct use I mean:
var md = window.markdownit().use(window.markdownitFontAwesome);
Hi @auXtern , thanks.
I have no idea. Try it and let me know!
I've tried it.
the problem arose for importing the Regex plugin, which states "require is not defined". It's a bit confusing to get around this.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.markdownitFontAwesome = factory());
})(this, (function () {
'use strict';
var Plugin = require('markdown-it-regexp');
module.exports = function fontawesome_plugin(md) {
// FA4 style.
md.use(Plugin(
/\:fa-([\w\-]+)\:/,
function (match, utils) {
return '<i class="fa fa-' + utils.escape(match[1]) + '"></i>';
}
));
// FA5 style.
md.use(Plugin(
/\:fa([\w])-([\w\-]+)\:/,
function (match, utils) {
return '<i class="fa' + utils.escape(match[1]) + ' fa-' + utils.escape(match[2]) + '"></i>';
}
));
};
}));
For reference I looked at the markdown-it-emoji plugin: https://github.com/markdown-it/markdown-it-emoji/blob/master/dist/markdown-it-emoji.js
Yeah, it wasn't built with this in mind.
This plugin is pretty small. If you can get markdown-it-regexp to work on the browser, it should be easy to just copy the code from this plugin and apply in your project.
Or if you are passing this package through a bundler, maybe there is a way to make it work.