Skip to content

Commit

Permalink
feat: initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
rparree committed Mar 28, 2024
1 parent b425fc4 commit 1545683
Show file tree
Hide file tree
Showing 24 changed files with 3,337 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export NODE_VERSIONS=~/.nvm/versions/node
export NODE_VERSION_PREFIX="v"
export PATH=/home/rparree/opt/hugo/0.124.1:$PATH
use node
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
27 changes: 27 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:@typescript-eslint/recommended",
"eslint-config-prettier"
],
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"node": {
"paths": [
"lib"
],
"extensions": [
".ts"
]
}
}
},
"rules": {
"import/named": "off",
"import/no-unresolved": "off"
}
}
172 changes: 172 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
### Linux template
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.npmrc
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"printWidth": 120,
"bracketSpacing": true,
"endOfLine": "lf"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 EDC4IT B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
94 changes: 93 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,96 @@
# Reveal.js Railroad-diagram

[![Version](https://img.shields.io/npm/v/@edc4it/reveal.js-raildroad)](#)
[![Version](https://img.shields.io/npm/v/@edc4it/reveal.js-railroad)](#)

A [reveal.js](https://revealjs.com/) plugin that adds support for Railroad-diagrams.
It is a thin wrapper around the amazing [Railroad-diagram Generator](https://github.com/tabatkins/railroad-diagrams) project.

![](demo/Screenshot_20240328_141848.png)

---

```html
<script type="application/railroad">
Diagram(
'function',
NonTerminal('identifier'),
'(', ZeroOrMore('param', ','), ')',
'{', ZeroOrMore(NonTerminal('statement')), '}');
</script>
```

**Important** notes:

- We chose the "holder" to be `<script type="application/railroad">`
- The containment script is **executed** using [`eval`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval). This could be an enormous security risk if you don't know the authors of your slides.

## Quickstart

### Installation

This plugin is published to, and can be installed from, npm.

```console
npm install add @edc4it/reveal.js-railroad
```

Or using yarn

```console
yarn add @edc4it/reveal.js-railroad
```

### Initialise (as npm library)

```js
import Reveal from 'reveal.js';
import ClipCode from '@edc4it/reveal.js-clipcode';

Reveal.initialize({
railroad: {
// Default values
bg: 'unset',
pathStroke: '#82e4ff',
rectFill: '#00a6ff',
rectStroke: 'white',
textFill: 'white',
},
plugins: [RailRoad],
});
```

### Add a diagram

For the full syntax of "components" see [Railroad-Diagram components](https://github.com/tabatkins/railroad-diagrams/blob/gh-pages/README-js.md#components)

```html
<script type="application/railroad">
Diagram(
'function',
NonTerminal('identifier'),
'(', ZeroOrMore('param', ','), ')',
'{', ZeroOrMore(NonTerminal('statement')), '}');
</script>
```

## Global options

```javascript
Reveal.initialize({
railroad: {
// Default values
bg: 'unset',
pathStroke: '#82e4ff',
rectFill: '#00a6ff',
rectStroke: 'white',
textFill: 'white',
},
plugins: [RailRoad],
});
```

- `bg`: the background of the diagram
- `pathStroke`: the color used for the "path" of the railroad diagram,
- `rectFill`: 'the fill/background color of the components
- `rectStroke`: 'the stroke color of the components,
- `textFill`: color of the text inside the components,
Binary file added demo/Screenshot_20240328_141848.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RailRoad Diagrams reveal.js plugin</title>
<link rel="stylesheet" href="node_modules/reveal.js/dist/reset.css" />
<link rel="stylesheet" href="node_modules/reveal.js/dist/reveal.css" />
<link rel="stylesheet" href="node_modules/reveal.js/dist/theme/black.css" />
<link rel="stylesheet" href="node_modules/reveal.js/plugin/highlight/monokai.css" />
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>RailRoad</h1>
<h2>Reveal.js Plugin</h2>
<script type="application/railroad">
Diagram(
'function',
NonTerminal('identifier'),
'(', ZeroOrMore('param', ','), ')',
'{', ZeroOrMore(NonTerminal('statement')), '}');
</script>
</section>
</div>
</div>

<script type="module">
import Reveal from 'reveal.js';
import RailRoad from './src/plugin.ts';

Reveal.initialize({
history: true,
overview: false,
center: true,
margin: 0.15,
railroad: {
// Default values
bg: 'unset',
pathStroke: '#82e4ff',
rectFill: '#00a6ff',
rectStroke: 'white',
textFill: 'white',
},
plugins: [RailRoad],
});
</script>
</body>
</html>
Loading

0 comments on commit 1545683

Please # to comment.