• This repository has been archived on 03/Jan/2024
  • Stars
    star
    306
  • Rank 131,913 (Top 3 %)
  • Language Vue
  • License
    MIT License
  • Created about 5 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

A Vue Component for Markdown-based Slides.

vue-mark-display

A Vue Component to generate Markdown-based slides.

Installation

npm install vue-mark-display

Usage

<template>
  <mark-display
    :markdown="markdown"
    @title="setTitle"
    keyboard-ctrl
    url-hash-ctrl
    auto-font-size
    auto-blank-target
  ></mark-display>
</template>

<script>
import MarkDisplay from "vue-mark-display";

const markdown = `# Hello World
----
This is Vue Mark Display`;

export default {
  components: { MarkDisplay },
  data() {
    return { markdown };
  },
  methods: {
    setTitle({ title }) {
      document.title = title;
    }
  }
};
</script>

<style>
body {
  margin: 0;
  overflow: hidden;
}
</style>

The Extension for Markdown Syntax

  1. It's based on marked.
  2. You can separate pages by horizon lines (----).
  3. You can use HTML comments for meta info of each slides. The format is like <!-- key: value -->. Here are all useful meta keys below:
    • background: the background style of the slide
    • backgroundColor: the background color of the slide
    • backgroundImage: URL of the background image of the slide
    • color: the default font color of the slide
    • style: inline css text attached to the slide
    • stageBackground: the background style attached to the stage when the current slide is shown

Example:

<!-- color: red; -->
<!-- style: font-weight: bold; -->

# Hello

---

<!-- stageBackground: silver -->

![./favicon.ico] this is content

API

Default Export: the Component

Props

{
  // markdown content
  markdown: String,
  // or give a markdown URL
  src: String,
  // initial page number
  page: Number,
  // set `baseUrl` for the whole document
  // so all the relative URLs in markdown content would be applied
  baseUrl: String,
  // whether use `src` as the `baseUrl` automatically
  autoBaseUrl: Boolean,
  // whether open links in a blank target by default
  autoBlankTarget: Boolean,
  // whether adjust font-size to adapt the screen size
  autoFontSize: Boolean,
  // whether support keyboard shortcuts (Arrows, Enter, Ctrl+G)
  keyboardCtrl: Boolean,
  // whether update URL hash when page changed
  urlHashCtrl: Boolean,
  // support opening an iframe on top of the page to preview a URL
  // when click the `<a>` link with `altKey` pressed
  supportPreview: Boolean
}

Events

  • @change="func({ from, to })": when page changed
  • @title="func({ title })": when title changed

Styles

The root element of the <mark-display> component has a class named mark-display which you can use for styling.

Also you can overwite the default transition style below on each slides:

.slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  transition: all 0.3s;
}
.slide-enter {
  opacity: 0;
}
.slide-leave-to {
  opacity: 0;
}

To learn more about transitions on Vue, see here.

At the end, it's a good choice to "normalizing" the body by your own:

body {
  margin: 0;
  overflow: hidden;
}

And feel free to set other styles for common HTML tags as you like.

If you want to customize other styles in the component, please be careful. Because they are not guaranteed which means they may be changed in the future.

Methods

With these methods you can call them outside through its ref. For example on the bottom you can use them to support touchable screens.

  • goto(page: number): go to a given page which is counted from 1 (not 0)
  • goNext(): go to next page if possible
  • goPrev(): go to previous page if possible
  • goFirst(): go to the first page
  • goLast(): go to the last page

Named Export: setHighlighter()

Set a centralized code highlighter.

  • parameters:

    • highlighter: function (code: string, lang: string): string: the customized code highlighter from you
  • examples:

    Take highlight.js for example:

    import hljs from "highlight.js";
    import "highlight.js/styles/github.css";
    import { setHighlighter } from "vue-mark-display";
    setHighlighter(code => hljs.highlightAuto(code).value);

For Touchable Screen

You can using some open source touch event libs to bring touch controls into the slides. For example the code below is using Hammer.js and methods goNext()/goPrev() to support swipe gestures:

<template>
  <mark-display ref="main" markdown="..." />
</template>

<script>
import Hammer from "hammerjs";
import MarkDisplay from "vue-mark-display";
export default {
  components: { MarkDisplay },
  mounted() {
    const mc = new Hammer(this.$el);
    const main = this.$refs.main;
    mc.on("swipe", event => {
      if (event.pointerType === "mouse") {
        return;
      }
      switch (event.direction) {
        case Hammer.DIRECTION_LEFT:
          main.goNext();
          return;
        case Hammer.DIRECTION_RIGHT:
          main.goPrev();
          return;
      }
    });
  }
};
</script>

Export into PDF

screenshot of export into PDF

You can print the slides simply by CMD+P. The page style has been automatically formated by CSS page media & fragmentation specs under the hook. Then just select "export to PDF" on the print dialog to finish it. That makes your slides easy to export and share on/off the internet.

Notice that when you print the slides, only current screen-displayed stageBackground meta info is active. So it would be applied to all pages of the exported PDF.

More Repositories

1

h5slides

A Slides App based on HTML5
JavaScript
855
star
2

zhlint

A linting tool for Chinese language.
TypeScript
235
star
3

px2rem-loader

Webpack loader for px2rem css file
JavaScript
204
star
4

vue-a11y-utils

Utilities for accessibility (a11y) in Vue.js
TypeScript
119
star
5

weex-x

JavaScript
58
star
6

vlite

A lite demo server, inspired by Vite
TypeScript
48
star
7

weex-template

JavaScript
38
star
8

v-dynamic-island

A Vue (3.x) implementation of Dynamic Island
Vue
31
star
9

rich-game

JavaScript
28
star
10

vue-keyboard-over

A Vue component that display pressed keys on the keyboard by the user right now.
Vue
26
star
11

vue-simple-compiler

A lib to compile Vue Single-File Component into plain JavaScript & CSS.
TypeScript
22
star
12

webcomponents-demo

All demos I wrote about Web Components
18
star
13

mark2slides

A markdown-to-slides generator.
JavaScript
15
star
14

html5-slides-20110512

如何制作简易的HTML5幻灯片
JavaScript
14
star
15

996.band

Homepage of 996 Band
HTML
14
star
16

slides

My slides (generated by mark2Slides)
JavaScript
12
star
17

vue-a11y-examples

Examples for vue-a11y-utils
Vue
11
star
18

html5-player-20110610

JavaScript
8
star
19

vue-computed-array

A JS library to create a two-way computed array in Vue easier.
JavaScript
7
star
20

jie

基于 Polymer 的一套组件库,开发代号暂定为 JIE
6
star
21

vue-mark-preview

A web app to preview a markdown URL as slides.
JavaScript
6
star
22

pic360

Show panorama pictures in 360 degrees.
JavaScript
6
star
23

grunt-combo-html-css-js

Combine css links and javscript files to html file with inline tags automatically
JavaScript
5
star
24

wcag20-techs-contents-cn

Techniques for WCAG 2.0 目录的中文翻译
4
star
25

jinjiang.github.io

Jinjiang's dev site
Shell
4
star
26

zorro

A web components framework & gallery
3
star
27

jie-dialog

3
star
28

vue-typed-style

JavaScript
3
star
29

jie-progress

2
star
30

source-map-view

A web app to view source code and source maps side-by-side.
TypeScript
2
star
31

try-nuxt

Vue
1
star
32

jie-btn

1
star
33

jie-icon

1
star
34

jiongks

My Chinese blog
JavaScript
1
star
35

jie-dock

1
star
36

translation-workflow-demo

JavaScript
1
star