GithubHelp home page GithubHelp logo

ideas's People

Contributors

christianmurphy avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ideas's Issues

Generic asset inliner (css, js, img)

I've created a small generic asset inliner that I'm using for one of my projects:

https://github.com/marko-knoebl/rehype-inline

It's currently installable as npm package @karuga/rehype-inline - I'm planning to drop the username prefix.

It inlines css, js and img elements. In contrast to the existing rehype-inline-svg its main goal is creating a single HTML file and not so much optimizing for speed.

I guess this could be included in the list of plugins in the rehype documentation. Before that I'm happy about feedback / testing / suggestions.

HAST and lit-html

I've been thinking about how HAST can work with https://github.com/Polymer/lit-html . Some potential ideas:

  • Converting the HAST to a lit-html template could allow us to use the lit-html's efficiently rendering?
  • Maybe using plugins to add directives and event binding? Some experimental examples are below. I'm debating if this is any more useful than just writing custom elements.

Add a click event tolis:

export const click = () => {
  return (tree: UNIST.Node, vfile: VFile) => {
    
    visit(tree, ['element'], (node: MDAST.Link, index, parent) => {
      if (node.tagName === 'li') {
        const n = {
          type: LIT_TYPE,
          template: c => html`<li @click="${onClick}">${c}</li>`, // children are added back later
          children: node.children
        };

        parent.children.splice(index, 1, n);
        return true; 
      }
    });
  };

  function onClick(e) {
    e.stopPropagation();
    this.classList.toggle('hidden')
  }
};

Convert an elements to a timed counter:

export const clock = () => {
  const wait = (t) => new Promise((resolve) => setTimeout(resolve, t));

  async function* countUp() {
    let i = 0;
    while (true) {
      yield i++;
      await wait(1000);
    }
  }

  return (tree: UNIST.Node, vfile: VFile) => {
    visit(tree, ['element'], (node: MDAST.Link, index, parent) => {
      if (node.tagName === 'strong') {
        const n = {
          type: LIT_TYPE,
          template: c => html`<span>Count: ${asyncReplace(countUp())}</span>`,
          children: node.children
        };

        parent.children.splice(index, 1, n);
        return true; 
      }
    });
  };
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.