npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

medium-editor-auto-style-extension

v2.0.3

Published

AutoStyle is an extension for the Medium Editor.

Downloads

13

Readme

AutoStyleExtension for Medium Editor

AutoStyleExtension for Medium Editor allows auto-styling of words. The auto-styling is defined by a configuration object, which gets passed to the constructur.

In detail:

  1. Words and the CSS style to be applied to these words.
  2. Words and the CSS class to be applied to these words.
  3. Whether case matching is to be performed.
  4. Whether words only are matched, or substrings, too.

Try out the live example.

Installation

npm install medium-editor
npm install medium-editor-auto-style-extension

Usage (via NPM)

index.js

MediumEditor = require('medium-editor');
AutoStyleExtension = require('medium-editor-auto-style-extension');

Usage (via Header)

index.html


<script type="text/javascript" src="<path>/medium-editor.js"></script>
<script type="text/javascript" src="<path>/auto-style.js"></script>

<style type="text/css">
    .combine-class-one {
        border: 2px dotted green;
    }
    .combine-class-two {
        background-color:gold;
    }
</style>

<div class="editable">CömbineStyleAndClass, CombineStyles, CombineClasses, gräy gräyx, oraNGE oraNGEX, ÖÖÖ</div>

<script type="text/javascript">
var editor = new MediumEditor('.editable', {
    extensions: {
        'auto-highlight': new AutoStyleExtension({

            config: {
                sectionA: {
                    matchcase: false,
                    wordsonly: false,
                    class: 'combine-class-one',
                    style: 'color:red;',
                    words: ['CömbineStyleAndClass']
                },
                sectionB: {
                    matchcase: false,
                    wordsonly: false,
                    style: 'background-color:#aaa;',
                    words: ['gräy']
                },
                sectionC: {
                    matchcase: true,
                    wordsonly: true,
                    style: 'background-color:orange;',
                    words: ['oraNGE']
                },
                sectionD: {
                    matchcase: true,
                    wordsonly: true,
                    class: 'combine-class-one',
                    words: ['CombineClasses']
                },
                sectionE: {
                    matchcase: true,
                    wordsonly: true,
                    class: 'combine-class-two',
                    words: ['CombineClasses']
                },
                sectionF: {
                    matchcase: true,
                    wordsonly: true,
                    style: 'border: 2px dotted green;',
                    words: ['CombineStyles']
                },
                sectionG: {
                    matchcase: true,
                    wordsonly: true,
                    style: 'background-color:gold;',
                    words: ['CombineStyles']
                },
                sectionH: {
                    matchcase: false,
                    wordsonly: false,
                    style: 'background-color:silver;',
                    words: ['ÖÖÖ']
                }
            }

        })
    }
});
</script>

Configuration at Runtime

Additional methods allow manipulation of sections during runtime

getConfig: function() {
  ...
},
setConfig: function(config) {
 ...
},
removeConfigSection: function(sectionName) {
  ...
},
setConfigSection: function(sectionName, sectionObject) {
  ...
},

// Applies all config styles to the text.
// Useful for triggering via external code.
applyStyles: function() {
  ...
}

Configuration at Runtime: Example

Changing the configuration does not cause re-evaluation of the content implicitly. Call the function applyStyles() manually to re-evaluate the style of the content.

var extension = editor.getExtensionByName('auto-style');

extension.setConfigSection('your-section-name', {
    matchcase: false,
    wordsonly: true,
    //class: 'a-class',
    style: 'color:red;',
    words: ['some','red','words']
});

extension.applyStyles();

Changelog

2.0.0

  • Call extension.applyStyles() to apply configuration modification made during runtime
  • Tried to fix some weired unicode behavious during word matching.

1.1.0

  • Allows for CSS- and Class-combination of words present in more than one section.

1.0.0

  • Reworked configuration structure
  • Added unicode support
  • Added configuration modification during runtime

Contributers

This implementation is based on the inbuild AutoLink plugin of Medium Editor.

License

MIT