Coder Social home page Coder Social logo

htmltooembed's Introduction

HTML to Oembed

Searches for embeddably links on HTML elements or text and replaces them with HTML embeds.

Client Side Use

Refer to /Browser

Installation

Simply download and include the oembed.js file

<script src="/Browser/oembed.js">

Usage

//HTMLToOembed((HTML Element)element, (object)options)
HTMLToOembed(document.getElementByID("articleContent"))

Server Side Use with Node.js

Refer to /NPM

Installation

npm install HTMLToOembed

Usage

HTMLToOembed((string)html, (object)options)

const HTMLToOembed = require("HTMLToOembed")

var articleContent = <HTMLAsString> //E.g innerHTML as sent by the client to the server

articleContent = HTMLToOembed(articleContent) //Your new HTML with links embedded

Options

These options are usable for both the server side version and client side version of the HTMLToOembed functions

(bool; Default true) gyazo: Converts gyazo links to img tags

(bool; Default true) imgFile: Converts image links to img tags

(bool; Default true) videoFile: Converts video links to img tags

(bool; Default true) imgur: Embeds Imgur links. Should turn this into a plain image tag if I can figure out how to extract the image

(bool; Default true) codepen: Embeds Codepen pens

(RegEx Array; Default undefined) fileDomainWhitelist: Only domains that are matched by this whitelist will be handled for image embeds. NPM Example:

await toOembed(<HTMLAsString>, {
	fileDomainWhitelist: [
		/https:\/\/(i\.)?imgur\.com/,
		/https:\/\/(i\.)?gyazo\.com/,
		/https:\/\/cdn\.discordapp\.com/,
		/https:\/\/media\.discordapp\.net/,
		/https:\/\/(cdn\.)?wearedevs\.net/,
	],
})

htmltooembed's People

Contributors

2jj1 avatar

Watchers

 avatar

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.