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

@aegisjsproject/markdown

v0.1.3

Published

Markdown parser for `@aegisjsproject/core`

Downloads

59

Readme

@aegisjsproject/markdown

Markdown parser for @aegisjsproject/core

CodeQL Node CI Lint Code Base

GitHub license GitHub last commit GitHub release GitHub Sponsors

npm node-current NPM Unpacked Size

npm

GitHub followers GitHub forks GitHub stars Twitter Follow

Donate using Liberapay


Adding language support

In order to reduce bundle size, only plaintext is available/supported by default. However, you can easily add support for additional languages in a variety of ways:

Registering from Static Imports

Note: All languages provided by highlight.js may be found at /es/languages/${lang}.min.js.

import { registerLanguage } from '@aegisjsproject/markdown';
import javascript from 'highlight.js/lanuages/javascript.min.js';
import xml from 'highlight.js/languages/xml.min.js';
import css from 'highlight.js/languages/css.min.js';

registerLanguage('javascript', javascript);
registerLanguage('xml', xml);
registerLanguage('css',css);

// Or
import { registerLanguages } from '@aegisjsproject/markdown';
import javascript from 'highlight.js/lanuages/javascript.min.js';
import xml from 'highlight.js/languages/xml.min.js';
import css from 'highlight.js/languages/css.min.js';

registerLanguages({ javascript, xml, css });

Dynamically Loading and Registering using Dynamic Imports

This uses import() for dynamic loading of language modules from unpkg.com.

Note: These are case-sensitive and MUST be the correct filename (without extension).

import { loadLanguages } from '@aegisjsproject/markdown';

await loadLanguages('javascript', 'css', 'xml', 'typescript');

Example

import { md, createStyleSheet, getMarkdown, registerLanguages } from '@aegisjsproject/markdown';
import javascript from 'highlight.js/languages/javascript.min.js';
import css from 'highlight.js/languages/css.min.js';
import xml from 'highlight.js/languages/xml.min.js';

registerLanguages({ javascript, css, xml });

document.head.append(
  createStyleSheet('github', { media: '(prefers-color-scheme: light)' }),
  createStyleSheet('github-dark', { media: '(prefers-color-scheme: dark)' }),
);

document.getElementById('header').append(md`
  # Hello, World!

  ## It is currently ${new Date()}.
`);

customElements.define('md-preview', class HTMLMDPreviewElement extends HTMLElement {
  #shadow;

  constructor() {
    super();

    this.#shadow = this.attachShadow({ mode: 'closed' });
    const container = document.createElement('div');
    container.id = 'container';
    container.part.add('container');

    this.#shadow.append(
      createStyleSheet('github', { media: '(prefers-color-scheme: light)' }),
      createStyleSheet('github-dark', { media: '(prefers-color-scheme: dark)' }),
      container,
    );
  }

  async attributeChangedCallback(name, oldVal, newVal) {
    switch(name) {
      case 'src':
        if (typeof newVal === 'string') {
          this.#shadow.getElementById('container').replaceChildren(await getMarkdown(this.src));
        } else {
          this.#shadow.getElementById('container').replaceChildren();
        }
        break;

      default:
        throw new Error(`Unhandled attribute change: ${name}.`);
    }
  }

  set content(val) {
    if (typeof val === 'string' && val.length !== 0) {
      this.#shadow.getElementById('container').replaceChildren(md`${val}`);
      this.scrollIntoView({ behavior: 'smooth', block: 'start' });
    } else {
      this.#shadow.getElementById('container').replaceChildren();
    }
  }

  get src() {
    return this.getAttribute('src');
  }

  set src(val) {
    if (typeof val === 'string' || val instanceof URL) {
      this.setAttribute('src', val);
    } else {
      this.removeAttribute('src');
    }
  }

  clear() {
    this.content = null;
  }

  static get observedAttributes() {
    return ['src'];
  }
});

document.forms.test.addEventListener('submit', event => {
  event.preventDefault();
  const data = new FormData(event.target);
  document.getElementById('preview').content = data.get('md');
});

document.forms.test.addEventListener('reset', () => document.getElementById('preview').clear());