Skip to content

Commit

Permalink
Separator Options (#19)
Browse files Browse the repository at this point in the history
* Add custom separator options
* Add description about separator options
  • Loading branch information
yusukebe committed Oct 21, 2021
1 parent 434ead1 commit 6c67e92
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 51 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ Then access the local web server such as `http://localhost:3000` with Chrome, Fi
Available options:

```text
-p, --port tcp port number of this server. default is 3000.
--theme slide theme or original css file name. default themes:
-p, --port TCP port number of this server. default is 3000.
--theme Slide theme or original css file name. default themes:
beige, black, blood, league, moon, night, serif, simple, sky, solarized, and white
--transition transition effect for slides: default, cube, page, concave, zoom, linear, fade, none
--multiplex enable slide multiplexi
--transition Transition effect for slides: default, cube, page, concave, zoom, linear, fade, none
--separator Horizontal slide separator characters (default: ^---)
--vertical-separator Vertical slide separator characters (default: ^___)
--multiplex Enable slide multiplex
```

### Screenshots
Expand All @@ -45,7 +47,7 @@ Open the server address with your web browser:

### Sample Makrdown

```markdown
```text
## This is an H2 Title
Description...
Expand All @@ -56,9 +58,9 @@ The horizontal slide separator characters are '---'
# This is second title
The vertical slide separator characters are '\_\_\_'
The vertical slide separator characters are '^___'
---
___
## This is a third title
Expand Down
40 changes: 28 additions & 12 deletions assets/templates/slide.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<base href="/"> <!-- Force all the relative paths to lookup from / -->
<link rel="stylesheet" href="revealjs/css/reveal.css">
<link rel="stylesheet" {{if .OriginalTheme}} href="{{.Theme}}" {{else}} href="revealjs/css/theme/{{.Theme}}" {{end}} id="theme">
<link rel="stylesheet" href="revealjs/lib/css/zenburn.css">
<meta charset="utf-8" />
<base href="/" />
<!-- Force all the relative paths to lookup from / -->
<link rel="stylesheet" href="revealjs/css/reveal.css" />
<link
rel="stylesheet"
{{if
.OriginalTheme}}
href="{{.Theme}}"
{{else}}
href="revealjs/css/theme/{{.Theme}}"
{{end}}
id="theme"
/>
<link rel="stylesheet" href="revealjs/lib/css/zenburn.css" />
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="revealjs/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
document.write(
'<link rel="stylesheet" href="revealjs/css/print/' +
(window.location.search.match(/print-pdf/gi) ? "pdf" : "paper") +
'.css" type="text/css" media="print">'
)
</script>
<!--[if lt IE 9]>
<script src="revealjs/lib/js/html5shiv.js"></script>
Expand All @@ -17,11 +31,13 @@
<body>
<div class="reveal">
<div class="slides">
<section data-markdown="{{.Path}}"
data-separator="^---"
data-separator-vertical="^___"
data-charset="utf-8"
data-notes="^Note:">
<section
data-markdown="{{.Path}}"
data-separator="{{.Separator}}"
data-separator-vertical="{{.VerticalSeparator }}"
data-charset="utf-8"
data-notes="^Note:"
>
<script type="text/template">
## Page title

Expand Down
23 changes: 13 additions & 10 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ type CLI struct {
}

type CLIOptions struct {
Port int `short:"p" long:"port" description:"TCP port number of this server. default is 3000."`
Theme string `long:"theme" description:"Slide theme or original css file name. default themes: beige, black, blood, league, moon, night, serif, simple, sky, solarized, and white" default:"black.css"`
Transition string `long:"transition" description:"Transition effect for slides: default, cube, page, concave, zoom, linear, fade, none" default:"default"`
Multiplex bool `long:"multiplex" description:"Enable slide multiplexing"`
Version bool `short:"v" long:"version" description:"Show the version"`
Port int `short:"p" long:"port" description:"TCP port number of this server. default is 3000."`
Theme string `long:"theme" description:"Slide theme or original css file name. default themes: beige, black, blood, league, moon, night, serif, simple, sky, solarized, and white" default:"black.css"`
Transition string `long:"transition" description:"Transition effect for slides: default, cube, page, concave, zoom, linear, fade, none" default:"default"`
Separator string `long:"separator" description:"Horizontal slide separator characters" default:"^---"`
VerticalSeparator string `long:"vertical-separator" description:"Vertical slide separator characters" default:"^___"`
Multiplex bool `long:"multiplex" description:"Enable slide multiplexing"`
Version bool `short:"v" long:"version" description:"Show the version"`
}

func (cli *CLI) Run(args []string) int {
Expand Down Expand Up @@ -80,10 +82,12 @@ func (cli *CLI) serve(args []string) {
port: opts.Port,
}
param := ServerParam{
Path: args[0],
Theme: addExtention(opts.Theme, "css"),
Transition: opts.Transition,
OriginalTheme: originalTheme,
Path: args[0],
Theme: addExtention(opts.Theme, "css"),
Transition: opts.Transition,
OriginalTheme: originalTheme,
Separator: opts.Separator,
VerticalSeparator: opts.VerticalSeparator,
}
if opts.Multiplex {
password := "this-is-not-a-secret"
Expand All @@ -110,4 +114,3 @@ func (cli *CLI) newParser() *flags.Parser {
parser.Usage = "[options] [MARKDOWN FILE]"
return parser
}

12 changes: 7 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ type Server struct {
}

type ServerParam struct {
Path string
Theme string
OriginalTheme bool
Transition string
Multiplex MultiplexParam
Path string
Theme string
OriginalTheme bool
Transition string
Separator string
VerticalSeparator string
Multiplex MultiplexParam
}

type MultiplexParam struct {
Expand Down
35 changes: 18 additions & 17 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (

func TestContentHandler(t *testing.T) {
param := ServerParam{
Path: "testdata/example.md",
Theme: "beige.css",
Transition: "fade",
Path: "testdata/example.md",
Theme: "beige.css",
Transition: "fade",
Separator: "^===",
VerticalSeparator: "^----",
}
ts := httptest.NewServer(contentHandler(param, http.FileServer(http.Dir("."))))
defer ts.Close()
Expand All @@ -29,22 +31,21 @@ func TestContentHandler(t *testing.T) {
buf.ReadFrom(res.Body)
s := buf.String()

match := "revealjs/css/theme/beige.css"
r := regexp.MustCompile(match)
if r.MatchString(s) == false {
t.Errorf("content do not match %v\n", match)
matches := []struct {
regexp string
}{
{regexp: "revealjs/css/theme/beige.css"},
{regexp: `data-markdown="testdata/example.md"`},
{regexp: `|| 'zoom',`},
{regexp: `data-separator="\^==="`},
{regexp: `data-separator-vertical="\^----"`},
}

match = `data-markdown="testdata/example.md"`
r = regexp.MustCompile(match)
if r.MatchString(s) == false {
t.Errorf("content do not match %v\n", match)
}

match = `|| 'zoom',`
r = regexp.MustCompile(match)
if r.MatchString(s) == false {
t.Errorf("content do not match %v\n", match)
for _, m := range matches {
r := regexp.MustCompile(m.regexp)
if r.MatchString(s) == false {
t.Errorf("content do not match %v\n", m.regexp)
}
}

r2, err := http.Get(ts.URL + "/testdata/markdown.svg")
Expand Down

0 comments on commit 6c67e92

Please sign in to comment.