Git Product home page Git Product logo

markdown-loader's Introduction

markdown-loader

markdown-loader for webpack using marked.

Version on NPM Semantically released Monthly downloads on NPM
License

Installation

npm install markdown-loader

Minimal requirements:

  • Node >=12.22.9
  • webpack >=5.0.0

Usage

Since marked's output is HTML, it's best served in conjunction with the html-loader.

// webpack.config.js
export default {
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "html-loader",
          },
          {
            loader: "markdown-loader",
            options: {
              // Pass options to marked
              // See https://marked.js.org/using_advanced#options
            },
          },
        ],
      },
    ],
  },
};

License

MIT (http://www.opensource.org/licenses/mit-license.php)

Sponsors

markdown-loader's People

Contributors

alansouzati avatar alex-lit avatar darul75 avatar ethancrook99 avatar hpohlmeyer avatar jhnns avatar jkinkead avatar kommander avatar meaku avatar qiuyuntao avatar semantic-release-bot avatar sokra avatar styfle avatar tmorehouse avatar yash-singh1 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-loader's Issues

Loading a dynamic file at run time

Hi,

I am trying to use this to load a file at run time which I can change dynamically. The file lives in my /dist folder. Any ideas? Thanks.

webpack v2.2.1
react v15.4.2
markdown-loader v2.0.0
react-markdown v2.5.0

Create a Security Policy

Hi team, I've noticed that there is not a security policy for this project. GitHub recommends that projects have a Security Policy (SECURITY.md). This is a simple document that explains how the project wishes to receive and handle responsible disclosure of potential vulnerabilities, hopefully reducing public exposures.

There are a few ways to receive such disclosures:

If you're interested in GitHub's feature, it must be activated for the repository by:

  1. Open the repo's settings
  2. Click on Code security & analysis
  3. Click "Enable" for "Private vulnerability reporting (Beta)"

If you activate that, I can send a PR suggesting a Security Policy markdown file afterwards. Thanks!

Documentation no longer valid for webpack2

Using the following syntax from the README.md:

module.exports = {
    ...
    markdownLoader: {
        renderer: renderer
    }
};

I get:

[0] Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
[0]  - configuration has an unknown property 'markdownLoader'. These properties are valid:
[0]    object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
[0]    For typos: please correct them.
[0]    For loader options: webpack 2 no longer allows custom properties in configuration.
[0]      Loaders should be updated to allow passing options via loader options in module.rules.
[0]      Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
[0]      plugins: [
[0]        new webpack.LoaderOptionsPlugin({
[0]          // test: /\.xxx$/, // may apply this only for some modules
[0]          options: {
[0]            markdownLoader: ...
[0]          }
[0]        })
[0]      ]

Add support for syntax highlighting

If you are interested, I think you can add syntax highlighting to the library quite easily. Here's the basic idea:

var highlight = require('highlight.js');

marked.setOptions({
    highlight: function(code) {
        return highlight.highlightAuto(code).value;
    }
});

This is the synchronous way to deal with it. There is also an async way to do this if needed.

Update version

It looks like package.json says the version is 0.2.0 but npm says the version is 2.0.0

This needs to be resolved to fix an error with the example

Any way to remove inserted line breaks?

Hey! I'm a little confused. When I use this in my project, I'm getting line breaks inserted between the html tags. I want to actually render the html, and because of the line breaks it's rendering it all as plain text on the page.

Example:
content.md

# Hello!
> What's up
Here's some markdown

test.js

import content from './content.md';
function someComponent(props) {
    return content;
}

My debugger says content = "<h1 id="hello-">Hello!</h1>\n<blockquote><p>What&#39;s upHere&#39;s some markdown</p>\n</blockquote>\n"

I'm wondering why there are line breaks, and how I can make this into renderable html because right now it looks like this:
screen shot 2018-02-09 at 8 47 54 pm

loader-utils need to update

(node:99162) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.

Usage example

I don't understand how this is supposed to work. Please add some examples.

Cheers

posibility of a 6.0.1 release with less strict marked version dependency

Hi, @meaku @jhnns,

Issue Description

I noticed that a vulnerability is introduced in [email protected]:
Vulnerability SNYK-JS-MARKED-584281 affects package marked (versions:<1.1.1): https://snyk.io/vuln/SNYK-JS-MARKED-584281
The above vulnerable package is referenced by [email protected] via:
[email protected][email protected]

Since [email protected] (14,926 downloads per week) is referenced by 26 downstream projects (e.g., @anansi/webpack-config 8.0.3 (latest version), @vtex/gatsby-theme-store 0.373.5 (latest version), yakuza0 2.19.5 (latest version), @next-core/dev-dependencies 1.10.9 (latest version), webpack-config-jaid 15.0.0 (latest version)), the vulnerability SNYK-JS-MARKED-584281 can be propagated into these downstream projects and expose security threats to them via the following package dependency paths:
(1)@anansi/[email protected][email protected][email protected]
(2) @cutting/[email protected][email protected][email protected]
......

If [email protected].* removes the vulnerable package from the above version, then its fixed version can help downstream users decrease their pain.

Given the large number of downstream users, could you help update your package to remove the vulnerability from [email protected] ?

Fixing suggestions

In [email protected], maybe you can kindly try to perform the following upgrade :
marked ^0.7.0 ➔ ^1.1.1;

Note:
[email protected](>=1.1.1) has fixed the vulnerability SNYK-JS-MARKED-584281.

Of course, you are welcome to share other ways to resolve the issue.^_^

How to use?

I use this loader to load *.md

var html = require("html!markdown!./README.md");
console.log(html)

html is <p>module.exports = &quot;<h3 id=\"example\">Example</h3>\n<ul>\n<li><code>npm install</code></li>\n<li><code>webpack-dev-server</code></li>\n</ul>\n&quot;;</p>

it is a string, I just want to use like this var container = document.getElementById('container'); container.innerHTML = html;

Why comes module.exports = &quot;, then how can I use?

Support programmable options

refer to: #4

I want to use programmable options as below.

var marked = require('marked');
var renderer = new marked.Renderer();

module.exports = {
  ...
  markdownLoader: {
    markedOptions: {
      renderer: renderer,
      ...
    }
  }
};

Images are not being extracted/loaded after upgrading to Angular 13

Hello, this might not be an issue with markdown-loader, however I hope to find some help here... I am all out of ideas.

Situation:

  • I recently upgraded my app from Angular 12 to Angular 13
  • I am using @angular-builders/custom-webpack to configure webpack
  • nothing changed in my webpack config between the versions
  • same version of html-loader and markdown-loader in both

To isolate the issue, I created a new empty angular app with ng new on both ng12 and ng13, with following webpack config:

import { Configuration } from 'webpack';

export default {
  module: {
    rules: [
      {
        test: /\.md$/i,
        use: [
          {
            loader: require.resolve('html-loader')
          },
          {loader: require.resolve('markdown-loader')}
        ],
      }
    ],
  }
} as Configuration;

markdown file with image:

Lemon the cat

![lemon](lemon.jpg) 

Results:

  • The app created with Angular 12 shows the image which has been correctly extracted in the dist files.
  • The app created with Angular 13 does not show the image, the image has not been extracted, and the link points to the local path, e.g. <img src="file:///C:/dev/workspace/labs/markdown-images/src/app/lemon.jpg" alt="lemon">

Any idea at all about what could be causing this issue? Thank you.

License and copyright information

I was not able to find the copy of the license. Although I was able to see that it is a MIT license, I was not able to find the license itself or the copyright information. Would anybody be able to help?

Add vue-cli usages

One can use it in vue.config.js (vue cli v3) as follows:

module.exports = {
  chainWebpack: config => {
    config.module.rule('md')
      .test(/\.md/)
      .use('html-loader')
      .loader('html-loader')
      .end()
      .use('markdown-loader')
      .loader('markdown-loader')
  }
}

please add to readme.

Conflict between url-loader and html-loader

Actually, this is not an issue since I have a solution. I am just posting here for others that may have the same problem.

Coming from webpack 4, I was using url-loader. Somehow, when using url-loader for the image type(s) that may appear in my normal html/js code AND in my markdown document the result was that the images were not working with markdown. The image file content was replaced with some JS export directive. By excluding the type(s) that I needed with the markdown document from the generic rule (test) related to url-loader then there is conflict and all is good. Obviously this mean I can not use the same type of file for both normal html/js and markdown, which is not good.. :-(

However, with Webpack 5, a new native module exists, which remove the need to use url-loader. This module (Asset) is apparently smart enough not to conflict with html-loader. This allows to have a generic rule supporting all image types while still be able to use the same type in markdown.

8.0.0 Cannot find module

Admittedly I haven't dug into this at all yet but something in 8.0.0 is throwing a "Cannot find module" error. Possible it is not an issue with markdowns-loader but downgrading to 7 works again so... I'm starting here.

I don't have time to dig into it right now but I thought I'd see if anyone had any tips.

ERROR in ./src/marketing/data/markdown/terms.md
Module build failed (from ../../.yarn/__virtual__/markdown-loader-virtual-b93c1fc2dc/0/cache/markdown-loader-npm-8.0.0-8cc869e04f-c5f878a24a.zip/node_modules/markdown-loader/src/main.cjs):
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/www/app/.yarn/__virtual__/markdown-loader-virtual-b93c1fc2dc/0/cache/markdown-loader-npm-8.0.0-8cc869e04f-c5f878a24a.zip/node_modules/markdown-loader/src/loader.js' imported from /www/app/.yarn/__virtual__/markdown-loader-virtual-b93c1fc2dc/0/cache/markdown-loader-npm-8.0.0-8cc869e04f-c5f878a24a.zip/node_modules/markdown-loader/src/main.cjs
  at new NodeError (internal/errors.js:322:7)
  at finalizeResolution (internal/modules/esm/resolve.js:308:11)
  at moduleResolve (internal/modules/esm/resolve.js:731:10)
  at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
  at Loader.resolve (internal/modules/esm/loader.js:89:40)
  at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
  at Loader.import (internal/modules/esm/loader.js:177:28)
  at importModuleDynamically (internal/modules/cjs/loader.js:1028:27)
  at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
  at Object.<anonymous> (/www/app/.yarn/__virtual__/markdown-loader-virtual-b93c1fc2dc/0/cache/markdown-loader-npm-8.0.0-8cc869e04f-c5f878a24a.zip/node_modules/markdown-loader/src/main.cjs:6:22)

Images inside markdown

I am trying to load images inside the article, but it does not seem to work.

It generates a file that is called

<img src="xxxHTMLLINKxxx0.5461799555923790.5964239498134702xxx" alt="header.jpg">

which obivious does not exist.

Using this with Showdown

Hello there,

Primarily trying Showdown because it is smarter and provides more options around id generation.

Can I use Showdown instead of markedjs with this plugin? If so, what would I need to do.

Thanks

Hash links with "&" are not converted the same way as github links

On github markdown, a header like this one:

This & That Section

will write out an id like this: this--that-section

On markdown-loader, it writes out this-that-section

This breaks links that adhere to github markdowns syntax:

[This & That Section](#this--that-section)

Not possible to escape the '|' (pipe) sign.

Property Type Default Comments
prop1? string | number; 'Def1'
prop2? string | number; 'Def2'

I have some.md file with table and the '|' (pipe) character cant be escaped the way like here (please see the source of this file). It always add new column within the row. It also not works within code marks.

Error when markdown contain invisible space

Version: 0.1.7

Console.log info

WARNING in ./data/build-markdown/test.md
Module parse failed: /Users/appuser/test/myapp/node_modules/html-loader/index.js!/Users/appuser/test/myapp/node_modules/markdown-loader/index.js!/Users/appuser/test/myapp/data/build-markdown/test.md Unterminated string constant (1:17)
You may need an appropriate loader to handle this file type.
SyntaxError: Unterminated string constant (1:17)

I found this invisible space after tried many markdown editor, this character not show in any editor even Sublime Text. I think it was produced by ACE HTML editor.

http://ww4.sinaimg.cn/large/6110a121gw1f4loqpj4i9j20b708o74r.jpg

issue with sanitize

I'm trying to set sanitize to false using the following:

  {
    test: /\.md$/,
    loader: 'html!markdown?sanitize=false'
  }

but it does not seem to work.

New release of marked incoming

Just wanted to drop a note saying that it seems like a new release of marked (0.5.0) is imminent; see markedjs/marked#1321. It would be great to see it hit markdown-loader quickly 😄 Am I okay to put up a PR for the new release once it is live?

code highlighting with highlight.js

Hello I am trying to get code highlighting to work

doing something similar to

const marked = require("marked");
marked.setOptions({
  highlight: function (code) {
    return require('highlight.js').highlightAuto(code).value;
  }
});
const renderer = new marked.Renderer();

  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.md$/,
        use: [ 
          {
            loader: "html-loader"
          },
          {
            loader: "markdown-loader",
            options: {
                pedantic: true,
                renderer
            }
          }
        ]
      },
}

Any advice would be great !

how to load a markdown file [file.md] without error

help is wanted

my config (nuxt.config.js)

  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "html-loader"
          },
          {
            loader: "markdown-loader",
            options: {
              pedantic: true,
              renderer
            }
          }
        ]
      }
    ]
  }

error occur during nuxt command

error in ./assets/markdowns/first.md

Module parse failed: Unexpected token (1:5)
You may need an appropriate loader to handle this file type.
| some para
| # Marked
|


 @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":true,"presets":[["G://Experiments//Project//nuxtjs//node_modules//babel-preset-vue-app//dist//index.common.js",{"targets":{"ie":9,"uglify":true}}]]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./pages/marked.vue 8:0-51
 @ ./pages/marked.vue
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr ./.nuxt/client.js

What is the necessary step to debug

Help getting custom renderer working

I'm trying to get a custom renderer working with the markdown loader, and I haven't had any luck. It doesn't look like anything I'm doing is wrong, but then when I look at the code for the loader, it all looks good, as well.

So... if you have any time, I was hoping you could take a quick look at my current set up and see if anything looks wrong at a glance. If it doesn't, I'll keep looking and will try to figure out exactly what's going on.

Some things to note:

  1. The custom highlight and turning sanitize off work as I'd expect
  2. Calling renderer.code('sample') prior to it being on the options object passed to Marked (via markdown-loader) works fine and outputs the code. However, when it's merged with the other options, it doesn't seem to work.

At a glance, anything look incorrect?

The sample code

webpack.config.js

module.exports = {
  module: {
    loaders: [
      {
        test: /\.md$/,
        loaders: ['html', 'markdown']
      }
    ]
  },
  markdownLoader: require('./build/webpack/markdown-options')
};

build/webpack/markdown-options.js

module.exports = {
  renderer: require('./markdown-renderer'),
  highlight: function(code) {
    return require('highlight.js').highlightAuto(code).value;
  },
  sanitize: false
};

build/webpack/markdown-renderer.js

Note that this isn't actually what I'm trying to do, but just to illustrate that the custom code renderer isn't being called.

/* globals escape */
var marked = require('marked');
var renderer = new marked.Renderer();

renderer.code = function(code, lang, escaped) {
  console.log(code);
  return code;
};

module.exports = renderer;

Inline HTML support?

I'm using this with suggested html-loader webpack plugin, and inline HTML tags are just showing up as plain text. Any advice? Thanks.

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.