• Stars
    star
    241
  • Rank 161,488 (Top 4 %)
  • Language
    JavaScript
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive coding tutorials with markdown

Tutorial Markdown

Tutorial markdown is a small js library, which allows (with some data attributes) for a tutorial to type, and execute its code as you scroll through the document. You can see an example of it working on generative artistry.

Currently the system is geared towards showing visual javascript work on things like the canvas, so there will probably be some things pop up when trying to do other things, but please, report an issue for anything like that and we can grow the library together.

The How

To run an interactive tutorial there are several parts that you will need to set up to act together, without all of them in place, we don't get to see any magic. These are:

1. Correct code marking

When you are marking your code blocks, you'll need to use the correct data- attributes. These are what will be parsed into instructions for the editor to display, and the iframe to run. You'll also need a consistent class name that marks all blocks.

There are only a few data attributes that tutorial markdown runs off

  1. data-from (mandatory) is the line number where you intend your new code to be injected from.
  2. data-to (optional) if you set a data-to all code between the from and to line will be replaced with your new code
  3. data-indent (optional) indents your code to the level, so you don't need to indent code blocks needlessly in the markdown.

You can see examples of these in the generative artistry posts ... for example, in the previous link, there is the line <div class="tmd-trigger" data-from="10" data-to="11" data-indent="1">...</div>, inside this div is the code I want to send to the editor and iframe. The data-from says, start from line 10, and the data-to says, replace all code between line 10 and 11 with the contents.

2. The editor and iframe on the page

Currently tutorial markdown only supports windows monaco editor ... although its been built to have others in mind, the support isn't implemented just yet. You will need to initialize a new "editor" and have the variable on hand.

The "iframe" is an iframe on your page, set up by you with the html you want to run your tutorial. In this iframe, you'll need some code that handles tutorialMarkdown sending messages to it. This can be found in dist ... In the examples on generativeArtistry you can see this set up with a canvas.

The Iframe needs to have the iframe.js script included in dist, within the file, this lets it recieve the code and add it during each step.

3. Correct tutorial markdown initiation and variables

Once you have included the tutorial markdown js file (available in /dist) you'll need to initialize it, here's an example.

new TutorialMarkdown({
  editor: {
    editor: value,
    api: value
  },
 iframe: value,
 markdownSelector: {
   blockSelector: value
   codeSelector: value
 }
})

The values here are as follows.

  • editor is the Monaco code editor you have created on page
  • api is the global variable created by adding the monaco script, allows tutorial markdown to access some of its functions
  • iframe is the iframe in which tutorial markdown will send the code to run
  • blockSelector is the selector (classname or id) which holds the blocks of code you want to be run by the system
  • codeSelector is an optional variable which allows you to select the element that contains the code, within the blockSelector element... this is because these blocks often contain line numbers and other non relavent code.

All together these will make tutorial markdown work.

The Other Things

In order to keep things simpler, there are certain pieces that tutorial markdown is not running, for example, how your page is styled. In the example you can see the editor and iframe set up in a way that keeps them on the page (with position sticky) you will need to do the same.

The iframe itself needs to be styled and set up by you. In the examples this includes adding a canvas, and styling it to take up the full frame.

There is an additional function you may call on your TutorialMarkdown instance, named sendCode calling this will re-send whatever is in the editor to the iframe. This can be seen in generative artistry, clicking the small arrow means that people can edit their own code, and send the result. Anything sent will be forgotten when another code block is sent to the editor.

More Repositories

1

elevator.js

Finally, a "back to top" button that behaves like a real elevator.
JavaScript
6,620
star
2

github-corners

A fresher "Fork me on GitHub" callout.
HTML
4,891
star
3

zenpen

A minimalist writing zone.
JavaScript
3,765
star
4

cursor-effects

Old-school cursor effects for your browser built with modern JavaScript
JavaScript
3,181
star
5

intense-images

A simple library to view large images up close using simple mouse interaction, and the full screen.
JavaScript
2,572
star
6

generative-artistry

A website for self coding generative art tutorials.
JavaScript
833
star
7

giflinks

The best thing to happen to the internet since the <a> tag.
JavaScript
796
star
8

dom-animator

A nifty javascript library to run animations, hidden in comment nodes, within the dom.
JavaScript
628
star
9

ascii-morph

Library to animate between two ascii images -
JavaScript
570
star
10

obnoxious.css

Animations for the strong of heart, and stupid of mind.
CSS
506
star
11

console-dot-frog

Forget console logs, console.frog is where its all at!
JavaScript
315
star
12

overscroll

Javascript for adding small easter eggs when over scrolling on apple devices.
JavaScript
295
star
13

texter

Texter is a little app that lets you explore your creativity by drawing with text.
JavaScript
273
star
14

the-indie-web

A hotspot for indie creations on the web
CSS
250
star
15

what-have-you-made-today

Chrome & FireFox extension to replace the default home page. What have you made today?
Vue
231
star
16

discreet-twitter-ui

A minimal ui/ux concept for twitter buttons allowing hover reveals under an icon.
CSS
221
star
17

office-simulator

Miss the office life? You won't any more with this wonderful office slack simulator.
JavaScript
160
star
18

tileJs

Windows Metro Tiles with css3 and javascript
JavaScript
154
star
19

buddy

Chrome extension, and friend from hell
JavaScript
134
star
20

smelvetica

Sorry y'all, got a takedown from monotype.
134
star
21

bsod.js

Blue screen of death for the web, because debugging shouldn't be easy.
JavaScript
112
star
22

binary-music-player

A binary music player, with customizable notes & playback.
HTML
95
star
23

mosquito-js

An annoying mosquito created with the web audio api.
JavaScript
93
star
24

unicoder.js

A small js library to convert text into ⓣⓔⓧⓣ.
JavaScript
92
star
25

console-fright-night

Open the browser console, get a fright. Just like that!
JavaScript
89
star
26

the-zen-zone

Digital meditation aid
JavaScript
80
star
27

the-pattern-library

A library of beautiful patterns, created by talented designers.
JavaScript
75
star
28

palettab

New fonts and colors with every new tab.
JavaScript
68
star
29

image-nodes

Javascript experiment using image data to create a small interactive particle system
CSS
58
star
30

emoji-intensifies

A quick and simple tool to make shaky "intensifies" emoji.
JavaScript
54
star
31

meettheipsums

A website to link out to all of the awesome filler text in the world.
HTML
52
star
32

s.js

Canvas JavaScript polyfill for the vital and pivotal S we all drew in school.
JavaScript
51
star
33

resizer

A small library to improve the user experience of a text box, by decreasing the font size slightly if it is filled with text.
JavaScript
49
star
34

the-internet

Basically the internet (or most important parts) in a module.
JavaScript
49
star
35

beautiful-curves

A simple generative drawing app using the html5 canvas
JavaScript
39
star
36

cant-not-tweet-this

Taking annoying social media popup crap to the next level!
CSS
37
star
37

concentrics

A little web experiment, using concentric circles and squares to create abstract arty stuff!
JavaScript
35
star
38

abstract-clocks

Abstract Clocks, telling the time in abstract & beautiful ways.
HTML
34
star
39

tetris-pieces

A beautiful AI Tetris, playing on your wall!
JavaScript
33
star
40

long-doge-challenge

The Long Doge Challenge
HTML
32
star
41

rasterizer

Experimenting with rasterization with javascript + the html5 canvas
JavaScript
30
star
42

checkboxrace

A checkbox based race
HTML
26
star
43

asciiFaceSaver

An osx screen saver, looping over various ascii faces. Written in Swift.
Swift
26
star
44

interactive-banners

A few html5 experiments using js/canvas to create interactive banners
JavaScript
25
star
45

useless-web-archive

An archive for the sites of "the useless web"
HTML
22
star
46

puginarug

Honor the Pug in a Rug
HTML
20
star
47

Dripping-Paint

Small html5 canvas experiment to simulate a simple dripping paint effect
JavaScript
19
star
48

mondrian-and-me

A "Useless Website" honoring Piet Mondrian's fantastic art.
HTML
19
star
49

tholman-blog

Source to my personal blog and website.
CSS
17
star
50

thats-the-finger

The finger. Thats it.
JavaScript
13
star
51

star-spangled-browser

A chrome plugin to blow minds when hovering the word america.
JavaScript
12
star
52

one-square-minesweeper

A game of minesweeper with only one square to sweep. Fun for the whole family.
CSS
10
star
53

scripts-for-life

A few bash shells scripts I use to make life easier.
Shell
8
star
54

human-music

Sit back and stretch your legs and enjoy the relaxing tunes of Earth radio.
HTML
5
star
55

tholman

A repo about me!
1
star