Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-md-loader

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-md-loader - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

3

index.js

@@ -6,3 +6,4 @@ const loaderUtils = require('loader-utils')

this.cacheable && this.cacheable()
return new Parser(loaderUtils.getOptions(this)).parse(source)
const options = loaderUtils.getOptions(this)
return new Parser(options).parse(source)
}
{
"name": "vue-md-loader",
"version": "0.1.2",
"version": "0.1.3",
"description": "Webpack loader for converting Markdown files to Vue components.",

@@ -46,2 +46,3 @@ "main": "index.js",

"eslint-plugin-standard": "^3.0.1",
"markdown-it-anchor": "^4.0.0",
"mocha": "^4.0.1",

@@ -48,0 +49,0 @@ "style-loader": "^0.19.0",

@@ -166,12 +166,20 @@ # vue-md-loader

### md
### markdown
Object.
Use this to replace the Markdown-It instance inside the loader. For example:
Markdown-It options. Default:
```javascript
new MarkdownIt({
// options
})
{
html: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value
} catch (__) {}
}
return ''
}
}
```

@@ -178,0 +186,0 @@

@@ -5,8 +5,20 @@ const MarkdownIt = require('markdown-it')

const NEW_LINE = '\r\n'
const DEFAULT_MARKDOWN_OPTIONS = {
html: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value
} catch (__) {}
}
return '' // use external default escaping
}
}
// https://github.com/QingWei-Li/vue-markdown-loader/blob/master/lib/markdown-compiler.js
const ensureVPre = function (md) {
if (md && md.renderer && md.renderer.rules) {
// Apply `v-pre` to `<pre>` and `<code>` tags
const ensureVPre = function (markdown) {
if (markdown && markdown.renderer && markdown.renderer.rules) {
let rules = ['code_inline', 'code_block', 'fence']
let rendererRules = md.renderer.rules
let rendererRules = markdown.renderer.rules
rules.forEach(function (rule) {

@@ -23,5 +35,5 @@ if (rendererRules.hasOwnProperty(rule) && typeof rendererRules[rule] === 'function') {

function Parser (_options) {
function Parser (options) {
// default options
this.options = {
const defaultOptions = {
// live options

@@ -31,15 +43,5 @@ live: true,

liveTemplateProcessor: null,
// md instance
md: new MarkdownIt({
html: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value
} catch (__) {}
}
return '' // use external default escaping
}
}),
// md plugins
// markdown options
markdown: Object.assign({}, DEFAULT_MARKDOWN_OPTIONS),
// markdown plugins
plugins: [],

@@ -50,10 +52,18 @@ // others

// merge user options into defaults
Object.assign(this.options, _options)
let md = this.options.md
// Apply `v-pre` to `<pre>` and `<code>` tags
ensureVPre(md)
// Apply plugins to md instance
this.options.plugins.forEach(function (p) {
Array.isArray(p) ? md.use.apply(md, p) : md.use(p)
})
this.options = Object.assign({}, defaultOptions, options)
this.markdown = new MarkdownIt(Object.assign({}, this.options.markdown))
ensureVPre(this.markdown)
if (this.options.plugins && this.options.plugins.length) {
let markdown = this.markdown
// Apply plugins to markdown instance
this.options.plugins.forEach(function (p) {
if (Array.isArray(p)) {
if (p[0]) {
markdown.use.apply(markdown, p)
}
} else if (p) {
markdown.use(p)
}
})
}
this.reset()

@@ -202,3 +212,3 @@ }

let result = this.options.live ? this.parseLives() : {template: source, script: '', style: ''}
let html = this.options.md.render(result.template)
let html = this.markdown.render(result.template)
let vueFile = `<template><${this.options.wrapper}>${html}</${this.options.wrapper}></template>${result.style}${result.script}`

@@ -205,0 +215,0 @@ return vueFile

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc