Skip to content

A tiny component to render code with highlight.js inside of a terminal-like window.

License

Notifications You must be signed in to change notification settings

janole/embed-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

embed-code

A tiny component to render code with highlight.js inside of a terminal-like window.

How to embed the code

HOWTO

There are basically two ways of embedding the code. Both options will be using a simple JavaScript that is going to replace itself with the rendered code inside of a nice looking terminal window.

1. Plain text inside of the script tag

<script src="embed-code.js" type="text/javascript" data-lang="js">
function Welcome(props)
{
    return <h1>Hello, {props.name}</h1>;
}
</script>

2. JSON encoded data inside of the script tag

<script src="embed-code.js" type="text/javascript">
{"lang": "js", "code": "function Welcome(props)\n{\n    return <h1>Hello, {props.name}<\/h1>;\n}"}
</script>

The result will be looking like this:

The embedded code

CDN

The latest embed-code.js is available from unpkg.com:

https://unpkg.com/embed-code@latest/embed-code.js

WHY

I want to use this component in a Wordpress blog that's going to be filled from a github repository with markdown posts ...

About

A tiny component to render code with highlight.js inside of a terminal-like window.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published