Giter Club home page Giter Club logo

vue-prism-component's Introduction

vue-prism-component

NPM version NPM downloads Release Package donate

Install

yarn add vue-prism-component

CDN: UNPKG | jsDelivr

Usage

First you need to load Prism somewhere in your app:

// yarn add prismjs
import 'prismjs'
import 'prismjs/themes/prism.css'

OR:

<link rel="stylesheet" href="https://unpkg.com/prismjs/themes/prism.css" />
<script src="https://unpkg.com/prismjs"></script>

Then In SFC:

<template>
  <prism language="javascript">{{ code }}</prism>
</template>

<script>
import Prism from 'vue-prism-component'

export default {
  data() {
    return {
      code: 'const a = b'
    }
  },
  components: {
    Prism
  }
}
</script>

Or In JSX:

<Prism language="html">{`
  <div>
    <strong>foo</strong>
  </div>
`}</Prism>

For inline rendering, pass the inline prop:

<Prism inline language="javascript" >alert("foo");</Prism>

You can also set the code using a prop:

import 'prismjs/components/prism-rust'

<Prism language="rust" code={ myRustCode } />

Related

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

vue-prism-component © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin

vue-prism-component's People

Contributors

abdelrahman3d avatar alegalviz avatar egoist avatar fzembow avatar privatenumber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-prism-component's Issues

vue-prism-component does not provide an export named 'default'

Is it possible to prepare an ESM version so I can use this in Vite? I'm not sure why I'm seeing issues like this...

SyntaxError: The requested module '/@fs/Users/lucaban/ghq/github.com/CyCraft/blitzar/node_modules/vue-prism-component/dist/vue-prism-component.common.js?v=d01fabea' does not provide an export named 'default'

Empty component fails to render

Try to use this but don't provide any children

var code = ctx.props.code || ctx.children[0].text;

Fails since there are no children. Probably better to just fall back to '' in this case

Getting an error when using the component with PHP code

When I'm trying to use the component with language="php", I'm getting the following error:

Error in render: "TypeError: Prism.languages['markup-templating'] is undefined"

Here's what my component looks like:

<template>
  <prism language="php">{{ code }}</prism>
</template>

<script>
import "prismjs";
import "prismjs/components/prism-php";

import Prism from "vue-prism-component";

export default {
  data() {
    return {
      code: "<?= 'Hello world!' ?>"
    };
  },
  components: {
    Prism
  }
};
</script>

I'm not getting any errors with other languages (tried JSON, Bash, Ruby, JavaScript, Python, C#, Java, Go, Scala).

Example of working code:

<template>
  <prism language="ruby">{{ code }}</prism>
</template>

<script>
import "prismjs";
import "prismjs/components/prism-ruby";

import Prism from "vue-prism-component";

export default {
  data() {
    return {
      code: 'puts "Hello world!"'
    };
  },
  components: {
    Prism
  }
};
</script>

Willing to PR if I can help 🙂

How to escape backticks?

I'm trying to showcase this code via prism:

 code: `this.reasons.push({
        id: i,
       name: `Reason-${i}`
      });`

and in template:
<prism language="js">{{ code}}</prism>

When compiling I get an error:

Failed to compile.
./src/components/Reasons/Reason-8.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Reasons/Reason-8.vue?vue&type=script&lang=js&) 58:14
Module parse failed: Unexpected token (58:14)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
    this.reasons.push({
       id: i,
        name: \`Reason-${i}\`
     });
    }

How can I overcome this problem and use template literals with Prism?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.