markdown-it-fontawesome icon indicating copy to clipboard operation
markdown-it-fontawesome copied to clipboard

Loads plugins directly into the page without using a package system.

Open auxtern opened this issue 2 years ago • 4 comments

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);

auxtern avatar Aug 13 '22 14:08 auxtern

Hi @auXtern , thanks.

I have no idea. Try it and let me know!

nunof07 avatar Aug 14 '22 10:08 nunof07

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>';
            }
        ));
    };

}));

auxtern avatar Aug 14 '22 10:08 auxtern

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

auxtern avatar Aug 14 '22 10:08 auxtern

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.

nunof07 avatar Aug 14 '22 11:08 nunof07